blob: 1dde87d2e6d25377e284b8c695483365ad95910d [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
Chandler Carruth55fc8732012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000024#include "clang/AST/Stmt.h"
25#include "clang/AST/StmtCXX.h"
26#include "clang/AST/StmtObjC.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Lex/Preprocessor.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000028#include "clang/Sema/Designator.h"
29#include "clang/Sema/Lookup.h"
30#include "clang/Sema/Ownership.h"
31#include "clang/Sema/ParsedTemplate.h"
32#include "clang/Sema/ScopeInfo.h"
33#include "clang/Sema/SemaDiagnostic.h"
34#include "clang/Sema/SemaInternal.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000035#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000036#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +0000250 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
David Blaikiedc84cd52013-02-20 22:23:23 +0000253 Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Richard Smithc83c2302012-12-19 01:39:02 +0000326 /// \brief Transform the given initializer.
327 ///
328 /// By default, this routine transforms an initializer by stripping off the
329 /// semantic nodes added by initialization, then passing the result to
330 /// TransformExpr or TransformExprs.
331 ///
332 /// \returns the transformed initializer.
333 ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
334
Douglas Gregoraa165f82011-01-03 19:04:46 +0000335 /// \brief Transform the given list of expressions.
336 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000337 /// This routine transforms a list of expressions by invoking
338 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000339 /// support for variadic templates by expanding any pack expansions (if the
340 /// derived class permits such expansion) along the way. When pack expansions
341 /// are present, the number of outputs may not equal the number of inputs.
342 ///
343 /// \param Inputs The set of expressions to be transformed.
344 ///
345 /// \param NumInputs The number of expressions in \c Inputs.
346 ///
347 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000348 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 /// be.
350 ///
351 /// \param Outputs The transformed input expressions will be added to this
352 /// vector.
353 ///
354 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
355 /// due to transformation.
356 ///
357 /// \returns true if an error occurred, false otherwise.
358 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000359 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000360 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000361
Douglas Gregor577f75a2009-08-04 16:50:30 +0000362 /// \brief Transform the given declaration, which is referenced from a type
363 /// or expression.
364 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000365 /// By default, acts as the identity function on declarations, unless the
366 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000367 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 llvm::DenseMap<Decl *, Decl *>::iterator Known
370 = TransformedLocalDecls.find(D);
371 if (Known != TransformedLocalDecls.end())
372 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000373
374 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000376
Chad Rosier4a9d7952012-08-08 18:46:20 +0000377 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000378 /// place them on the new declaration.
379 ///
380 /// By default, this operation does nothing. Subclasses may override this
381 /// behavior to transform attributes.
382 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000383
Douglas Gregordfca6f52012-02-13 22:00:16 +0000384 /// \brief Note that a local declaration has been transformed by this
385 /// transformer.
386 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000387 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000388 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
389 /// the transformer itself has to transform the declarations. This routine
390 /// can be overridden by a subclass that keeps track of such mappings.
391 void transformedLocalDecl(Decl *Old, Decl *New) {
392 TransformedLocalDecls[Old] = New;
393 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000394
Douglas Gregor43959a92009-08-20 07:17:43 +0000395 /// \brief Transform the definition of the given declaration.
396 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000397 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000398 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000399 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
400 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000401 }
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor6cd21982009-10-20 05:58:46 +0000403 /// \brief Transform the given declaration, which was the first part of a
404 /// nested-name-specifier in a member access expression.
405 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000407 /// identifier in a nested-name-specifier of a member access expression, e.g.,
408 /// the \c T in \c x->T::member
409 ///
410 /// By default, invokes TransformDecl() to transform the declaration.
411 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000412 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
413 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000414 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000415
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000416 /// \brief Transform the given nested-name-specifier with source-location
417 /// information.
418 ///
419 /// By default, transforms all of the types and declarations within the
420 /// nested-name-specifier. Subclasses may override this function to provide
421 /// alternate behavior.
422 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
423 NestedNameSpecifierLoc NNS,
424 QualType ObjectType = QualType(),
425 NamedDecl *FirstQualifierInScope = 0);
426
Douglas Gregor81499bb2009-09-03 22:13:48 +0000427 /// \brief Transform the given declaration name.
428 ///
429 /// By default, transforms the types of conversion function, constructor,
430 /// and destructor names and then (if needed) rebuilds the declaration name.
431 /// Identifiers and selectors are returned unmodified. Sublcasses may
432 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000433 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000434 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000435
Douglas Gregor577f75a2009-08-04 16:50:30 +0000436 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000437 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000438 /// \param SS The nested-name-specifier that qualifies the template
439 /// name. This nested-name-specifier must already have been transformed.
440 ///
441 /// \param Name The template name to transform.
442 ///
443 /// \param NameLoc The source location of the template name.
444 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000445 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000446 /// access expression, this is the type of the object whose member template
447 /// is being referenced.
448 ///
449 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
450 /// also refers to a name within the current (lexical) scope, this is the
451 /// declaration it refers to.
452 ///
453 /// By default, transforms the template name by transforming the declarations
454 /// and nested-name-specifiers that occur within the template name.
455 /// Subclasses may override this function to provide alternate behavior.
456 TemplateName TransformTemplateName(CXXScopeSpec &SS,
457 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000458 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000459 QualType ObjectType = QualType(),
460 NamedDecl *FirstQualifierInScope = 0);
461
Douglas Gregor577f75a2009-08-04 16:50:30 +0000462 /// \brief Transform the given template argument.
463 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000464 /// By default, this operation transforms the type, expression, or
465 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000466 /// new template argument from the transformed result. Subclasses may
467 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000468 ///
469 /// Returns true if there was an error.
470 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
471 TemplateArgumentLoc &Output);
472
Douglas Gregorfcc12532010-12-20 17:31:10 +0000473 /// \brief Transform the given set of template arguments.
474 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000475 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000476 /// in the input set using \c TransformTemplateArgument(), and appends
477 /// the transformed arguments to the output list.
478 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000479 /// Note that this overload of \c TransformTemplateArguments() is merely
480 /// a convenience function. Subclasses that wish to override this behavior
481 /// should override the iterator-based member template version.
482 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000483 /// \param Inputs The set of template arguments to be transformed.
484 ///
485 /// \param NumInputs The number of template arguments in \p Inputs.
486 ///
487 /// \param Outputs The set of transformed template arguments output by this
488 /// routine.
489 ///
490 /// Returns true if an error occurred.
491 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
492 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000493 TemplateArgumentListInfo &Outputs) {
494 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
495 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000496
497 /// \brief Transform the given set of template arguments.
498 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000499 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000500 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000501 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000502 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000503 /// \param First An iterator to the first template argument.
504 ///
505 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506 ///
507 /// \param Outputs The set of transformed template arguments output by this
508 /// routine.
509 ///
510 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000511 template<typename InputIterator>
512 bool TransformTemplateArguments(InputIterator First,
513 InputIterator Last,
514 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000515
John McCall833ca992009-10-29 08:12:44 +0000516 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
517 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
518 TemplateArgumentLoc &ArgLoc);
519
John McCalla93c9342009-12-07 02:54:59 +0000520 /// \brief Fakes up a TypeSourceInfo for a type.
521 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
522 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000523 getDerived().getBaseLocation());
524 }
Mike Stump1eb44332009-09-09 15:08:12 +0000525
John McCalla2becad2009-10-21 00:40:46 +0000526#define ABSTRACT_TYPELOC(CLASS, PARENT)
527#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000528 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000529#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000530
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000531 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
532 FunctionProtoTypeLoc TL,
533 CXXRecordDecl *ThisContext,
534 unsigned ThisTypeQuals);
535
John Wiegley28bbe4b2011-04-28 01:08:34 +0000536 StmtResult
537 TransformSEHHandler(Stmt *Handler);
538
Chad Rosier4a9d7952012-08-08 18:46:20 +0000539 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000540 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
541 TemplateSpecializationTypeLoc TL,
542 TemplateName Template);
543
Chad Rosier4a9d7952012-08-08 18:46:20 +0000544 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000545 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
546 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000547 TemplateName Template,
548 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000549
Chad Rosier4a9d7952012-08-08 18:46:20 +0000550 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000551 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000552 DependentTemplateSpecializationTypeLoc TL,
553 NestedNameSpecifierLoc QualifierLoc);
554
John McCall21ef0fa2010-03-11 09:03:00 +0000555 /// \brief Transforms the parameters of a function type into the
556 /// given vectors.
557 ///
558 /// The result vectors should be kept in sync; null entries in the
559 /// variables vector are acceptable.
560 ///
561 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000562 bool TransformFunctionTypeParams(SourceLocation Loc,
563 ParmVarDecl **Params, unsigned NumParams,
564 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000565 SmallVectorImpl<QualType> &PTypes,
566 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000567
568 /// \brief Transforms a single function-type parameter. Return null
569 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000570 ///
571 /// \param indexAdjustment - A number to add to the parameter's
572 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000573 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000574 int indexAdjustment,
David Blaikiedc84cd52013-02-20 22:23:23 +0000575 Optional<unsigned> NumExpansions,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000576 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000577
John McCall43fed0d2010-11-12 08:19:04 +0000578 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000579
John McCall60d7b3a2010-08-24 06:29:42 +0000580 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
581 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000582
Richard Smith612409e2012-07-25 03:56:55 +0000583 /// \brief Transform the captures and body of a lambda expression.
584 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
585
Richard Smithefeeccf2012-10-21 03:28:35 +0000586 ExprResult TransformAddressOfOperand(Expr *E);
587 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
588 bool IsAddressOfOperand);
589
Douglas Gregor43959a92009-08-20 07:17:43 +0000590#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000591 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000592#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000593 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000594#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000595#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000596
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 /// \brief Build a new pointer type given its pointee type.
598 ///
599 /// By default, performs semantic analysis when building the pointer type.
600 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000601 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602
603 /// \brief Build a new block pointer type given its pointee type.
604 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000605 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000607 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
John McCall85737a72009-10-30 00:06:24 +0000609 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ///
John McCall85737a72009-10-30 00:06:24 +0000611 /// By default, performs semantic analysis when building the
612 /// reference type. Subclasses may override this routine to provide
613 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 ///
John McCall85737a72009-10-30 00:06:24 +0000615 /// \param LValue whether the type was written with an lvalue sigil
616 /// or an rvalue sigil.
617 QualType RebuildReferenceType(QualType ReferentType,
618 bool LValue,
619 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new member pointer type given the pointee type and the
622 /// class type it refers into.
623 ///
624 /// By default, performs semantic analysis when building the member pointer
625 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000626 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
627 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Douglas Gregor577f75a2009-08-04 16:50:30 +0000629 /// \brief Build a new array type given the element type, size
630 /// modifier, size of the array (if known), size expression, and index type
631 /// qualifiers.
632 ///
633 /// By default, performs semantic analysis when building the array type.
634 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000635 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 QualType RebuildArrayType(QualType ElementType,
637 ArrayType::ArraySizeModifier SizeMod,
638 const llvm::APInt *Size,
639 Expr *SizeExpr,
640 unsigned IndexTypeQuals,
641 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new constant array type given the element type, size
644 /// modifier, (known) size of the array, and index type qualifiers.
645 ///
646 /// By default, performs semantic analysis when building the array type.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000648 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000649 ArrayType::ArraySizeModifier SizeMod,
650 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000651 unsigned IndexTypeQuals,
652 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// \brief Build a new incomplete array type given the element type, size
655 /// modifier, and index type qualifiers.
656 ///
657 /// By default, performs semantic analysis when building the array type.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000659 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000661 unsigned IndexTypeQuals,
662 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 /// size modifier, size expression, and index type qualifiers.
666 ///
667 /// By default, performs semantic analysis when building the array type.
668 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000669 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000671 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000672 unsigned IndexTypeQuals,
673 SourceRange BracketsRange);
674
Mike Stump1eb44332009-09-09 15:08:12 +0000675 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 /// size modifier, size expression, and index type qualifiers.
677 ///
678 /// By default, performs semantic analysis when building the array type.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000680 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000682 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 unsigned IndexTypeQuals,
684 SourceRange BracketsRange);
685
686 /// \brief Build a new vector type given the element type and
687 /// number of elements.
688 ///
689 /// By default, performs semantic analysis when building the vector type.
690 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000691 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000692 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000693
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694 /// \brief Build a new extended vector type given the element type and
695 /// number of elements.
696 ///
697 /// By default, performs semantic analysis when building the vector type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
700 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000701
702 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 /// given the element type and number of elements.
704 ///
705 /// By default, performs semantic analysis when building the vector type.
706 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000707 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000708 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000709 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 /// \brief Build a new function type.
712 ///
713 /// By default, performs semantic analysis when building the function type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildFunctionProtoType(QualType T,
Jordan Rosebea522f2013-03-08 21:51:21 +0000716 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +0000717 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
John McCalla2becad2009-10-21 00:40:46 +0000719 /// \brief Build a new unprototyped function type.
720 QualType RebuildFunctionNoProtoType(QualType ResultType);
721
John McCalled976492009-12-04 22:46:56 +0000722 /// \brief Rebuild an unresolved typename type, given the decl that
723 /// the UnresolvedUsingTypenameDecl was transformed to.
724 QualType RebuildUnresolvedUsingType(Decl *D);
725
Douglas Gregor577f75a2009-08-04 16:50:30 +0000726 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000727 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000728 return SemaRef.Context.getTypeDeclType(Typedef);
729 }
730
731 /// \brief Build a new class/struct/union type.
732 QualType RebuildRecordType(RecordDecl *Record) {
733 return SemaRef.Context.getTypeDeclType(Record);
734 }
735
736 /// \brief Build a new Enum type.
737 QualType RebuildEnumType(EnumDecl *Enum) {
738 return SemaRef.Context.getTypeDeclType(Enum);
739 }
John McCall7da24312009-09-05 00:15:47 +0000740
Mike Stump1eb44332009-09-09 15:08:12 +0000741 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 ///
743 /// By default, performs semantic analysis when building the typeof type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000745 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746
Mike Stump1eb44332009-09-09 15:08:12 +0000747 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000748 ///
749 /// By default, builds a new TypeOfType with the given underlying type.
750 QualType RebuildTypeOfType(QualType Underlying);
751
Sean Huntca63c202011-05-24 22:41:36 +0000752 /// \brief Build a new unary transform type.
753 QualType RebuildUnaryTransformType(QualType BaseType,
754 UnaryTransformType::UTTKind UKind,
755 SourceLocation Loc);
756
Mike Stump1eb44332009-09-09 15:08:12 +0000757 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000758 ///
759 /// By default, performs semantic analysis when building the decltype type.
760 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000761 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000762
Richard Smith34b41d92011-02-20 03:19:35 +0000763 /// \brief Build a new C++0x auto type.
764 ///
765 /// By default, builds a new AutoType with the given deduced type.
766 QualType RebuildAutoType(QualType Deduced) {
767 return SemaRef.Context.getAutoType(Deduced);
768 }
769
Douglas Gregor577f75a2009-08-04 16:50:30 +0000770 /// \brief Build a new template specialization type.
771 ///
772 /// By default, performs semantic analysis when building the template
773 /// specialization type. Subclasses may override this routine to provide
774 /// different behavior.
775 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000776 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000777 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000778
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000779 /// \brief Build a new parenthesized type.
780 ///
781 /// By default, builds a new ParenType type from the inner type.
782 /// Subclasses may override this routine to provide different behavior.
783 QualType RebuildParenType(QualType InnerType) {
784 return SemaRef.Context.getParenType(InnerType);
785 }
786
Douglas Gregor577f75a2009-08-04 16:50:30 +0000787 /// \brief Build a new qualified name type.
788 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000789 /// By default, builds a new ElaboratedType type from the keyword,
790 /// the nested-name-specifier and the named type.
791 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000792 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
793 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000794 NestedNameSpecifierLoc QualifierLoc,
795 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000796 return SemaRef.Context.getElaboratedType(Keyword,
797 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000798 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000799 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800
801 /// \brief Build a new typename type that refers to a template-id.
802 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000803 /// By default, builds a new DependentNameType type from the
804 /// nested-name-specifier and the given type. Subclasses may override
805 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000806 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000807 ElaboratedTypeKeyword Keyword,
808 NestedNameSpecifierLoc QualifierLoc,
809 const IdentifierInfo *Name,
810 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000811 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000812 // Rebuild the template name.
813 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000814 CXXScopeSpec SS;
815 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000816 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000818
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000819 if (InstName.isNull())
820 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 // If it's still dependent, make a dependent specialization.
823 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
825 QualifierLoc.getNestedNameSpecifier(),
826 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000827 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000829 // Otherwise, make an elaborated type wrapping a non-dependent
830 // specialization.
831 QualType T =
832 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
833 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000834
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000835 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
836 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
838 return SemaRef.Context.getElaboratedType(Keyword,
839 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000840 T);
841 }
842
Douglas Gregor577f75a2009-08-04 16:50:30 +0000843 /// \brief Build a new typename type that refers to an identifier.
844 ///
845 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000847 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000848 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000850 NestedNameSpecifierLoc QualifierLoc,
851 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000853 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000854 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000857 // If the name is still dependent, just build a new dependent name type.
858 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000859 return SemaRef.Context.getDependentNameType(Keyword,
860 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000861 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000862 }
863
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000864 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000865 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000866 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867
868 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
869
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000870 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000871 // into a non-dependent elaborated-type-specifier. Find the tag we're
872 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000874 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
875 if (!DC)
876 return QualType();
877
John McCall56138762010-05-27 06:40:31 +0000878 if (SemaRef.RequireCompleteDeclContext(SS, DC))
879 return QualType();
880
Douglas Gregor40336422010-03-31 22:19:08 +0000881 TagDecl *Tag = 0;
882 SemaRef.LookupQualifiedName(Result, DC);
883 switch (Result.getResultKind()) {
884 case LookupResult::NotFound:
885 case LookupResult::NotFoundInCurrentInstantiation:
886 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000887
Douglas Gregor40336422010-03-31 22:19:08 +0000888 case LookupResult::Found:
889 Tag = Result.getAsSingle<TagDecl>();
890 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000891
Douglas Gregor40336422010-03-31 22:19:08 +0000892 case LookupResult::FoundOverloaded:
893 case LookupResult::FoundUnresolvedValue:
894 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000895
Douglas Gregor40336422010-03-31 22:19:08 +0000896 case LookupResult::Ambiguous:
897 // Let the LookupResult structure handle ambiguities.
898 return QualType();
899 }
900
901 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 // Check where the name exists but isn't a tag type and use that to emit
903 // better diagnostics.
904 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
905 SemaRef.LookupQualifiedName(Result, DC);
906 switch (Result.getResultKind()) {
907 case LookupResult::Found:
908 case LookupResult::FoundOverloaded:
909 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000910 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000911 unsigned Kind = 0;
912 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000913 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
914 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000915 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
916 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
917 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000918 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000919 default:
920 // FIXME: Would be nice to highlight just the source range.
921 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
922 << Kind << Id << DC;
923 break;
924 }
Douglas Gregor40336422010-03-31 22:19:08 +0000925 return QualType();
926 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000927
Richard Trieubbf34c02011-06-10 03:11:26 +0000928 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
929 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000930 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000931 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
932 return QualType();
933 }
934
935 // Build the elaborated-type-specifier type.
936 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 return SemaRef.Context.getElaboratedType(Keyword,
938 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000939 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000940 }
Mike Stump1eb44332009-09-09 15:08:12 +0000941
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000942 /// \brief Build a new pack expansion type.
943 ///
944 /// By default, builds a new PackExpansionType type from the given pattern.
945 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000946 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000947 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000948 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000949 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000950 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
951 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000952 }
953
Eli Friedmanb001de72011-10-06 23:00:33 +0000954 /// \brief Build a new atomic type given its value type.
955 ///
956 /// By default, performs semantic analysis when building the atomic type.
957 /// Subclasses may override this routine to provide different behavior.
958 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
959
Douglas Gregord1067e52009-08-06 06:41:21 +0000960 /// \brief Build a new template name given a nested name specifier, a flag
961 /// indicating whether the "template" keyword was provided, and the template
962 /// that the template name refers to.
963 ///
964 /// By default, builds the new template name directly. Subclasses may override
965 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000966 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000967 bool TemplateKW,
968 TemplateDecl *Template);
969
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 /// \brief Build a new template name given a nested name specifier and the
971 /// name that is referred to as a template.
972 ///
973 /// By default, performs semantic analysis to determine whether the name can
974 /// be resolved to a specific template, then builds the appropriate kind of
975 /// template name. Subclasses may override this routine to provide different
976 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000977 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
978 const IdentifierInfo &Name,
979 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000980 QualType ObjectType,
981 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000982
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000983 /// \brief Build a new template name given a nested name specifier and the
984 /// overloaded operator name that is referred to as a template.
985 ///
986 /// By default, performs semantic analysis to determine whether the name can
987 /// be resolved to a specific template, then builds the appropriate kind of
988 /// template name. Subclasses may override this routine to provide different
989 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000990 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000991 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000992 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000993 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000994
995 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000996 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997 ///
998 /// By default, performs semantic analysis to determine whether the name can
999 /// be resolved to a specific template, then builds the appropriate kind of
1000 /// template name. Subclasses may override this routine to provide different
1001 /// behavior.
1002 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1003 const TemplateArgument &ArgPack) {
1004 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1005 }
1006
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 /// \brief Build a new compound statement.
1008 ///
1009 /// By default, performs semantic analysis to build the new statement.
1010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001011 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 MultiStmtArg Statements,
1013 SourceLocation RBraceLoc,
1014 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001015 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 IsStmtExpr);
1017 }
1018
1019 /// \brief Build a new case statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001023 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001024 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001026 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 ColonLoc);
1030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Attach the body to a new case statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001037 getSema().ActOnCaseStmtBody(S, Body);
1038 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 }
Mike Stump1eb44332009-09-09 15:08:12 +00001040
Douglas Gregor43959a92009-08-20 07:17:43 +00001041 /// \brief Build a new default statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001045 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Stmt *SubStmt) {
1048 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 /*CurScope=*/0);
1050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001056 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1057 SourceLocation ColonLoc, Stmt *SubStmt) {
1058 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 }
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Richard Smith534986f2012-04-14 00:33:13 +00001061 /// \brief Build a new label statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001065 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1066 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001067 Stmt *SubStmt) {
1068 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1069 }
1070
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 /// \brief Build a new "if" statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001075 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001076 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001078 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 }
Mike Stump1eb44332009-09-09 15:08:12 +00001080
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 /// \brief Start building a new switch statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001085 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001086 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001087 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001088 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
Mike Stump1eb44332009-09-09 15:08:12 +00001090
Douglas Gregor43959a92009-08-20 07:17:43 +00001091 /// \brief Attach the body to the switch statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001095 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001096 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
1099
1100 /// \brief Build a new while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001104 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1105 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001106 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001107 }
Mike Stump1eb44332009-09-09 15:08:12 +00001108
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 /// \brief Build a new do-while statement.
1110 ///
1111 /// By default, performs semantic analysis to build the new statement.
1112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001113 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001114 SourceLocation WhileLoc, SourceLocation LParenLoc,
1115 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001116 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1117 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001118 }
1119
1120 /// \brief Build a new for statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001124 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001125 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001126 VarDecl *CondVar, Sema::FullExprArg Inc,
1127 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor43959a92009-08-20 07:17:43 +00001132 /// \brief Build a new goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001136 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1137 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001138 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001139 }
1140
1141 /// \brief Build a new indirect goto statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001145 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 SourceLocation StarLoc,
1147 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001148 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001149 }
Mike Stump1eb44332009-09-09 15:08:12 +00001150
Douglas Gregor43959a92009-08-20 07:17:43 +00001151 /// \brief Build a new return statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001155 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001156 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001157 }
Mike Stump1eb44332009-09-09 15:08:12 +00001158
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 /// \brief Build a new declaration statement.
1160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001163 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001164 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001165 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001166 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1167 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 }
Mike Stump1eb44332009-09-09 15:08:12 +00001169
Anders Carlsson703e3942010-01-24 05:50:09 +00001170 /// \brief Build a new inline asm statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001174 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1175 bool IsVolatile, unsigned NumOutputs,
1176 unsigned NumInputs, IdentifierInfo **Names,
1177 MultiExprArg Constraints, MultiExprArg Exprs,
1178 Expr *AsmString, MultiExprArg Clobbers,
1179 SourceLocation RParenLoc) {
1180 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1181 NumInputs, Names, Constraints, Exprs,
1182 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001183 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001184
Chad Rosier8cd64b42012-06-11 20:47:18 +00001185 /// \brief Build a new MS style inline asm statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001189 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1190 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001191 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001192 }
1193
James Dennett699c9042012-06-15 07:13:21 +00001194 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001198 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001199 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001200 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001201 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001202 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001203 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001204 }
1205
Douglas Gregorbe270a02010-04-26 17:57:08 +00001206 /// \brief Rebuild an Objective-C exception declaration.
1207 ///
1208 /// By default, performs semantic analysis to build the new declaration.
1209 /// Subclasses may override this routine to provide different behavior.
1210 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1211 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001212 return getSema().BuildObjCExceptionDecl(TInfo, T,
1213 ExceptionDecl->getInnerLocStart(),
1214 ExceptionDecl->getLocation(),
1215 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001217
James Dennett699c9042012-06-15 07:13:21 +00001218 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001222 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001223 SourceLocation RParenLoc,
1224 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001225 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001227 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001229
James Dennett699c9042012-06-15 07:13:21 +00001230 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001234 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001235 Stmt *Body) {
1236 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001237 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001238
James Dennett699c9042012-06-15 07:13:21 +00001239 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001240 ///
1241 /// By default, performs semantic analysis to build the new statement.
1242 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001243 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001244 Expr *Operand) {
1245 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001247
James Dennett699c9042012-06-15 07:13:21 +00001248 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
1252 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1253 Expr *object) {
1254 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1255 }
1256
James Dennett699c9042012-06-15 07:13:21 +00001257 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001259 /// By default, performs semantic analysis to build the new statement.
1260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001261 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001262 Expr *Object, Stmt *Body) {
1263 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001264 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001265
James Dennett699c9042012-06-15 07:13:21 +00001266 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001267 ///
1268 /// By default, performs semantic analysis to build the new statement.
1269 /// Subclasses may override this routine to provide different behavior.
1270 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1271 Stmt *Body) {
1272 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1273 }
John McCall990567c2011-07-27 01:07:15 +00001274
Douglas Gregorc3203e72010-04-22 23:10:45 +00001275 /// \brief Build a new Objective-C fast enumeration statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001279 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001280 Stmt *Element,
1281 Expr *Collection,
1282 SourceLocation RParenLoc,
1283 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001284 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001285 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001286 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001287 RParenLoc);
1288 if (ForEachStmt.isInvalid())
1289 return StmtError();
1290
1291 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001293
Douglas Gregor43959a92009-08-20 07:17:43 +00001294 /// \brief Build a new C++ exception declaration.
1295 ///
1296 /// By default, performs semantic analysis to build the new decaration.
1297 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001298 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001299 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001300 SourceLocation StartLoc,
1301 SourceLocation IdLoc,
1302 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001303 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1304 StartLoc, IdLoc, Id);
1305 if (Var)
1306 getSema().CurContext->addDecl(Var);
1307 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001308 }
1309
1310 /// \brief Build a new C++ catch statement.
1311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001315 VarDecl *ExceptionDecl,
1316 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001317 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1318 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001319 }
Mike Stump1eb44332009-09-09 15:08:12 +00001320
Douglas Gregor43959a92009-08-20 07:17:43 +00001321 /// \brief Build a new C++ try statement.
1322 ///
1323 /// By default, performs semantic analysis to build the new statement.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001326 Stmt *TryBlock,
1327 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001328 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001329 }
Mike Stump1eb44332009-09-09 15:08:12 +00001330
Richard Smithad762fc2011-04-14 22:09:26 +00001331 /// \brief Build a new C++0x range-based for statement.
1332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
1335 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1336 SourceLocation ColonLoc,
1337 Stmt *Range, Stmt *BeginEnd,
1338 Expr *Cond, Expr *Inc,
1339 Stmt *LoopVar,
1340 SourceLocation RParenLoc) {
1341 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001342 Cond, Inc, LoopVar, RParenLoc,
1343 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001344 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001345
1346 /// \brief Build a new C++0x range-based for statement.
1347 ///
1348 /// By default, performs semantic analysis to build the new statement.
1349 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001350 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001351 bool IsIfExists,
1352 NestedNameSpecifierLoc QualifierLoc,
1353 DeclarationNameInfo NameInfo,
1354 Stmt *Nested) {
1355 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1356 QualifierLoc, NameInfo, Nested);
1357 }
1358
Richard Smithad762fc2011-04-14 22:09:26 +00001359 /// \brief Attach body to a C++0x range-based for statement.
1360 ///
1361 /// By default, performs semantic analysis to finish the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1363 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1364 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1365 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001366
John Wiegley28bbe4b2011-04-28 01:08:34 +00001367 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1368 SourceLocation TryLoc,
1369 Stmt *TryBlock,
1370 Stmt *Handler) {
1371 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1372 }
1373
1374 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1375 Expr *FilterExpr,
1376 Stmt *Block) {
1377 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1378 }
1379
1380 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1381 Stmt *Block) {
1382 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1383 }
1384
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// \brief Build a new expression that references a declaration.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001389 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001390 LookupResult &R,
1391 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001392 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1393 }
1394
1395
1396 /// \brief Build a new expression that references a declaration.
1397 ///
1398 /// By default, performs semantic analysis to build the new expression.
1399 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001400 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001401 ValueDecl *VD,
1402 const DeclarationNameInfo &NameInfo,
1403 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001404 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001405 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001406
1407 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001408
1409 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 }
Mike Stump1eb44332009-09-09 15:08:12 +00001411
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001413 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001416 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001418 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001419 }
1420
Douglas Gregora71d8192009-09-04 17:36:40 +00001421 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001422 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001425 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001426 SourceLocation OperatorLoc,
1427 bool isArrow,
1428 CXXScopeSpec &SS,
1429 TypeSourceInfo *ScopeType,
1430 SourceLocation CCLoc,
1431 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001432 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001435 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001439 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001440 Expr *SubExpr) {
1441 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 }
Mike Stump1eb44332009-09-09 15:08:12 +00001443
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001444 /// \brief Build a new builtin offsetof expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001448 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001449 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001450 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001451 unsigned NumComponents,
1452 SourceLocation RParenLoc) {
1453 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1454 NumComponents, RParenLoc);
1455 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001456
1457 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001458 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001459 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001462 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1463 SourceLocation OpLoc,
1464 UnaryExprOrTypeTrait ExprKind,
1465 SourceRange R) {
1466 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 }
1468
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001469 /// \brief Build a new sizeof, alignof or vec step expression with an
1470 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001471 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001474 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1475 UnaryExprOrTypeTrait ExprKind,
1476 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001477 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001478 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001480 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001481
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001482 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 }
Mike Stump1eb44332009-09-09 15:08:12 +00001484
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001486 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001489 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001491 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001493 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1494 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 RBracketLoc);
1496 }
1497
1498 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001499 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 /// By default, performs semantic analysis to build the new expression.
1501 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001502 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001504 SourceLocation RParenLoc,
1505 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001506 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001507 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 }
1509
1510 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001511 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001514 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001515 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001516 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001517 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001518 const DeclarationNameInfo &MemberNameInfo,
1519 ValueDecl *Member,
1520 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001521 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001522 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001523 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1524 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001525 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001526 // We have a reference to an unnamed field. This is always the
1527 // base of an anonymous struct/union member access, i.e. the
1528 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001529 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001530 assert(Member->getType()->isRecordType() &&
1531 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Richard Smith9138b4e2011-10-26 19:06:56 +00001533 BaseResult =
1534 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001535 QualifierLoc.getNestedNameSpecifier(),
1536 FoundDecl, Member);
1537 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001538 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001539 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001540 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001541 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001542 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001543 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001544 cast<FieldDecl>(Member)->getType(),
1545 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001546 return getSema().Owned(ME);
1547 }
Mike Stump1eb44332009-09-09 15:08:12 +00001548
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001549 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001550 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001551
John Wiegley429bb272011-04-08 18:41:53 +00001552 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001553 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001554
John McCall6bb80172010-03-30 21:47:33 +00001555 // FIXME: this involves duplicating earlier analysis in a lot of
1556 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001557 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001558 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001559 R.resolveKind();
1560
John McCall9ae2f072010-08-23 23:25:46 +00001561 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001562 SS, TemplateKWLoc,
1563 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001564 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001572 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001573 Expr *LHS, Expr *RHS) {
1574 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 }
1576
1577 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001578 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001581 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001582 SourceLocation QuestionLoc,
1583 Expr *LHS,
1584 SourceLocation ColonLoc,
1585 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001586 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1587 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 }
1589
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001591 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001594 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001595 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001597 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001598 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 }
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001603 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001606 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001607 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001610 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001611 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 }
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001615 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001618 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 SourceLocation OpLoc,
1620 SourceLocation AccessorLoc,
1621 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001622
John McCall129e2df2009-11-30 22:42:35 +00001623 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001624 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001625 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001626 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001627 SS, SourceLocation(),
1628 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001629 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001630 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 }
Mike Stump1eb44332009-09-09 15:08:12 +00001632
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001634 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001637 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001638 MultiExprArg Inits,
1639 SourceLocation RBraceLoc,
1640 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001642 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001643 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001644 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001645
Douglas Gregore48319a2009-11-09 17:16:50 +00001646 // Patch in the result type we were given, which may have been computed
1647 // when the initial InitListExpr was built.
1648 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1649 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001650 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 MultiExprArg ArrayExprs,
1659 SourceLocation EqualOrColonLoc,
1660 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001661 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001664 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001667
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001668 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001672 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 /// By default, builds the implicit value initialization without performing
1674 /// any semantic analysis. Subclasses may override this routine to provide
1675 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001676 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1678 }
Mike Stump1eb44332009-09-09 15:08:12 +00001679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001681 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001685 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001686 SourceLocation RParenLoc) {
1687 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001689 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 }
1691
1692 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001693 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001696 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001697 MultiExprArg SubExprs,
1698 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001699 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 }
Mike Stump1eb44332009-09-09 15:08:12 +00001701
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001703 ///
1704 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// rather than attempting to map the label statement itself.
1706 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001707 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001708 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001709 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 }
Mike Stump1eb44332009-09-09 15:08:12 +00001711
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001713 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001716 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001719 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// \brief Build a new __builtin_choose_expr expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001726 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001727 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 SourceLocation RParenLoc) {
1729 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001730 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 RParenLoc);
1732 }
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Peter Collingbournef111d932011-04-15 00:35:48 +00001734 /// \brief Build a new generic selection expression.
1735 ///
1736 /// By default, performs semantic analysis to build the new expression.
1737 /// Subclasses may override this routine to provide different behavior.
1738 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1739 SourceLocation DefaultLoc,
1740 SourceLocation RParenLoc,
1741 Expr *ControllingExpr,
1742 TypeSourceInfo **Types,
1743 Expr **Exprs,
1744 unsigned NumAssocs) {
1745 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1746 ControllingExpr, Types, Exprs,
1747 NumAssocs);
1748 }
1749
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 /// \brief Build a new overloaded operator call expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// The semantic analysis provides the behavior of template instantiation,
1754 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001755 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 /// argument-dependent lookup, etc. Subclasses may override this routine to
1757 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001758 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001760 Expr *Callee,
1761 Expr *First,
1762 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001763
1764 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 /// reinterpret_cast.
1766 ///
1767 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001768 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001770 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 Stmt::StmtClass Class,
1772 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001773 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 SourceLocation RAngleLoc,
1775 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001776 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation RParenLoc) {
1778 switch (Class) {
1779 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001780 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001781 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783
1784 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001785 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001786 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001787 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001790 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001791 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001792 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001796 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001797 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001799
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001801 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 }
Mike Stump1eb44332009-09-09 15:08:12 +00001804
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 /// \brief Build a new C++ static_cast expression.
1806 ///
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001809 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001811 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001812 SourceLocation RAngleLoc,
1813 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001814 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001816 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001817 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001818 SourceRange(LAngleLoc, RAngleLoc),
1819 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 }
1821
1822 /// \brief Build a new C++ dynamic_cast expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001826 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001828 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 SourceLocation RAngleLoc,
1830 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001831 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001833 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001834 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001835 SourceRange(LAngleLoc, RAngleLoc),
1836 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 }
1838
1839 /// \brief Build a new C++ reinterpret_cast expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001843 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001845 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 SourceLocation RAngleLoc,
1847 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001848 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001850 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001851 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001852 SourceRange(LAngleLoc, RAngleLoc),
1853 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 }
1855
1856 /// \brief Build a new C++ const_cast expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001860 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001862 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 SourceLocation RAngleLoc,
1864 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001865 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001867 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001868 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001869 SourceRange(LAngleLoc, RAngleLoc),
1870 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 }
Mike Stump1eb44332009-09-09 15:08:12 +00001872
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 /// \brief Build a new C++ functional-style cast expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001877 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1878 SourceLocation LParenLoc,
1879 Expr *Sub,
1880 SourceLocation RParenLoc) {
1881 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001882 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 RParenLoc);
1884 }
Mike Stump1eb44332009-09-09 15:08:12 +00001885
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 /// \brief Build a new C++ typeid(type) expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001891 SourceLocation TypeidLoc,
1892 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001894 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001895 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 }
Mike Stump1eb44332009-09-09 15:08:12 +00001897
Francois Pichet01b7c302010-09-08 12:20:18 +00001898
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 /// \brief Build a new C++ typeid(expr) expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001903 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001904 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001905 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001907 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001908 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001909 }
1910
Francois Pichet01b7c302010-09-08 12:20:18 +00001911 /// \brief Build a new C++ __uuidof(type) expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
1915 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1916 SourceLocation TypeidLoc,
1917 TypeSourceInfo *Operand,
1918 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001919 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001920 RParenLoc);
1921 }
1922
1923 /// \brief Build a new C++ __uuidof(expr) expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
1927 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1928 SourceLocation TypeidLoc,
1929 Expr *Operand,
1930 SourceLocation RParenLoc) {
1931 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1932 RParenLoc);
1933 }
1934
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// \brief Build a new C++ "this" expression.
1936 ///
1937 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001938 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001939 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001941 QualType ThisType,
1942 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001943 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001945 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1946 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 }
1948
1949 /// \brief Build a new C++ throw expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001953 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1954 bool IsThrownVariableInScope) {
1955 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 }
1957
1958 /// \brief Build a new C++ default-argument expression.
1959 ///
1960 /// By default, builds a new default-argument expression, which does not
1961 /// require any semantic analysis. Subclasses may override this routine to
1962 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001963 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001964 ParmVarDecl *Param) {
1965 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1966 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 }
1968
1969 /// \brief Build a new C++ zero-initialization expression.
1970 ///
1971 /// By default, performs semantic analysis to build the new expression.
1972 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001973 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1974 SourceLocation LParenLoc,
1975 SourceLocation RParenLoc) {
1976 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001977 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001978 }
Mike Stump1eb44332009-09-09 15:08:12 +00001979
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 /// \brief Build a new C++ "new" expression.
1981 ///
1982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001984 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001985 bool UseGlobal,
1986 SourceLocation PlacementLParen,
1987 MultiExprArg PlacementArgs,
1988 SourceLocation PlacementRParen,
1989 SourceRange TypeIdParens,
1990 QualType AllocatedType,
1991 TypeSourceInfo *AllocatedTypeInfo,
1992 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001993 SourceRange DirectInitRange,
1994 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001995 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001997 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001999 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002000 AllocatedType,
2001 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002002 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002003 DirectInitRange,
2004 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 }
Mike Stump1eb44332009-09-09 15:08:12 +00002006
Douglas Gregorb98b1992009-08-11 05:31:07 +00002007 /// \brief Build a new C++ "delete" expression.
2008 ///
2009 /// By default, performs semantic analysis to build the new expression.
2010 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002011 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002012 bool IsGlobalDelete,
2013 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002014 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002016 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 }
Mike Stump1eb44332009-09-09 15:08:12 +00002018
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 /// \brief Build a new unary type trait expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002023 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002024 SourceLocation StartLoc,
2025 TypeSourceInfo *T,
2026 SourceLocation RParenLoc) {
2027 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 }
2029
Francois Pichet6ad6f282010-12-07 00:08:36 +00002030 /// \brief Build a new binary type trait expression.
2031 ///
2032 /// By default, performs semantic analysis to build the new expression.
2033 /// Subclasses may override this routine to provide different behavior.
2034 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2035 SourceLocation StartLoc,
2036 TypeSourceInfo *LhsT,
2037 TypeSourceInfo *RhsT,
2038 SourceLocation RParenLoc) {
2039 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2040 }
2041
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002042 /// \brief Build a new type trait expression.
2043 ///
2044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
2046 ExprResult RebuildTypeTrait(TypeTrait Trait,
2047 SourceLocation StartLoc,
2048 ArrayRef<TypeSourceInfo *> Args,
2049 SourceLocation RParenLoc) {
2050 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2051 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002052
John Wiegley21ff2e52011-04-28 00:16:57 +00002053 /// \brief Build a new array type trait expression.
2054 ///
2055 /// By default, performs semantic analysis to build the new expression.
2056 /// Subclasses may override this routine to provide different behavior.
2057 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2058 SourceLocation StartLoc,
2059 TypeSourceInfo *TSInfo,
2060 Expr *DimExpr,
2061 SourceLocation RParenLoc) {
2062 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2063 }
2064
John Wiegley55262202011-04-25 06:54:41 +00002065 /// \brief Build a new expression trait expression.
2066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
2069 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2070 SourceLocation StartLoc,
2071 Expr *Queried,
2072 SourceLocation RParenLoc) {
2073 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2074 }
2075
Mike Stump1eb44332009-09-09 15:08:12 +00002076 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002077 /// expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002081 ExprResult RebuildDependentScopeDeclRefExpr(
2082 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002083 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002084 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002085 const TemplateArgumentListInfo *TemplateArgs,
2086 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002087 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002088 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002089
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002090 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002091 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002092 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002093
Richard Smithefeeccf2012-10-21 03:28:35 +00002094 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2095 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002096 }
2097
2098 /// \brief Build a new template-id expression.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002102 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002103 SourceLocation TemplateKWLoc,
2104 LookupResult &R,
2105 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002106 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002107 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2108 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 }
2110
2111 /// \brief Build a new object-construction expression.
2112 ///
2113 /// By default, performs semantic analysis to build the new expression.
2114 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002115 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002116 SourceLocation Loc,
2117 CXXConstructorDecl *Constructor,
2118 bool IsElidable,
2119 MultiExprArg Args,
2120 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002121 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002122 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002123 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002124 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002125 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002126 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002127 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002128 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002129
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002130 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002131 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002132 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002133 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002134 RequiresZeroInit, ConstructKind,
2135 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 }
2137
2138 /// \brief Build a new object-construction expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002142 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2143 SourceLocation LParenLoc,
2144 MultiExprArg Args,
2145 SourceLocation RParenLoc) {
2146 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002147 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002148 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002149 RParenLoc);
2150 }
2151
2152 /// \brief Build a new object-construction expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002156 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2157 SourceLocation LParenLoc,
2158 MultiExprArg Args,
2159 SourceLocation RParenLoc) {
2160 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002161 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002162 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002163 RParenLoc);
2164 }
Mike Stump1eb44332009-09-09 15:08:12 +00002165
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166 /// \brief Build a new member reference expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002170 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002171 QualType BaseType,
2172 bool IsArrow,
2173 SourceLocation OperatorLoc,
2174 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002175 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002176 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002177 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002178 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002179 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002180 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002181
John McCall9ae2f072010-08-23 23:25:46 +00002182 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002183 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002184 SS, TemplateKWLoc,
2185 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002186 MemberNameInfo,
2187 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 }
2189
John McCall129e2df2009-11-30 22:42:35 +00002190 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002191 ///
2192 /// By default, performs semantic analysis to build the new expression.
2193 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002194 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2195 SourceLocation OperatorLoc,
2196 bool IsArrow,
2197 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002198 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002199 NamedDecl *FirstQualifierInScope,
2200 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002201 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002202 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002203 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002204
John McCall9ae2f072010-08-23 23:25:46 +00002205 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002206 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002207 SS, TemplateKWLoc,
2208 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002209 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002210 }
Mike Stump1eb44332009-09-09 15:08:12 +00002211
Sebastian Redl2e156222010-09-10 20:55:43 +00002212 /// \brief Build a new noexcept expression.
2213 ///
2214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
2216 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2217 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2218 }
2219
Douglas Gregoree8aff02011-01-04 17:33:58 +00002220 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002221 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2222 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002223 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002224 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002225 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002226 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2227 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002228 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002229
2230 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2231 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002232 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002233 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002234
Patrick Beardeb382ec2012-04-19 00:25:12 +00002235 /// \brief Build a new Objective-C boxed expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
2239 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2240 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2241 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002242
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002243 /// \brief Build a new Objective-C array literal.
2244 ///
2245 /// By default, performs semantic analysis to build the new expression.
2246 /// Subclasses may override this routine to provide different behavior.
2247 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2248 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002249 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002250 MultiExprArg(Elements, NumElements));
2251 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002252
2253 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002254 Expr *Base, Expr *Key,
2255 ObjCMethodDecl *getterMethod,
2256 ObjCMethodDecl *setterMethod) {
2257 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2258 getterMethod, setterMethod);
2259 }
2260
2261 /// \brief Build a new Objective-C dictionary literal.
2262 ///
2263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
2265 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2266 ObjCDictionaryElement *Elements,
2267 unsigned NumElements) {
2268 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2269 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002270
James Dennett699c9042012-06-15 07:13:21 +00002271 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 ///
2273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002275 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002276 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002277 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002278 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002280 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002281
Douglas Gregor92e986e2010-04-22 16:44:27 +00002282 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002283 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002284 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002285 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002286 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002287 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002288 MultiExprArg Args,
2289 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2291 ReceiverTypeInfo->getType(),
2292 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002293 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002294 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002295 }
2296
2297 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002298 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002299 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002300 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002301 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002302 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002303 MultiExprArg Args,
2304 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002305 return SemaRef.BuildInstanceMessage(Receiver,
2306 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002307 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002308 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002309 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002310 }
2311
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002312 /// \brief Build a new Objective-C ivar reference expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002316 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 SourceLocation IvarLoc,
2318 bool IsArrow, bool IsFreeIvar) {
2319 // FIXME: We lose track of the IsFreeIvar bit.
2320 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002321 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002322 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2323 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002324 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002326 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002327 false);
John Wiegley429bb272011-04-08 18:41:53 +00002328 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002329 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002330
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002331 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002332 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002333
John Wiegley429bb272011-04-08 18:41:53 +00002334 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002335 /*FIXME:*/IvarLoc, IsArrow,
2336 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002337 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002338 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002339 /*TemplateArgs=*/0);
2340 }
Douglas Gregore3303542010-04-26 20:47:02 +00002341
2342 /// \brief Build a new Objective-C property reference expression.
2343 ///
2344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002346 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002347 ObjCPropertyDecl *Property,
2348 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002349 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002350 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002351 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2352 Sema::LookupMemberName);
2353 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002354 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002355 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002356 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002357 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002358 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002359
Douglas Gregore3303542010-04-26 20:47:02 +00002360 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002361 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362
John Wiegley429bb272011-04-08 18:41:53 +00002363 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002364 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002365 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002366 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002368 /*TemplateArgs=*/0);
2369 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370
John McCall12f78a62010-12-02 01:19:52 +00002371 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002372 ///
2373 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002374 /// Subclasses may override this routine to provide different behavior.
2375 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2376 ObjCMethodDecl *Getter,
2377 ObjCMethodDecl *Setter,
2378 SourceLocation PropertyLoc) {
2379 // Since these expressions can only be value-dependent, we do not
2380 // need to perform semantic analysis again.
2381 return Owned(
2382 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2383 VK_LValue, OK_ObjCProperty,
2384 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002385 }
2386
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002387 /// \brief Build a new Objective-C "isa" expression.
2388 ///
2389 /// By default, performs semantic analysis to build the new expression.
2390 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002391 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002392 bool IsArrow) {
2393 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002394 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2396 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002397 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002398 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002399 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002400 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002401 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002402
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002403 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002404 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002405
John Wiegley429bb272011-04-08 18:41:53 +00002406 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002407 /*FIXME:*/IsaLoc, IsArrow,
2408 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002409 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002410 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002411 /*TemplateArgs=*/0);
2412 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002413
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414 /// \brief Build a new shuffle vector expression.
2415 ///
2416 /// By default, performs semantic analysis to build the new expression.
2417 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002418 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002419 MultiExprArg SubExprs,
2420 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002421 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002422 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002423 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2424 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2425 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002426 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Douglas Gregorb98b1992009-08-11 05:31:07 +00002428 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002429 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002430 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2431 SemaRef.Context.BuiltinFnTy,
2432 VK_RValue, BuiltinLoc);
2433 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2434 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2435 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002436
2437 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002438 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002439 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002440 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002441 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002442 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002443
Douglas Gregorb98b1992009-08-11 05:31:07 +00002444 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002445 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002446 }
John McCall43fed0d2010-11-12 08:19:04 +00002447
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002448 /// \brief Build a new template argument pack expansion.
2449 ///
2450 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002451 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002452 /// different behavior.
2453 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002454 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002455 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002456 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002457 case TemplateArgument::Expression: {
2458 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002459 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2460 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002461 if (Result.isInvalid())
2462 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002463
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002464 return TemplateArgumentLoc(Result.get(), Result.get());
2465 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002466
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002467 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002468 return TemplateArgumentLoc(TemplateArgument(
2469 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002470 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002471 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002472 Pattern.getTemplateNameLoc(),
2473 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002474
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002475 case TemplateArgument::Null:
2476 case TemplateArgument::Integral:
2477 case TemplateArgument::Declaration:
2478 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002479 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002480 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002481 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002482
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002483 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002484 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002485 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002486 EllipsisLoc,
2487 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002488 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2489 Expansion);
2490 break;
2491 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002492
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002493 return TemplateArgumentLoc();
2494 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002495
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002496 /// \brief Build a new expression pack expansion.
2497 ///
2498 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002499 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002501 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002502 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002503 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002505
2506 /// \brief Build a new atomic operation expression.
2507 ///
2508 /// By default, performs semantic analysis to build the new expression.
2509 /// Subclasses may override this routine to provide different behavior.
2510 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2511 MultiExprArg SubExprs,
2512 QualType RetTy,
2513 AtomicExpr::AtomicOp Op,
2514 SourceLocation RParenLoc) {
2515 // Just create the expression; there is not any interesting semantic
2516 // analysis here because we can't actually build an AtomicExpr until
2517 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002518 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002519 RParenLoc);
2520 }
2521
John McCall43fed0d2010-11-12 08:19:04 +00002522private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002523 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2524 QualType ObjectType,
2525 NamedDecl *FirstQualifierInScope,
2526 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002527
2528 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2529 QualType ObjectType,
2530 NamedDecl *FirstQualifierInScope,
2531 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002532};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002533
Douglas Gregor43959a92009-08-20 07:17:43 +00002534template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002535StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002536 if (!S)
2537 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002538
Douglas Gregor43959a92009-08-20 07:17:43 +00002539 switch (S->getStmtClass()) {
2540 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 // Transform individual statement nodes
2543#define STMT(Node, Parent) \
2544 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002545#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002546#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002547#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002548
Douglas Gregor43959a92009-08-20 07:17:43 +00002549 // Transform expressions by calling TransformExpr.
2550#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002551#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002552#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002553#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002554 {
John McCall60d7b3a2010-08-24 06:29:42 +00002555 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002556 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002557 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002558
Richard Smith41956372013-01-14 22:39:08 +00002559 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002560 }
Mike Stump1eb44332009-09-09 15:08:12 +00002561 }
2562
John McCall3fa5cae2010-10-26 07:05:15 +00002563 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002564}
Mike Stump1eb44332009-09-09 15:08:12 +00002565
2566
Douglas Gregor670444e2009-08-04 22:27:00 +00002567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002568ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002569 if (!E)
2570 return SemaRef.Owned(E);
2571
2572 switch (E->getStmtClass()) {
2573 case Stmt::NoStmtClass: break;
2574#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002575#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002576#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002577 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002578#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002579 }
2580
John McCall3fa5cae2010-10-26 07:05:15 +00002581 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002582}
2583
2584template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002585ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2586 bool CXXDirectInit) {
2587 // Initializers are instantiated like expressions, except that various outer
2588 // layers are stripped.
2589 if (!Init)
2590 return SemaRef.Owned(Init);
2591
2592 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2593 Init = ExprTemp->getSubExpr();
2594
2595 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2596 Init = Binder->getSubExpr();
2597
2598 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2599 Init = ICE->getSubExprAsWritten();
2600
Richard Smith5cf15892012-12-21 08:13:35 +00002601 // If this is not a direct-initializer, we only need to reconstruct
2602 // InitListExprs. Other forms of copy-initialization will be a no-op if
2603 // the initializer is already the right type.
2604 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2605 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2606 return getDerived().TransformExpr(Init);
2607
2608 // Revert value-initialization back to empty parens.
2609 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2610 SourceRange Parens = VIE->getSourceRange();
2611 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2612 Parens.getEnd());
2613 }
2614
2615 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2616 if (isa<ImplicitValueInitExpr>(Init))
2617 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2618 SourceLocation());
2619
2620 // Revert initialization by constructor back to a parenthesized or braced list
2621 // of expressions. Any other form of initializer can just be reused directly.
2622 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002623 return getDerived().TransformExpr(Init);
2624
2625 SmallVector<Expr*, 8> NewArgs;
2626 bool ArgChanged = false;
2627 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2628 /*IsCall*/true, NewArgs, &ArgChanged))
2629 return ExprError();
2630
2631 // If this was list initialization, revert to list form.
2632 if (Construct->isListInitialization())
2633 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2634 Construct->getLocEnd(),
2635 Construct->getType());
2636
Richard Smithc83c2302012-12-19 01:39:02 +00002637 // Build a ParenListExpr to represent anything else.
2638 SourceRange Parens = Construct->getParenRange();
2639 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2640 Parens.getEnd());
2641}
2642
2643template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002644bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2645 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002646 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002647 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002648 bool *ArgChanged) {
2649 for (unsigned I = 0; I != NumInputs; ++I) {
2650 // If requested, drop call arguments that need to be dropped.
2651 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2652 if (ArgChanged)
2653 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002654
Douglas Gregoraa165f82011-01-03 19:04:46 +00002655 break;
2656 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002657
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002658 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2659 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002660
Chris Lattner686775d2011-07-20 06:58:45 +00002661 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002662 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2663 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002664
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002665 // Determine whether the set of unexpanded parameter packs can and should
2666 // be expanded.
2667 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002668 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002669 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2670 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002671 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2672 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002673 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002674 Expand, RetainExpansion,
2675 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002676 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002677
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002678 if (!Expand) {
2679 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002680 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002681 // expansion.
2682 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2683 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2684 if (OutPattern.isInvalid())
2685 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002686
2687 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002688 Expansion->getEllipsisLoc(),
2689 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002690 if (Out.isInvalid())
2691 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002692
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002693 if (ArgChanged)
2694 *ArgChanged = true;
2695 Outputs.push_back(Out.get());
2696 continue;
2697 }
John McCallc8fc90a2011-07-06 07:30:07 +00002698
2699 // Record right away that the argument was changed. This needs
2700 // to happen even if the array expands to nothing.
2701 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002702
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002703 // The transform has determined that we should perform an elementwise
2704 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002705 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002706 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2707 ExprResult Out = getDerived().TransformExpr(Pattern);
2708 if (Out.isInvalid())
2709 return true;
2710
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002711 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002712 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2713 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002714 if (Out.isInvalid())
2715 return true;
2716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002717
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002718 Outputs.push_back(Out.get());
2719 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002720
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002721 continue;
2722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002723
Richard Smithc83c2302012-12-19 01:39:02 +00002724 ExprResult Result =
2725 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2726 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002727 if (Result.isInvalid())
2728 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002729
Douglas Gregoraa165f82011-01-03 19:04:46 +00002730 if (Result.get() != Inputs[I] && ArgChanged)
2731 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002732
2733 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002734 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002735
Douglas Gregoraa165f82011-01-03 19:04:46 +00002736 return false;
2737}
2738
2739template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002740NestedNameSpecifierLoc
2741TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2742 NestedNameSpecifierLoc NNS,
2743 QualType ObjectType,
2744 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002745 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002746 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002747 Qualifier = Qualifier.getPrefix())
2748 Qualifiers.push_back(Qualifier);
2749
2750 CXXScopeSpec SS;
2751 while (!Qualifiers.empty()) {
2752 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2753 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002754
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002755 switch (QNNS->getKind()) {
2756 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002759 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002760 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002761 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002762 FirstQualifierInScope, false))
2763 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002765 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002766
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002767 case NestedNameSpecifier::Namespace: {
2768 NamespaceDecl *NS
2769 = cast_or_null<NamespaceDecl>(
2770 getDerived().TransformDecl(
2771 Q.getLocalBeginLoc(),
2772 QNNS->getAsNamespace()));
2773 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2774 break;
2775 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002776
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002777 case NestedNameSpecifier::NamespaceAlias: {
2778 NamespaceAliasDecl *Alias
2779 = cast_or_null<NamespaceAliasDecl>(
2780 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2781 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002782 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002783 Q.getLocalEndLoc());
2784 break;
2785 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002786
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002787 case NestedNameSpecifier::Global:
2788 // There is no meaningful transformation that one could perform on the
2789 // global scope.
2790 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2791 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002792
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002793 case NestedNameSpecifier::TypeSpecWithTemplate:
2794 case NestedNameSpecifier::TypeSpec: {
2795 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2796 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002797
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002798 if (!TL)
2799 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002800
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002801 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002802 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002803 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002804 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002805 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002806 if (TL.getType()->isEnumeralType())
2807 SemaRef.Diag(TL.getBeginLoc(),
2808 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002809 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2810 Q.getLocalEndLoc());
2811 break;
2812 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002813 // If the nested-name-specifier is an invalid type def, don't emit an
2814 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002815 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2816 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002817 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002818 << TL.getType() << SS.getRange();
2819 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002820 return NestedNameSpecifierLoc();
2821 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002822 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002823
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002824 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002825 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002826 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002827 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002828
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002829 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002830 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002831 !getDerived().AlwaysRebuild())
2832 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833
2834 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002835 // nested-name-specifier, do so.
2836 if (SS.location_size() == NNS.getDataLength() &&
2837 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2838 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2839
2840 // Allocate new nested-name-specifier location information.
2841 return SS.getWithLocInContext(SemaRef.Context);
2842}
2843
2844template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002845DeclarationNameInfo
2846TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002847::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002848 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002849 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002850 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002851
2852 switch (Name.getNameKind()) {
2853 case DeclarationName::Identifier:
2854 case DeclarationName::ObjCZeroArgSelector:
2855 case DeclarationName::ObjCOneArgSelector:
2856 case DeclarationName::ObjCMultiArgSelector:
2857 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002858 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002859 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002860 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002861
Douglas Gregor81499bb2009-09-03 22:13:48 +00002862 case DeclarationName::CXXConstructorName:
2863 case DeclarationName::CXXDestructorName:
2864 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002865 TypeSourceInfo *NewTInfo;
2866 CanQualType NewCanTy;
2867 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002868 NewTInfo = getDerived().TransformType(OldTInfo);
2869 if (!NewTInfo)
2870 return DeclarationNameInfo();
2871 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002872 }
2873 else {
2874 NewTInfo = 0;
2875 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002876 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002877 if (NewT.isNull())
2878 return DeclarationNameInfo();
2879 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2880 }
Mike Stump1eb44332009-09-09 15:08:12 +00002881
Abramo Bagnara25777432010-08-11 22:01:17 +00002882 DeclarationName NewName
2883 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2884 NewCanTy);
2885 DeclarationNameInfo NewNameInfo(NameInfo);
2886 NewNameInfo.setName(NewName);
2887 NewNameInfo.setNamedTypeInfo(NewTInfo);
2888 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002889 }
Mike Stump1eb44332009-09-09 15:08:12 +00002890 }
2891
David Blaikieb219cfc2011-09-23 05:06:16 +00002892 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002893}
2894
2895template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002896TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002897TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2898 TemplateName Name,
2899 SourceLocation NameLoc,
2900 QualType ObjectType,
2901 NamedDecl *FirstQualifierInScope) {
2902 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2903 TemplateDecl *Template = QTN->getTemplateDecl();
2904 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002905
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002906 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002908 Template));
2909 if (!TransTemplate)
2910 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002911
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002912 if (!getDerived().AlwaysRebuild() &&
2913 SS.getScopeRep() == QTN->getQualifier() &&
2914 TransTemplate == Template)
2915 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002916
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002917 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2918 TransTemplate);
2919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002920
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002921 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2922 if (SS.getScopeRep()) {
2923 // These apply to the scope specifier, not the template.
2924 ObjectType = QualType();
2925 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002926 }
2927
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002928 if (!getDerived().AlwaysRebuild() &&
2929 SS.getScopeRep() == DTN->getQualifier() &&
2930 ObjectType.isNull())
2931 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002932
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002933 if (DTN->isIdentifier()) {
2934 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002936 NameLoc,
2937 ObjectType,
2938 FirstQualifierInScope);
2939 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002940
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002941 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2942 ObjectType);
2943 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002945 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2946 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002948 Template));
2949 if (!TransTemplate)
2950 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002951
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002952 if (!getDerived().AlwaysRebuild() &&
2953 TransTemplate == Template)
2954 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002955
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002956 return TemplateName(TransTemplate);
2957 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002959 if (SubstTemplateTemplateParmPackStorage *SubstPack
2960 = Name.getAsSubstTemplateTemplateParmPack()) {
2961 TemplateTemplateParmDecl *TransParam
2962 = cast_or_null<TemplateTemplateParmDecl>(
2963 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2964 if (!TransParam)
2965 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002966
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002967 if (!getDerived().AlwaysRebuild() &&
2968 TransParam == SubstPack->getParameterPack())
2969 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002970
2971 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002972 SubstPack->getArgumentPack());
2973 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002974
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002975 // These should be getting filtered out before they reach the AST.
2976 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002977}
2978
2979template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002980void TreeTransform<Derived>::InventTemplateArgumentLoc(
2981 const TemplateArgument &Arg,
2982 TemplateArgumentLoc &Output) {
2983 SourceLocation Loc = getDerived().getBaseLocation();
2984 switch (Arg.getKind()) {
2985 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002986 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002987 break;
2988
2989 case TemplateArgument::Type:
2990 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002991 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002992
John McCall833ca992009-10-29 08:12:44 +00002993 break;
2994
Douglas Gregor788cd062009-11-11 01:00:40 +00002995 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002996 case TemplateArgument::TemplateExpansion: {
2997 NestedNameSpecifierLocBuilder Builder;
2998 TemplateName Template = Arg.getAsTemplate();
2999 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3000 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3001 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3002 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003003
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003004 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003005 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003006 Builder.getWithLocInContext(SemaRef.Context),
3007 Loc);
3008 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003009 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003010 Builder.getWithLocInContext(SemaRef.Context),
3011 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003012
Douglas Gregor788cd062009-11-11 01:00:40 +00003013 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003014 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003015
John McCall833ca992009-10-29 08:12:44 +00003016 case TemplateArgument::Expression:
3017 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3018 break;
3019
3020 case TemplateArgument::Declaration:
3021 case TemplateArgument::Integral:
3022 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003023 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003024 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003025 break;
3026 }
3027}
3028
3029template<typename Derived>
3030bool TreeTransform<Derived>::TransformTemplateArgument(
3031 const TemplateArgumentLoc &Input,
3032 TemplateArgumentLoc &Output) {
3033 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003034 switch (Arg.getKind()) {
3035 case TemplateArgument::Null:
3036 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003037 case TemplateArgument::Pack:
3038 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003039 case TemplateArgument::NullPtr:
3040 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003041
Douglas Gregor670444e2009-08-04 22:27:00 +00003042 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003043 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003044 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003045 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003046
3047 DI = getDerived().TransformType(DI);
3048 if (!DI) return true;
3049
3050 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3051 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003052 }
Mike Stump1eb44332009-09-09 15:08:12 +00003053
Douglas Gregor788cd062009-11-11 01:00:40 +00003054 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003055 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3056 if (QualifierLoc) {
3057 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3058 if (!QualifierLoc)
3059 return true;
3060 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003061
Douglas Gregor1d752d72011-03-02 18:46:51 +00003062 CXXScopeSpec SS;
3063 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003064 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003065 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3066 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003067 if (Template.isNull())
3068 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003069
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003070 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003071 Input.getTemplateNameLoc());
3072 return false;
3073 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003074
3075 case TemplateArgument::TemplateExpansion:
3076 llvm_unreachable("Caller should expand pack expansions");
3077
Douglas Gregor670444e2009-08-04 22:27:00 +00003078 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003079 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003080 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003081 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003082
John McCall833ca992009-10-29 08:12:44 +00003083 Expr *InputExpr = Input.getSourceExpression();
3084 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3085
Chris Lattner223de242011-04-25 20:37:58 +00003086 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003087 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003088 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003089 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003090 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003091 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003092 }
Mike Stump1eb44332009-09-09 15:08:12 +00003093
Douglas Gregor670444e2009-08-04 22:27:00 +00003094 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003095 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003096}
3097
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003098/// \brief Iterator adaptor that invents template argument location information
3099/// for each of the template arguments in its underlying iterator.
3100template<typename Derived, typename InputIterator>
3101class TemplateArgumentLocInventIterator {
3102 TreeTransform<Derived> &Self;
3103 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003104
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003105public:
3106 typedef TemplateArgumentLoc value_type;
3107 typedef TemplateArgumentLoc reference;
3108 typedef typename std::iterator_traits<InputIterator>::difference_type
3109 difference_type;
3110 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003112 class pointer {
3113 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003114
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003115 public:
3116 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003118 const TemplateArgumentLoc *operator->() const { return &Arg; }
3119 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003121 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003122
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003123 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3124 InputIterator Iter)
3125 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127 TemplateArgumentLocInventIterator &operator++() {
3128 ++Iter;
3129 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003130 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003131
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003132 TemplateArgumentLocInventIterator operator++(int) {
3133 TemplateArgumentLocInventIterator Old(*this);
3134 ++(*this);
3135 return Old;
3136 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003137
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003138 reference operator*() const {
3139 TemplateArgumentLoc Result;
3140 Self.InventTemplateArgumentLoc(*Iter, Result);
3141 return Result;
3142 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003143
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003144 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003146 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3147 const TemplateArgumentLocInventIterator &Y) {
3148 return X.Iter == Y.Iter;
3149 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003150
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3152 const TemplateArgumentLocInventIterator &Y) {
3153 return X.Iter != Y.Iter;
3154 }
3155};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003156
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003157template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003158template<typename InputIterator>
3159bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3160 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003161 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003163 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003164 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003165
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003166 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3167 // Unpack argument packs, which we translate them into separate
3168 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003169 // FIXME: We could do much better if we could guarantee that the
3170 // TemplateArgumentLocInfo for the pack expansion would be usable for
3171 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003172 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003173 TemplateArgument::pack_iterator>
3174 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003176 In.getArgument().pack_begin()),
3177 PackLocIterator(*this,
3178 In.getArgument().pack_end()),
3179 Outputs))
3180 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003181
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003182 continue;
3183 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003185 if (In.getArgument().isPackExpansion()) {
3186 // We have a pack expansion, for which we will be substituting into
3187 // the pattern.
3188 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003189 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003190 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003191 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003192 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003193
Chris Lattner686775d2011-07-20 06:58:45 +00003194 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003195 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3196 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003197
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003198 // Determine whether the set of unexpanded parameter packs can and should
3199 // be expanded.
3200 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003201 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003202 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 if (getDerived().TryExpandParameterPacks(Ellipsis,
3204 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003205 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003206 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003207 RetainExpansion,
3208 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003209 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003210
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 if (!Expand) {
3212 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 // expansion.
3215 TemplateArgumentLoc OutPattern;
3216 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3217 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3218 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003219
Douglas Gregorcded4f62011-01-14 17:04:44 +00003220 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3221 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003222 if (Out.getArgument().isNull())
3223 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003224
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003225 Outputs.addArgument(Out);
3226 continue;
3227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003228
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003229 // The transform has determined that we should perform an elementwise
3230 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003231 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003232 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3233
3234 if (getDerived().TransformTemplateArgument(Pattern, Out))
3235 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003236
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003237 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003238 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3239 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003240 if (Out.getArgument().isNull())
3241 return true;
3242 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003244 Outputs.addArgument(Out);
3245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003246
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003247 // If we're supposed to retain a pack expansion, do so by temporarily
3248 // forgetting the partially-substituted parameter pack.
3249 if (RetainExpansion) {
3250 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003252 if (getDerived().TransformTemplateArgument(Pattern, Out))
3253 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregorcded4f62011-01-14 17:04:44 +00003255 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3256 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003257 if (Out.getArgument().isNull())
3258 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003259
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003260 Outputs.addArgument(Out);
3261 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003263 continue;
3264 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
3266 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003267 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003268 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003269
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003270 Outputs.addArgument(Out);
3271 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003273 return false;
3274
3275}
3276
Douglas Gregor577f75a2009-08-04 16:50:30 +00003277//===----------------------------------------------------------------------===//
3278// Type transformation
3279//===----------------------------------------------------------------------===//
3280
3281template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003282QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003283 if (getDerived().AlreadyTransformed(T))
3284 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003285
John McCalla2becad2009-10-21 00:40:46 +00003286 // Temporary workaround. All of these transformations should
3287 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003288 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3289 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003290
John McCall43fed0d2010-11-12 08:19:04 +00003291 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003292
John McCalla2becad2009-10-21 00:40:46 +00003293 if (!NewDI)
3294 return QualType();
3295
3296 return NewDI->getType();
3297}
3298
3299template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003300TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003301 // Refine the base location to the type's location.
3302 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3303 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003304 if (getDerived().AlreadyTransformed(DI->getType()))
3305 return DI;
3306
3307 TypeLocBuilder TLB;
3308
3309 TypeLoc TL = DI->getTypeLoc();
3310 TLB.reserve(TL.getFullDataSize());
3311
John McCall43fed0d2010-11-12 08:19:04 +00003312 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003313 if (Result.isNull())
3314 return 0;
3315
John McCalla93c9342009-12-07 02:54:59 +00003316 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003317}
3318
3319template<typename Derived>
3320QualType
John McCall43fed0d2010-11-12 08:19:04 +00003321TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003322 switch (T.getTypeLocClass()) {
3323#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003324#define TYPELOC(CLASS, PARENT) \
3325 case TypeLoc::CLASS: \
3326 return getDerived().Transform##CLASS##Type(TLB, \
3327 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003328#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003329 }
Mike Stump1eb44332009-09-09 15:08:12 +00003330
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003331 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003332}
3333
3334/// FIXME: By default, this routine adds type qualifiers only to types
3335/// that can have qualifiers, and silently suppresses those qualifiers
3336/// that are not permitted (e.g., qualifiers on reference or function
3337/// types). This is the right thing for template instantiation, but
3338/// probably not for other clients.
3339template<typename Derived>
3340QualType
3341TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003342 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003343 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003344
John McCall43fed0d2010-11-12 08:19:04 +00003345 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003346 if (Result.isNull())
3347 return QualType();
3348
3349 // Silently suppress qualifiers if the result type can't be qualified.
3350 // FIXME: this is the right thing for template instantiation, but
3351 // probably not for other clients.
3352 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003353 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003354
John McCallf85e1932011-06-15 23:02:42 +00003355 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003356 // resulting type.
3357 if (Quals.hasObjCLifetime()) {
3358 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3359 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003360 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003362 // A lifetime qualifier applied to a substituted template parameter
3363 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003364 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003365 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003366 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3367 QualType Replacement = SubstTypeParam->getReplacementType();
3368 Qualifiers Qs = Replacement.getQualifiers();
3369 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003371 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3372 Qs);
3373 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003374 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003375 Replacement);
3376 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003377 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3378 // 'auto' types behave the same way as template parameters.
3379 QualType Deduced = AutoTy->getDeducedType();
3380 Qualifiers Qs = Deduced.getQualifiers();
3381 Qs.removeObjCLifetime();
3382 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3383 Qs);
3384 Result = SemaRef.Context.getAutoType(Deduced);
3385 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003386 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003387 // Otherwise, complain about the addition of a qualifier to an
3388 // already-qualified type.
3389 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003390 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003391 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003392
Douglas Gregore559ca12011-06-17 22:11:49 +00003393 Quals.removeObjCLifetime();
3394 }
3395 }
3396 }
John McCall28654742010-06-05 06:41:15 +00003397 if (!Quals.empty()) {
3398 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3399 TLB.push<QualifiedTypeLoc>(Result);
3400 // No location information to preserve.
3401 }
John McCalla2becad2009-10-21 00:40:46 +00003402
3403 return Result;
3404}
3405
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003406template<typename Derived>
3407TypeLoc
3408TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3409 QualType ObjectType,
3410 NamedDecl *UnqualLookup,
3411 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003412 QualType T = TL.getType();
3413 if (getDerived().AlreadyTransformed(T))
3414 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003415
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003416 TypeLocBuilder TLB;
3417 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003419 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003420 TemplateSpecializationTypeLoc SpecTL =
3421 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003423 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003424 getDerived().TransformTemplateName(SS,
3425 SpecTL.getTypePtr()->getTemplateName(),
3426 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003427 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003428 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003429 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003430
3431 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003432 Template);
3433 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003434 DependentTemplateSpecializationTypeLoc SpecTL =
3435 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003436
Douglas Gregora88f09f2011-02-28 17:23:35 +00003437 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003438 = getDerived().RebuildTemplateName(SS,
3439 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003440 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003441 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003442 if (Template.isNull())
3443 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003444
3445 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003446 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003447 Template,
3448 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003449 } else {
3450 // Nothing special needs to be done for these.
3451 Result = getDerived().TransformType(TLB, TL);
3452 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003453
3454 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003455 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003457 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3458}
3459
Douglas Gregorb71d8212011-03-02 18:32:08 +00003460template<typename Derived>
3461TypeSourceInfo *
3462TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3463 QualType ObjectType,
3464 NamedDecl *UnqualLookup,
3465 CXXScopeSpec &SS) {
3466 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003467
Douglas Gregorb71d8212011-03-02 18:32:08 +00003468 QualType T = TSInfo->getType();
3469 if (getDerived().AlreadyTransformed(T))
3470 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003471
Douglas Gregorb71d8212011-03-02 18:32:08 +00003472 TypeLocBuilder TLB;
3473 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003474
Douglas Gregorb71d8212011-03-02 18:32:08 +00003475 TypeLoc TL = TSInfo->getTypeLoc();
3476 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003477 TemplateSpecializationTypeLoc SpecTL =
3478 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003479
Douglas Gregorb71d8212011-03-02 18:32:08 +00003480 TemplateName Template
3481 = getDerived().TransformTemplateName(SS,
3482 SpecTL.getTypePtr()->getTemplateName(),
3483 SpecTL.getTemplateNameLoc(),
3484 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003485 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003486 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003487
3488 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003489 Template);
3490 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003491 DependentTemplateSpecializationTypeLoc SpecTL =
3492 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003493
Douglas Gregorb71d8212011-03-02 18:32:08 +00003494 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003495 = getDerived().RebuildTemplateName(SS,
3496 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003497 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003498 ObjectType, UnqualLookup);
3499 if (Template.isNull())
3500 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003501
3502 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003503 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003504 Template,
3505 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506 } else {
3507 // Nothing special needs to be done for these.
3508 Result = getDerived().TransformType(TLB, TL);
3509 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003510
3511 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003512 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513
Douglas Gregorb71d8212011-03-02 18:32:08 +00003514 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3515}
3516
John McCalla2becad2009-10-21 00:40:46 +00003517template <class TyLoc> static inline
3518QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3519 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3520 NewT.setNameLoc(T.getNameLoc());
3521 return T.getType();
3522}
3523
John McCalla2becad2009-10-21 00:40:46 +00003524template<typename Derived>
3525QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003526 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003527 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3528 NewT.setBuiltinLoc(T.getBuiltinLoc());
3529 if (T.needsExtraLocalData())
3530 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3531 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003532}
Mike Stump1eb44332009-09-09 15:08:12 +00003533
Douglas Gregor577f75a2009-08-04 16:50:30 +00003534template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003535QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003536 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003537 // FIXME: recurse?
3538 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003539}
Mike Stump1eb44332009-09-09 15:08:12 +00003540
Douglas Gregor577f75a2009-08-04 16:50:30 +00003541template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003542QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003543 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003544 QualType PointeeType
3545 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003546 if (PointeeType.isNull())
3547 return QualType();
3548
3549 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003550 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003551 // A dependent pointer type 'T *' has is being transformed such
3552 // that an Objective-C class type is being replaced for 'T'. The
3553 // resulting pointer type is an ObjCObjectPointerType, not a
3554 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003555 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003556
John McCallc12c5bb2010-05-15 11:32:37 +00003557 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3558 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003559 return Result;
3560 }
John McCall43fed0d2010-11-12 08:19:04 +00003561
Douglas Gregor92e986e2010-04-22 16:44:27 +00003562 if (getDerived().AlwaysRebuild() ||
3563 PointeeType != TL.getPointeeLoc().getType()) {
3564 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3565 if (Result.isNull())
3566 return QualType();
3567 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003568
John McCallf85e1932011-06-15 23:02:42 +00003569 // Objective-C ARC can add lifetime qualifiers to the type that we're
3570 // pointing to.
3571 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003572
Douglas Gregor92e986e2010-04-22 16:44:27 +00003573 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3574 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003576}
Mike Stump1eb44332009-09-09 15:08:12 +00003577
3578template<typename Derived>
3579QualType
John McCalla2becad2009-10-21 00:40:46 +00003580TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003581 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003582 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003583 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3584 if (PointeeType.isNull())
3585 return QualType();
3586
3587 QualType Result = TL.getType();
3588 if (getDerived().AlwaysRebuild() ||
3589 PointeeType != TL.getPointeeLoc().getType()) {
3590 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003591 TL.getSigilLoc());
3592 if (Result.isNull())
3593 return QualType();
3594 }
3595
Douglas Gregor39968ad2010-04-22 16:50:51 +00003596 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003597 NewT.setSigilLoc(TL.getSigilLoc());
3598 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003599}
3600
John McCall85737a72009-10-30 00:06:24 +00003601/// Transforms a reference type. Note that somewhat paradoxically we
3602/// don't care whether the type itself is an l-value type or an r-value
3603/// type; we only care if the type was *written* as an l-value type
3604/// or an r-value type.
3605template<typename Derived>
3606QualType
3607TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003608 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003609 const ReferenceType *T = TL.getTypePtr();
3610
3611 // Note that this works with the pointee-as-written.
3612 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3613 if (PointeeType.isNull())
3614 return QualType();
3615
3616 QualType Result = TL.getType();
3617 if (getDerived().AlwaysRebuild() ||
3618 PointeeType != T->getPointeeTypeAsWritten()) {
3619 Result = getDerived().RebuildReferenceType(PointeeType,
3620 T->isSpelledAsLValue(),
3621 TL.getSigilLoc());
3622 if (Result.isNull())
3623 return QualType();
3624 }
3625
John McCallf85e1932011-06-15 23:02:42 +00003626 // Objective-C ARC can add lifetime qualifiers to the type that we're
3627 // referring to.
3628 TLB.TypeWasModifiedSafely(
3629 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3630
John McCall85737a72009-10-30 00:06:24 +00003631 // r-value references can be rebuilt as l-value references.
3632 ReferenceTypeLoc NewTL;
3633 if (isa<LValueReferenceType>(Result))
3634 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3635 else
3636 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3637 NewTL.setSigilLoc(TL.getSigilLoc());
3638
3639 return Result;
3640}
3641
Mike Stump1eb44332009-09-09 15:08:12 +00003642template<typename Derived>
3643QualType
John McCalla2becad2009-10-21 00:40:46 +00003644TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003645 LValueReferenceTypeLoc TL) {
3646 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003647}
3648
Mike Stump1eb44332009-09-09 15:08:12 +00003649template<typename Derived>
3650QualType
John McCalla2becad2009-10-21 00:40:46 +00003651TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003652 RValueReferenceTypeLoc TL) {
3653 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003654}
Mike Stump1eb44332009-09-09 15:08:12 +00003655
Douglas Gregor577f75a2009-08-04 16:50:30 +00003656template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003657QualType
John McCalla2becad2009-10-21 00:40:46 +00003658TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003659 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003660 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003661 if (PointeeType.isNull())
3662 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003663
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003664 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3665 TypeSourceInfo* NewClsTInfo = 0;
3666 if (OldClsTInfo) {
3667 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3668 if (!NewClsTInfo)
3669 return QualType();
3670 }
3671
3672 const MemberPointerType *T = TL.getTypePtr();
3673 QualType OldClsType = QualType(T->getClass(), 0);
3674 QualType NewClsType;
3675 if (NewClsTInfo)
3676 NewClsType = NewClsTInfo->getType();
3677 else {
3678 NewClsType = getDerived().TransformType(OldClsType);
3679 if (NewClsType.isNull())
3680 return QualType();
3681 }
Mike Stump1eb44332009-09-09 15:08:12 +00003682
John McCalla2becad2009-10-21 00:40:46 +00003683 QualType Result = TL.getType();
3684 if (getDerived().AlwaysRebuild() ||
3685 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003686 NewClsType != OldClsType) {
3687 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003688 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003689 if (Result.isNull())
3690 return QualType();
3691 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003692
John McCalla2becad2009-10-21 00:40:46 +00003693 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3694 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003695 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003696
3697 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003698}
3699
Mike Stump1eb44332009-09-09 15:08:12 +00003700template<typename Derived>
3701QualType
John McCalla2becad2009-10-21 00:40:46 +00003702TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003703 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003704 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003705 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003706 if (ElementType.isNull())
3707 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003708
John McCalla2becad2009-10-21 00:40:46 +00003709 QualType Result = TL.getType();
3710 if (getDerived().AlwaysRebuild() ||
3711 ElementType != T->getElementType()) {
3712 Result = getDerived().RebuildConstantArrayType(ElementType,
3713 T->getSizeModifier(),
3714 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003715 T->getIndexTypeCVRQualifiers(),
3716 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003717 if (Result.isNull())
3718 return QualType();
3719 }
Eli Friedman457a3772012-01-25 22:19:07 +00003720
3721 // We might have either a ConstantArrayType or a VariableArrayType now:
3722 // a ConstantArrayType is allowed to have an element type which is a
3723 // VariableArrayType if the type is dependent. Fortunately, all array
3724 // types have the same location layout.
3725 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003726 NewTL.setLBracketLoc(TL.getLBracketLoc());
3727 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003728
John McCalla2becad2009-10-21 00:40:46 +00003729 Expr *Size = TL.getSizeExpr();
3730 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003731 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3732 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003733 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003734 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003735 }
3736 NewTL.setSizeExpr(Size);
3737
3738 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003739}
Mike Stump1eb44332009-09-09 15:08:12 +00003740
Douglas Gregor577f75a2009-08-04 16:50:30 +00003741template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003743 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003744 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003745 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003746 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003747 if (ElementType.isNull())
3748 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003749
John McCalla2becad2009-10-21 00:40:46 +00003750 QualType Result = TL.getType();
3751 if (getDerived().AlwaysRebuild() ||
3752 ElementType != T->getElementType()) {
3753 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003754 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003755 T->getIndexTypeCVRQualifiers(),
3756 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003757 if (Result.isNull())
3758 return QualType();
3759 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003760
John McCalla2becad2009-10-21 00:40:46 +00003761 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3762 NewTL.setLBracketLoc(TL.getLBracketLoc());
3763 NewTL.setRBracketLoc(TL.getRBracketLoc());
3764 NewTL.setSizeExpr(0);
3765
3766 return Result;
3767}
3768
3769template<typename Derived>
3770QualType
3771TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003772 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003773 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003774 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3775 if (ElementType.isNull())
3776 return QualType();
3777
John McCall60d7b3a2010-08-24 06:29:42 +00003778 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003779 = getDerived().TransformExpr(T->getSizeExpr());
3780 if (SizeResult.isInvalid())
3781 return QualType();
3782
John McCall9ae2f072010-08-23 23:25:46 +00003783 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003784
3785 QualType Result = TL.getType();
3786 if (getDerived().AlwaysRebuild() ||
3787 ElementType != T->getElementType() ||
3788 Size != T->getSizeExpr()) {
3789 Result = getDerived().RebuildVariableArrayType(ElementType,
3790 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003791 Size,
John McCalla2becad2009-10-21 00:40:46 +00003792 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003793 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003794 if (Result.isNull())
3795 return QualType();
3796 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003797
John McCalla2becad2009-10-21 00:40:46 +00003798 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3799 NewTL.setLBracketLoc(TL.getLBracketLoc());
3800 NewTL.setRBracketLoc(TL.getRBracketLoc());
3801 NewTL.setSizeExpr(Size);
3802
3803 return Result;
3804}
3805
3806template<typename Derived>
3807QualType
3808TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003809 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003810 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003811 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3812 if (ElementType.isNull())
3813 return QualType();
3814
Richard Smithf6702a32011-12-20 02:08:33 +00003815 // Array bounds are constant expressions.
3816 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3817 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003818
John McCall3b657512011-01-19 10:06:00 +00003819 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3820 Expr *origSize = TL.getSizeExpr();
3821 if (!origSize) origSize = T->getSizeExpr();
3822
3823 ExprResult sizeResult
3824 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003825 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003826 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003827 return QualType();
3828
John McCall3b657512011-01-19 10:06:00 +00003829 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003830
3831 QualType Result = TL.getType();
3832 if (getDerived().AlwaysRebuild() ||
3833 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003834 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003835 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3836 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003837 size,
John McCalla2becad2009-10-21 00:40:46 +00003838 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003839 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003840 if (Result.isNull())
3841 return QualType();
3842 }
John McCalla2becad2009-10-21 00:40:46 +00003843
3844 // We might have any sort of array type now, but fortunately they
3845 // all have the same location layout.
3846 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3847 NewTL.setLBracketLoc(TL.getLBracketLoc());
3848 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003849 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003850
3851 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003852}
Mike Stump1eb44332009-09-09 15:08:12 +00003853
3854template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003855QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003856 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003857 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003858 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003859
3860 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003861 QualType ElementType = getDerived().TransformType(T->getElementType());
3862 if (ElementType.isNull())
3863 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003864
Richard Smithf6702a32011-12-20 02:08:33 +00003865 // Vector sizes are constant expressions.
3866 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3867 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003868
John McCall60d7b3a2010-08-24 06:29:42 +00003869 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003870 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003871 if (Size.isInvalid())
3872 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003873
John McCalla2becad2009-10-21 00:40:46 +00003874 QualType Result = TL.getType();
3875 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003876 ElementType != T->getElementType() ||
3877 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003878 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003879 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003880 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003881 if (Result.isNull())
3882 return QualType();
3883 }
John McCalla2becad2009-10-21 00:40:46 +00003884
3885 // Result might be dependent or not.
3886 if (isa<DependentSizedExtVectorType>(Result)) {
3887 DependentSizedExtVectorTypeLoc NewTL
3888 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3889 NewTL.setNameLoc(TL.getNameLoc());
3890 } else {
3891 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3892 NewTL.setNameLoc(TL.getNameLoc());
3893 }
3894
3895 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003896}
Mike Stump1eb44332009-09-09 15:08:12 +00003897
3898template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003899QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003900 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003901 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003902 QualType ElementType = getDerived().TransformType(T->getElementType());
3903 if (ElementType.isNull())
3904 return QualType();
3905
John McCalla2becad2009-10-21 00:40:46 +00003906 QualType Result = TL.getType();
3907 if (getDerived().AlwaysRebuild() ||
3908 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003909 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003910 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003911 if (Result.isNull())
3912 return QualType();
3913 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003914
John McCalla2becad2009-10-21 00:40:46 +00003915 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3916 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003917
John McCalla2becad2009-10-21 00:40:46 +00003918 return Result;
3919}
3920
3921template<typename Derived>
3922QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003923 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003924 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003925 QualType ElementType = getDerived().TransformType(T->getElementType());
3926 if (ElementType.isNull())
3927 return QualType();
3928
3929 QualType Result = TL.getType();
3930 if (getDerived().AlwaysRebuild() ||
3931 ElementType != T->getElementType()) {
3932 Result = getDerived().RebuildExtVectorType(ElementType,
3933 T->getNumElements(),
3934 /*FIXME*/ SourceLocation());
3935 if (Result.isNull())
3936 return QualType();
3937 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003938
John McCalla2becad2009-10-21 00:40:46 +00003939 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3940 NewTL.setNameLoc(TL.getNameLoc());
3941
3942 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003943}
Mike Stump1eb44332009-09-09 15:08:12 +00003944
David Blaikiedc84cd52013-02-20 22:23:23 +00003945template <typename Derived>
3946ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3947 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3948 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003949 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003950 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003951
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003952 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003953 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003954 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003955 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003956 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003957
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003958 TypeLocBuilder TLB;
3959 TypeLoc NewTL = OldDI->getTypeLoc();
3960 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003961
3962 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003963 OldExpansionTL.getPatternLoc());
3964 if (Result.isNull())
3965 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003966
3967 Result = RebuildPackExpansionType(Result,
3968 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003969 OldExpansionTL.getEllipsisLoc(),
3970 NumExpansions);
3971 if (Result.isNull())
3972 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003973
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003974 PackExpansionTypeLoc NewExpansionTL
3975 = TLB.push<PackExpansionTypeLoc>(Result);
3976 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3977 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3978 } else
3979 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003980 if (!NewDI)
3981 return 0;
3982
John McCallfb44de92011-05-01 22:35:37 +00003983 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003984 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003985
3986 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3987 OldParm->getDeclContext(),
3988 OldParm->getInnerLocStart(),
3989 OldParm->getLocation(),
3990 OldParm->getIdentifier(),
3991 NewDI->getType(),
3992 NewDI,
3993 OldParm->getStorageClass(),
3994 OldParm->getStorageClassAsWritten(),
3995 /* DefArg */ NULL);
3996 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3997 OldParm->getFunctionScopeIndex() + indexAdjustment);
3998 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003999}
4000
4001template<typename Derived>
4002bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004003 TransformFunctionTypeParams(SourceLocation Loc,
4004 ParmVarDecl **Params, unsigned NumParams,
4005 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004006 SmallVectorImpl<QualType> &OutParamTypes,
4007 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004008 int indexAdjustment = 0;
4009
Douglas Gregora009b592011-01-07 00:20:55 +00004010 for (unsigned i = 0; i != NumParams; ++i) {
4011 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004012 assert(OldParm->getFunctionScopeIndex() == i);
4013
David Blaikiedc84cd52013-02-20 22:23:23 +00004014 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004015 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004016 if (OldParm->isParameterPack()) {
4017 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004018 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004019
Douglas Gregor603cfb42011-01-05 23:12:31 +00004020 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004021 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004022 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004023 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4024 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004025 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4026
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 // Determine whether we should expand the parameter packs.
4028 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004029 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004030 Optional<unsigned> OrigNumExpansions =
4031 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004032 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004033 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4034 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004035 Unexpanded,
4036 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004037 RetainExpansion,
4038 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 return true;
4040 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004041
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042 if (ShouldExpand) {
4043 // Expand the function parameter pack into multiple, separate
4044 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004045 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004046 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004047 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004048 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004049 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004050 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004051 OrigNumExpansions,
4052 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053 if (!NewParm)
4054 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004055
Douglas Gregora009b592011-01-07 00:20:55 +00004056 OutParamTypes.push_back(NewParm->getType());
4057 if (PVars)
4058 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004059 }
Douglas Gregord3731192011-01-10 07:32:04 +00004060
4061 // If we're supposed to retain a pack expansion, do so by temporarily
4062 // forgetting the partially-substituted parameter pack.
4063 if (RetainExpansion) {
4064 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004065 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004066 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004067 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004068 OrigNumExpansions,
4069 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004070 if (!NewParm)
4071 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004072
Douglas Gregord3731192011-01-10 07:32:04 +00004073 OutParamTypes.push_back(NewParm->getType());
4074 if (PVars)
4075 PVars->push_back(NewParm);
4076 }
4077
John McCallfb44de92011-05-01 22:35:37 +00004078 // The next parameter should have the same adjustment as the
4079 // last thing we pushed, but we post-incremented indexAdjustment
4080 // on every push. Also, if we push nothing, the adjustment should
4081 // go down by one.
4082 indexAdjustment--;
4083
Douglas Gregor603cfb42011-01-05 23:12:31 +00004084 // We're done with the pack expansion.
4085 continue;
4086 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004087
4088 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004089 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004090 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4091 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004092 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004093 NumExpansions,
4094 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004095 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004096 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004097 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004099
John McCall21ef0fa2010-03-11 09:03:00 +00004100 if (!NewParm)
4101 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004102
Douglas Gregora009b592011-01-07 00:20:55 +00004103 OutParamTypes.push_back(NewParm->getType());
4104 if (PVars)
4105 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004106 continue;
4107 }
John McCall21ef0fa2010-03-11 09:03:00 +00004108
4109 // Deal with the possibility that we don't have a parameter
4110 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004111 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004112 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004113 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004114 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004115 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004116 = dyn_cast<PackExpansionType>(OldType)) {
4117 // We have a function parameter pack that may need to be expanded.
4118 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004119 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004120 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004121
Douglas Gregor603cfb42011-01-05 23:12:31 +00004122 // Determine whether we should expand the parameter packs.
4123 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004124 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004125 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004126 Unexpanded,
4127 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004128 RetainExpansion,
4129 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004130 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132
Douglas Gregor603cfb42011-01-05 23:12:31 +00004133 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004134 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004135 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004136 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004137 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4138 QualType NewType = getDerived().TransformType(Pattern);
4139 if (NewType.isNull())
4140 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004141
Douglas Gregora009b592011-01-07 00:20:55 +00004142 OutParamTypes.push_back(NewType);
4143 if (PVars)
4144 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004145 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004146
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 // We're done with the pack expansion.
4148 continue;
4149 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004150
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004151 // If we're supposed to retain a pack expansion, do so by temporarily
4152 // forgetting the partially-substituted parameter pack.
4153 if (RetainExpansion) {
4154 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4155 QualType NewType = getDerived().TransformType(Pattern);
4156 if (NewType.isNull())
4157 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004158
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004159 OutParamTypes.push_back(NewType);
4160 if (PVars)
4161 PVars->push_back(0);
4162 }
Douglas Gregord3731192011-01-10 07:32:04 +00004163
Chad Rosier4a9d7952012-08-08 18:46:20 +00004164 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004165 // expansion.
4166 OldType = Expansion->getPattern();
4167 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004168 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4169 NewType = getDerived().TransformType(OldType);
4170 } else {
4171 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004173
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 if (NewType.isNull())
4175 return true;
4176
4177 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004178 NewType = getSema().Context.getPackExpansionType(NewType,
4179 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004180
Douglas Gregora009b592011-01-07 00:20:55 +00004181 OutParamTypes.push_back(NewType);
4182 if (PVars)
4183 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004184 }
4185
John McCallfb44de92011-05-01 22:35:37 +00004186#ifndef NDEBUG
4187 if (PVars) {
4188 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4189 if (ParmVarDecl *parm = (*PVars)[i])
4190 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004191 }
John McCallfb44de92011-05-01 22:35:37 +00004192#endif
4193
4194 return false;
4195}
John McCall21ef0fa2010-03-11 09:03:00 +00004196
4197template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004198QualType
John McCalla2becad2009-10-21 00:40:46 +00004199TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004200 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004201 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4202}
4203
4204template<typename Derived>
4205QualType
4206TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4207 FunctionProtoTypeLoc TL,
4208 CXXRecordDecl *ThisContext,
4209 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004210 // Transform the parameters and return type.
4211 //
Richard Smithe6975e92012-04-17 00:58:00 +00004212 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004213 // When the function has a trailing return type, we instantiate the
4214 // parameters before the return type, since the return type can then refer
4215 // to the parameters themselves (via decltype, sizeof, etc.).
4216 //
Chris Lattner686775d2011-07-20 06:58:45 +00004217 SmallVector<QualType, 4> ParamTypes;
4218 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004219 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004220
Douglas Gregordab60ad2010-10-01 18:44:50 +00004221 QualType ResultType;
4222
Richard Smith9fbf3272012-08-14 22:51:13 +00004223 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004224 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004225 TL.getParmArray(),
4226 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004227 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004228 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004229 return QualType();
4230
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004231 {
4232 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004233 // If a declaration declares a member function or member function
4234 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004235 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004237 // declarator.
4238 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004239
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004240 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4241 if (ResultType.isNull())
4242 return QualType();
4243 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004244 }
4245 else {
4246 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4247 if (ResultType.isNull())
4248 return QualType();
4249
Chad Rosier4a9d7952012-08-08 18:46:20 +00004250 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004251 TL.getParmArray(),
4252 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004253 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004254 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004255 return QualType();
4256 }
4257
Richard Smithe6975e92012-04-17 00:58:00 +00004258 // FIXME: Need to transform the exception-specification too.
4259
John McCalla2becad2009-10-21 00:40:46 +00004260 QualType Result = TL.getType();
4261 if (getDerived().AlwaysRebuild() ||
4262 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004263 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004264 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004265 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004266 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004267 if (Result.isNull())
4268 return QualType();
4269 }
Mike Stump1eb44332009-09-09 15:08:12 +00004270
John McCalla2becad2009-10-21 00:40:46 +00004271 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004272 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004273 NewTL.setLParenLoc(TL.getLParenLoc());
4274 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004275 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004276 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4277 NewTL.setArg(i, ParamDecls[i]);
4278
4279 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004280}
Mike Stump1eb44332009-09-09 15:08:12 +00004281
Douglas Gregor577f75a2009-08-04 16:50:30 +00004282template<typename Derived>
4283QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004284 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004285 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004286 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004287 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4288 if (ResultType.isNull())
4289 return QualType();
4290
4291 QualType Result = TL.getType();
4292 if (getDerived().AlwaysRebuild() ||
4293 ResultType != T->getResultType())
4294 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4295
4296 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004297 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004298 NewTL.setLParenLoc(TL.getLParenLoc());
4299 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004300 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004301
4302 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004303}
Mike Stump1eb44332009-09-09 15:08:12 +00004304
John McCalled976492009-12-04 22:46:56 +00004305template<typename Derived> QualType
4306TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004307 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004308 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004309 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004310 if (!D)
4311 return QualType();
4312
4313 QualType Result = TL.getType();
4314 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4315 Result = getDerived().RebuildUnresolvedUsingType(D);
4316 if (Result.isNull())
4317 return QualType();
4318 }
4319
4320 // We might get an arbitrary type spec type back. We should at
4321 // least always get a type spec type, though.
4322 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4323 NewTL.setNameLoc(TL.getNameLoc());
4324
4325 return Result;
4326}
4327
Douglas Gregor577f75a2009-08-04 16:50:30 +00004328template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004329QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004330 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004331 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004332 TypedefNameDecl *Typedef
4333 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4334 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335 if (!Typedef)
4336 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004337
John McCalla2becad2009-10-21 00:40:46 +00004338 QualType Result = TL.getType();
4339 if (getDerived().AlwaysRebuild() ||
4340 Typedef != T->getDecl()) {
4341 Result = getDerived().RebuildTypedefType(Typedef);
4342 if (Result.isNull())
4343 return QualType();
4344 }
Mike Stump1eb44332009-09-09 15:08:12 +00004345
John McCalla2becad2009-10-21 00:40:46 +00004346 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4347 NewTL.setNameLoc(TL.getNameLoc());
4348
4349 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004350}
Mike Stump1eb44332009-09-09 15:08:12 +00004351
Douglas Gregor577f75a2009-08-04 16:50:30 +00004352template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004353QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004354 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004355 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004356 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4357 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCall60d7b3a2010-08-24 06:29:42 +00004359 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360 if (E.isInvalid())
4361 return QualType();
4362
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004363 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4364 if (E.isInvalid())
4365 return QualType();
4366
John McCalla2becad2009-10-21 00:40:46 +00004367 QualType Result = TL.getType();
4368 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004369 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004370 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004371 if (Result.isNull())
4372 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373 }
John McCalla2becad2009-10-21 00:40:46 +00004374 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004375
John McCalla2becad2009-10-21 00:40:46 +00004376 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004377 NewTL.setTypeofLoc(TL.getTypeofLoc());
4378 NewTL.setLParenLoc(TL.getLParenLoc());
4379 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004380
4381 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004382}
Mike Stump1eb44332009-09-09 15:08:12 +00004383
4384template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004385QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004386 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004387 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4388 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4389 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004391
John McCalla2becad2009-10-21 00:40:46 +00004392 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004393 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4394 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004395 if (Result.isNull())
4396 return QualType();
4397 }
Mike Stump1eb44332009-09-09 15:08:12 +00004398
John McCalla2becad2009-10-21 00:40:46 +00004399 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004400 NewTL.setTypeofLoc(TL.getTypeofLoc());
4401 NewTL.setLParenLoc(TL.getLParenLoc());
4402 NewTL.setRParenLoc(TL.getRParenLoc());
4403 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004404
4405 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004406}
Mike Stump1eb44332009-09-09 15:08:12 +00004407
4408template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004409QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004410 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004411 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004412
Douglas Gregor670444e2009-08-04 22:27:00 +00004413 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004414 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4415 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004416
John McCall60d7b3a2010-08-24 06:29:42 +00004417 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004418 if (E.isInvalid())
4419 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004420
Richard Smith76f3f692012-02-22 02:04:18 +00004421 E = getSema().ActOnDecltypeExpression(E.take());
4422 if (E.isInvalid())
4423 return QualType();
4424
John McCalla2becad2009-10-21 00:40:46 +00004425 QualType Result = TL.getType();
4426 if (getDerived().AlwaysRebuild() ||
4427 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004428 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004429 if (Result.isNull())
4430 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004431 }
John McCalla2becad2009-10-21 00:40:46 +00004432 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004433
John McCalla2becad2009-10-21 00:40:46 +00004434 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4435 NewTL.setNameLoc(TL.getNameLoc());
4436
4437 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004438}
4439
4440template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004441QualType TreeTransform<Derived>::TransformUnaryTransformType(
4442 TypeLocBuilder &TLB,
4443 UnaryTransformTypeLoc TL) {
4444 QualType Result = TL.getType();
4445 if (Result->isDependentType()) {
4446 const UnaryTransformType *T = TL.getTypePtr();
4447 QualType NewBase =
4448 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4449 Result = getDerived().RebuildUnaryTransformType(NewBase,
4450 T->getUTTKind(),
4451 TL.getKWLoc());
4452 if (Result.isNull())
4453 return QualType();
4454 }
4455
4456 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4457 NewTL.setKWLoc(TL.getKWLoc());
4458 NewTL.setParensRange(TL.getParensRange());
4459 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4460 return Result;
4461}
4462
4463template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004464QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4465 AutoTypeLoc TL) {
4466 const AutoType *T = TL.getTypePtr();
4467 QualType OldDeduced = T->getDeducedType();
4468 QualType NewDeduced;
4469 if (!OldDeduced.isNull()) {
4470 NewDeduced = getDerived().TransformType(OldDeduced);
4471 if (NewDeduced.isNull())
4472 return QualType();
4473 }
4474
4475 QualType Result = TL.getType();
4476 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4477 Result = getDerived().RebuildAutoType(NewDeduced);
4478 if (Result.isNull())
4479 return QualType();
4480 }
4481
4482 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4483 NewTL.setNameLoc(TL.getNameLoc());
4484
4485 return Result;
4486}
4487
4488template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004489QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004490 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004491 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004492 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004493 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4494 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004495 if (!Record)
4496 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004497
John McCalla2becad2009-10-21 00:40:46 +00004498 QualType Result = TL.getType();
4499 if (getDerived().AlwaysRebuild() ||
4500 Record != T->getDecl()) {
4501 Result = getDerived().RebuildRecordType(Record);
4502 if (Result.isNull())
4503 return QualType();
4504 }
Mike Stump1eb44332009-09-09 15:08:12 +00004505
John McCalla2becad2009-10-21 00:40:46 +00004506 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4507 NewTL.setNameLoc(TL.getNameLoc());
4508
4509 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004510}
Mike Stump1eb44332009-09-09 15:08:12 +00004511
4512template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004513QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004514 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004515 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004516 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004517 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4518 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519 if (!Enum)
4520 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004521
John McCalla2becad2009-10-21 00:40:46 +00004522 QualType Result = TL.getType();
4523 if (getDerived().AlwaysRebuild() ||
4524 Enum != T->getDecl()) {
4525 Result = getDerived().RebuildEnumType(Enum);
4526 if (Result.isNull())
4527 return QualType();
4528 }
Mike Stump1eb44332009-09-09 15:08:12 +00004529
John McCalla2becad2009-10-21 00:40:46 +00004530 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4531 NewTL.setNameLoc(TL.getNameLoc());
4532
4533 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004534}
John McCall7da24312009-09-05 00:15:47 +00004535
John McCall3cb0ebd2010-03-10 03:28:59 +00004536template<typename Derived>
4537QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4538 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004539 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004540 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4541 TL.getTypePtr()->getDecl());
4542 if (!D) return QualType();
4543
4544 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4545 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4546 return T;
4547}
4548
Douglas Gregor577f75a2009-08-04 16:50:30 +00004549template<typename Derived>
4550QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004551 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004552 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004553 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004554}
4555
Mike Stump1eb44332009-09-09 15:08:12 +00004556template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004557QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004558 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004559 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004560 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004561
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004562 // Substitute into the replacement type, which itself might involve something
4563 // that needs to be transformed. This only tends to occur with default
4564 // template arguments of template template parameters.
4565 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4566 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4567 if (Replacement.isNull())
4568 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004569
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004570 // Always canonicalize the replacement type.
4571 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4572 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004573 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004574 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004575
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004576 // Propagate type-source information.
4577 SubstTemplateTypeParmTypeLoc NewTL
4578 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4579 NewTL.setNameLoc(TL.getNameLoc());
4580 return Result;
4581
John McCall49a832b2009-10-18 09:09:24 +00004582}
4583
4584template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004585QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4586 TypeLocBuilder &TLB,
4587 SubstTemplateTypeParmPackTypeLoc TL) {
4588 return TransformTypeSpecType(TLB, TL);
4589}
4590
4591template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004592QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004593 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004594 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004595 const TemplateSpecializationType *T = TL.getTypePtr();
4596
Douglas Gregor1d752d72011-03-02 18:46:51 +00004597 // The nested-name-specifier never matters in a TemplateSpecializationType,
4598 // because we can't have a dependent nested-name-specifier anyway.
4599 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004600 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004601 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4602 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004603 if (Template.isNull())
4604 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004605
John McCall43fed0d2010-11-12 08:19:04 +00004606 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4607}
4608
Eli Friedmanb001de72011-10-06 23:00:33 +00004609template<typename Derived>
4610QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4611 AtomicTypeLoc TL) {
4612 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4613 if (ValueType.isNull())
4614 return QualType();
4615
4616 QualType Result = TL.getType();
4617 if (getDerived().AlwaysRebuild() ||
4618 ValueType != TL.getValueLoc().getType()) {
4619 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4620 if (Result.isNull())
4621 return QualType();
4622 }
4623
4624 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4625 NewTL.setKWLoc(TL.getKWLoc());
4626 NewTL.setLParenLoc(TL.getLParenLoc());
4627 NewTL.setRParenLoc(TL.getRParenLoc());
4628
4629 return Result;
4630}
4631
Chad Rosier4a9d7952012-08-08 18:46:20 +00004632 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004633 /// container that provides a \c getArgLoc() member function.
4634 ///
4635 /// This iterator is intended to be used with the iterator form of
4636 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4637 template<typename ArgLocContainer>
4638 class TemplateArgumentLocContainerIterator {
4639 ArgLocContainer *Container;
4640 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004641
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004642 public:
4643 typedef TemplateArgumentLoc value_type;
4644 typedef TemplateArgumentLoc reference;
4645 typedef int difference_type;
4646 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004647
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004648 class pointer {
4649 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004650
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004651 public:
4652 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004653
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004654 const TemplateArgumentLoc *operator->() const {
4655 return &Arg;
4656 }
4657 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004658
4659
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004660 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004661
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004662 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4663 unsigned Index)
4664 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004665
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004666 TemplateArgumentLocContainerIterator &operator++() {
4667 ++Index;
4668 return *this;
4669 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004670
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 TemplateArgumentLocContainerIterator operator++(int) {
4672 TemplateArgumentLocContainerIterator Old(*this);
4673 ++(*this);
4674 return Old;
4675 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004676
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004677 TemplateArgumentLoc operator*() const {
4678 return Container->getArgLoc(Index);
4679 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004680
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004681 pointer operator->() const {
4682 return pointer(Container->getArgLoc(Index));
4683 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004684
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004685 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004686 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004687 return X.Container == Y.Container && X.Index == Y.Index;
4688 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004689
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004691 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 return !(X == Y);
4693 }
4694 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004695
4696
John McCall43fed0d2010-11-12 08:19:04 +00004697template <typename Derived>
4698QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4699 TypeLocBuilder &TLB,
4700 TemplateSpecializationTypeLoc TL,
4701 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004702 TemplateArgumentListInfo NewTemplateArgs;
4703 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4704 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004705 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4706 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004707 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004708 ArgIterator(TL, TL.getNumArgs()),
4709 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004710 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004711
John McCall833ca992009-10-29 08:12:44 +00004712 // FIXME: maybe don't rebuild if all the template arguments are the same.
4713
4714 QualType Result =
4715 getDerived().RebuildTemplateSpecializationType(Template,
4716 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004717 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004718
4719 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004720 // Specializations of template template parameters are represented as
4721 // TemplateSpecializationTypes, and substitution of type alias templates
4722 // within a dependent context can transform them into
4723 // DependentTemplateSpecializationTypes.
4724 if (isa<DependentTemplateSpecializationType>(Result)) {
4725 DependentTemplateSpecializationTypeLoc NewTL
4726 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004727 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004728 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004729 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004730 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004731 NewTL.setLAngleLoc(TL.getLAngleLoc());
4732 NewTL.setRAngleLoc(TL.getRAngleLoc());
4733 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4734 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4735 return Result;
4736 }
4737
John McCall833ca992009-10-29 08:12:44 +00004738 TemplateSpecializationTypeLoc NewTL
4739 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004740 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004741 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4742 NewTL.setLAngleLoc(TL.getLAngleLoc());
4743 NewTL.setRAngleLoc(TL.getRAngleLoc());
4744 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4745 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004746 }
Mike Stump1eb44332009-09-09 15:08:12 +00004747
John McCall833ca992009-10-29 08:12:44 +00004748 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004749}
Mike Stump1eb44332009-09-09 15:08:12 +00004750
Douglas Gregora88f09f2011-02-28 17:23:35 +00004751template <typename Derived>
4752QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4753 TypeLocBuilder &TLB,
4754 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004755 TemplateName Template,
4756 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004757 TemplateArgumentListInfo NewTemplateArgs;
4758 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4759 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4760 typedef TemplateArgumentLocContainerIterator<
4761 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004762 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004763 ArgIterator(TL, TL.getNumArgs()),
4764 NewTemplateArgs))
4765 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004766
Douglas Gregora88f09f2011-02-28 17:23:35 +00004767 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004768
Douglas Gregora88f09f2011-02-28 17:23:35 +00004769 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4770 QualType Result
4771 = getSema().Context.getDependentTemplateSpecializationType(
4772 TL.getTypePtr()->getKeyword(),
4773 DTN->getQualifier(),
4774 DTN->getIdentifier(),
4775 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004776
Douglas Gregora88f09f2011-02-28 17:23:35 +00004777 DependentTemplateSpecializationTypeLoc NewTL
4778 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004779 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004780 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004781 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004782 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004783 NewTL.setLAngleLoc(TL.getLAngleLoc());
4784 NewTL.setRAngleLoc(TL.getRAngleLoc());
4785 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4786 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4787 return Result;
4788 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004789
4790 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004791 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004792 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004793 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004794
Douglas Gregora88f09f2011-02-28 17:23:35 +00004795 if (!Result.isNull()) {
4796 /// FIXME: Wrap this in an elaborated-type-specifier?
4797 TemplateSpecializationTypeLoc NewTL
4798 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004799 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004800 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004801 NewTL.setLAngleLoc(TL.getLAngleLoc());
4802 NewTL.setRAngleLoc(TL.getRAngleLoc());
4803 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4804 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4805 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004806
Douglas Gregora88f09f2011-02-28 17:23:35 +00004807 return Result;
4808}
4809
Mike Stump1eb44332009-09-09 15:08:12 +00004810template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004811QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004812TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004813 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004814 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004815
Douglas Gregor9e876872011-03-01 18:12:44 +00004816 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004817 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004818 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004819 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004820 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4821 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004822 return QualType();
4823 }
Mike Stump1eb44332009-09-09 15:08:12 +00004824
John McCall43fed0d2010-11-12 08:19:04 +00004825 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4826 if (NamedT.isNull())
4827 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004828
Richard Smith3e4c6c42011-05-05 21:57:07 +00004829 // C++0x [dcl.type.elab]p2:
4830 // If the identifier resolves to a typedef-name or the simple-template-id
4831 // resolves to an alias template specialization, the
4832 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004833 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4834 if (const TemplateSpecializationType *TST =
4835 NamedT->getAs<TemplateSpecializationType>()) {
4836 TemplateName Template = TST->getTemplateName();
4837 if (TypeAliasTemplateDecl *TAT =
4838 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4839 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4840 diag::err_tag_reference_non_tag) << 4;
4841 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4842 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004843 }
4844 }
4845
John McCalla2becad2009-10-21 00:40:46 +00004846 QualType Result = TL.getType();
4847 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004848 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004849 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004850 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004851 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004852 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004853 if (Result.isNull())
4854 return QualType();
4855 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004856
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004857 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004858 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004859 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004860 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004861}
Mike Stump1eb44332009-09-09 15:08:12 +00004862
4863template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004864QualType TreeTransform<Derived>::TransformAttributedType(
4865 TypeLocBuilder &TLB,
4866 AttributedTypeLoc TL) {
4867 const AttributedType *oldType = TL.getTypePtr();
4868 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4869 if (modifiedType.isNull())
4870 return QualType();
4871
4872 QualType result = TL.getType();
4873
4874 // FIXME: dependent operand expressions?
4875 if (getDerived().AlwaysRebuild() ||
4876 modifiedType != oldType->getModifiedType()) {
4877 // TODO: this is really lame; we should really be rebuilding the
4878 // equivalent type from first principles.
4879 QualType equivalentType
4880 = getDerived().TransformType(oldType->getEquivalentType());
4881 if (equivalentType.isNull())
4882 return QualType();
4883 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4884 modifiedType,
4885 equivalentType);
4886 }
4887
4888 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4889 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4890 if (TL.hasAttrOperand())
4891 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4892 if (TL.hasAttrExprOperand())
4893 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4894 else if (TL.hasAttrEnumOperand())
4895 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4896
4897 return result;
4898}
4899
4900template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004901QualType
4902TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4903 ParenTypeLoc TL) {
4904 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4905 if (Inner.isNull())
4906 return QualType();
4907
4908 QualType Result = TL.getType();
4909 if (getDerived().AlwaysRebuild() ||
4910 Inner != TL.getInnerLoc().getType()) {
4911 Result = getDerived().RebuildParenType(Inner);
4912 if (Result.isNull())
4913 return QualType();
4914 }
4915
4916 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4917 NewTL.setLParenLoc(TL.getLParenLoc());
4918 NewTL.setRParenLoc(TL.getRParenLoc());
4919 return Result;
4920}
4921
4922template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004923QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004924 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004925 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004926
Douglas Gregor2494dd02011-03-01 01:34:45 +00004927 NestedNameSpecifierLoc QualifierLoc
4928 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4929 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004930 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004931
John McCall33500952010-06-11 00:33:02 +00004932 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004933 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004934 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004935 QualifierLoc,
4936 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004937 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004938 if (Result.isNull())
4939 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004940
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004941 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4942 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004943 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4944
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004945 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004946 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004947 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004948 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004949 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004950 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004951 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004952 NewTL.setNameLoc(TL.getNameLoc());
4953 }
John McCalla2becad2009-10-21 00:40:46 +00004954 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004955}
Mike Stump1eb44332009-09-09 15:08:12 +00004956
Douglas Gregor577f75a2009-08-04 16:50:30 +00004957template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004958QualType TreeTransform<Derived>::
4959 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004960 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004961 NestedNameSpecifierLoc QualifierLoc;
4962 if (TL.getQualifierLoc()) {
4963 QualifierLoc
4964 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4965 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004966 return QualType();
4967 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004968
John McCall43fed0d2010-11-12 08:19:04 +00004969 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004970 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004971}
4972
4973template<typename Derived>
4974QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004975TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4976 DependentTemplateSpecializationTypeLoc TL,
4977 NestedNameSpecifierLoc QualifierLoc) {
4978 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004979
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004980 TemplateArgumentListInfo NewTemplateArgs;
4981 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4982 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004983
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004984 typedef TemplateArgumentLocContainerIterator<
4985 DependentTemplateSpecializationTypeLoc> ArgIterator;
4986 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4987 ArgIterator(TL, TL.getNumArgs()),
4988 NewTemplateArgs))
4989 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004990
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004991 QualType Result
4992 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4993 QualifierLoc,
4994 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004995 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004996 NewTemplateArgs);
4997 if (Result.isNull())
4998 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004999
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005000 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5001 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 // Copy information relevant to the template specialization.
5004 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005005 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005006 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005007 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005008 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5009 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005010 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005011 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005012
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005013 // Copy information relevant to the elaborated type.
5014 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005015 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005016 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005017 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5018 DependentTemplateSpecializationTypeLoc SpecTL
5019 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005020 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005022 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005023 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005024 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5025 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005026 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005027 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005028 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005029 TemplateSpecializationTypeLoc SpecTL
5030 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005031 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005032 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005033 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5034 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005035 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005036 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005037 }
5038 return Result;
5039}
5040
5041template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005042QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5043 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005044 QualType Pattern
5045 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005046 if (Pattern.isNull())
5047 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005048
5049 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005050 if (getDerived().AlwaysRebuild() ||
5051 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005052 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005053 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005054 TL.getEllipsisLoc(),
5055 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005056 if (Result.isNull())
5057 return QualType();
5058 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005059
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005060 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5061 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5062 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005063}
5064
5065template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005066QualType
5067TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005068 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005069 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005070 TLB.pushFullCopy(TL);
5071 return TL.getType();
5072}
5073
5074template<typename Derived>
5075QualType
5076TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005077 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005078 // ObjCObjectType is never dependent.
5079 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005080 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005081}
Mike Stump1eb44332009-09-09 15:08:12 +00005082
5083template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005084QualType
5085TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005086 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005087 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005088 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005089 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005090}
5091
Douglas Gregor577f75a2009-08-04 16:50:30 +00005092//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005093// Statement transformation
5094//===----------------------------------------------------------------------===//
5095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005096StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005097TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005098 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005099}
5100
5101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005102StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005103TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5104 return getDerived().TransformCompoundStmt(S, false);
5105}
5106
5107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005108StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005109TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005110 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005111 Sema::CompoundScopeRAII CompoundScope(getSema());
5112
John McCall7114cba2010-08-27 19:56:05 +00005113 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005115 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5117 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005118 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005119 if (Result.isInvalid()) {
5120 // Immediately fail if this was a DeclStmt, since it's very
5121 // likely that this will cause problems for future statements.
5122 if (isa<DeclStmt>(*B))
5123 return StmtError();
5124
5125 // Otherwise, just keep processing substatements and fail later.
5126 SubStmtInvalid = true;
5127 continue;
5128 }
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5131 Statements.push_back(Result.takeAs<Stmt>());
5132 }
Mike Stump1eb44332009-09-09 15:08:12 +00005133
John McCall7114cba2010-08-27 19:56:05 +00005134 if (SubStmtInvalid)
5135 return StmtError();
5136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005139 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005140
5141 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005142 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 S->getRBracLoc(),
5144 IsStmtExpr);
5145}
Mike Stump1eb44332009-09-09 15:08:12 +00005146
Douglas Gregor43959a92009-08-20 07:17:43 +00005147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005148StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005149TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005150 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005152 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5153 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005154
Eli Friedman264c1f82009-11-19 03:14:00 +00005155 // Transform the left-hand case value.
5156 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005157 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005158 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005159 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Eli Friedman264c1f82009-11-19 03:14:00 +00005161 // Transform the right-hand case value (for the GNU case-range extension).
5162 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005163 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005164 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005165 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005166 }
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 // Build the case statement.
5169 // Case statements are always rebuilt so that they will attached to their
5170 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005171 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005172 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005174 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 S->getColonLoc());
5176 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005177 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005180 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005182 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005185 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005186}
5187
5188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005189StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005190TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005192 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005194 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregor43959a92009-08-20 07:17:43 +00005196 // Default statements are always rebuilt
5197 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005198 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005199}
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregor43959a92009-08-20 07:17:43 +00005201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005202StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005203TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005204 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005205 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005206 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Chris Lattner57ad3782011-02-17 20:34:02 +00005208 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5209 S->getDecl());
5210 if (!LD)
5211 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005212
5213
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005215 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005216 cast<LabelDecl>(LD), SourceLocation(),
5217 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005218}
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregor43959a92009-08-20 07:17:43 +00005220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005221StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005222TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5223 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5224 if (SubStmt.isInvalid())
5225 return StmtError();
5226
5227 // TODO: transform attributes
5228 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5229 return S;
5230
5231 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5232 S->getAttrs(),
5233 SubStmt.get());
5234}
5235
5236template<typename Derived>
5237StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005238TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005239 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005240 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005241 VarDecl *ConditionVar = 0;
5242 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005243 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005244 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005245 getDerived().TransformDefinition(
5246 S->getConditionVariable()->getLocation(),
5247 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005248 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005250 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005251 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005252
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005253 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005254 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005255
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005256 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005257 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005258 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005259 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005260 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005261 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005262
John McCall9ae2f072010-08-23 23:25:46 +00005263 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005264 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005266
John McCall9ae2f072010-08-23 23:25:46 +00005267 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5268 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005269 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005270
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005272 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005274 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005275
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005277 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005279 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005280
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005282 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005283 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 Then.get() == S->getThen() &&
5285 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005286 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005288 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005289 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005290 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005291}
5292
5293template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005294StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005295TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005297 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005298 VarDecl *ConditionVar = 0;
5299 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005300 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005301 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005302 getDerived().TransformDefinition(
5303 S->getConditionVariable()->getLocation(),
5304 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005305 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005306 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005307 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005308 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005309
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005310 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005311 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005312 }
Mike Stump1eb44332009-09-09 15:08:12 +00005313
Douglas Gregor43959a92009-08-20 07:17:43 +00005314 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005315 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005316 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005317 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005318 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005322 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005325
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005327 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5328 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005329}
Mike Stump1eb44332009-09-09 15:08:12 +00005330
Douglas Gregor43959a92009-08-20 07:17:43 +00005331template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005332StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005333TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005335 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005336 VarDecl *ConditionVar = 0;
5337 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005338 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005339 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005340 getDerived().TransformDefinition(
5341 S->getConditionVariable()->getLocation(),
5342 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005343 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005344 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005345 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005346 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005347
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005348 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005349 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005350
5351 if (S->getCond()) {
5352 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005353 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005354 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005355 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005356 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005357 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005358 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005359 }
Mike Stump1eb44332009-09-09 15:08:12 +00005360
John McCall9ae2f072010-08-23 23:25:46 +00005361 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5362 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005366 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005368 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005371 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005372 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005374 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005375
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005376 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005377 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005378}
Mike Stump1eb44332009-09-09 15:08:12 +00005379
Douglas Gregor43959a92009-08-20 07:17:43 +00005380template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005381StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005382TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005383 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005384 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005386 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005388 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005389 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005390 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005391 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005392
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 if (!getDerived().AlwaysRebuild() &&
5394 Cond.get() == S->getCond() &&
5395 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005396 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005397
John McCall9ae2f072010-08-23 23:25:46 +00005398 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5399 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005400 S->getRParenLoc());
5401}
Mike Stump1eb44332009-09-09 15:08:12 +00005402
Douglas Gregor43959a92009-08-20 07:17:43 +00005403template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005404StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005405TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005407 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005409 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005410
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005412 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005413 VarDecl *ConditionVar = 0;
5414 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005415 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005416 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005417 getDerived().TransformDefinition(
5418 S->getConditionVariable()->getLocation(),
5419 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005420 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005421 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 } else {
5423 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005424
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005425 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005427
5428 if (S->getCond()) {
5429 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005430 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005431 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005432 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005434
John McCall9ae2f072010-08-23 23:25:46 +00005435 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005436 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005437 }
Mike Stump1eb44332009-09-09 15:08:12 +00005438
Chad Rosier4a9d7952012-08-08 18:46:20 +00005439 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005440 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005442
Douglas Gregor43959a92009-08-20 07:17:43 +00005443 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005444 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005446 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005447
Richard Smith41956372013-01-14 22:39:08 +00005448 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005449 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005450 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005451
Douglas Gregor43959a92009-08-20 07:17:43 +00005452 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005453 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005455 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregor43959a92009-08-20 07:17:43 +00005457 if (!getDerived().AlwaysRebuild() &&
5458 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005459 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 Inc.get() == S->getInc() &&
5461 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005462 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005465 Init.get(), FullCond, ConditionVar,
5466 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005467}
5468
5469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005470StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005471TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005472 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5473 S->getLabel());
5474 if (!LD)
5475 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005476
Douglas Gregor43959a92009-08-20 07:17:43 +00005477 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005478 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005479 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005480}
5481
5482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005483StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005484TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005485 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005486 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005487 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005488 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregor43959a92009-08-20 07:17:43 +00005490 if (!getDerived().AlwaysRebuild() &&
5491 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005492 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005493
5494 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005495 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005496}
5497
5498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005500TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005501 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005502}
Mike Stump1eb44332009-09-09 15:08:12 +00005503
Douglas Gregor43959a92009-08-20 07:17:43 +00005504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005505StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005506TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005507 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005508}
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Douglas Gregor43959a92009-08-20 07:17:43 +00005510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005511StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005512TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005513 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005514 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005515 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005516
Mike Stump1eb44332009-09-09 15:08:12 +00005517 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005518 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005519 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005520}
Mike Stump1eb44332009-09-09 15:08:12 +00005521
Douglas Gregor43959a92009-08-20 07:17:43 +00005522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005523StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005524TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005526 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5528 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005529 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5530 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005531 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005532 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005533
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 if (Transformed != *D)
5535 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregor43959a92009-08-20 07:17:43 +00005537 Decls.push_back(Transformed);
5538 }
Mike Stump1eb44332009-09-09 15:08:12 +00005539
Douglas Gregor43959a92009-08-20 07:17:43 +00005540 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005541 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005542
5543 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005544 S->getStartLoc(), S->getEndLoc());
5545}
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregor43959a92009-08-20 07:17:43 +00005547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005548StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005549TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005550
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005551 SmallVector<Expr*, 8> Constraints;
5552 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005553 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005554
John McCall60d7b3a2010-08-24 06:29:42 +00005555 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005556 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005557
5558 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005559
Anders Carlsson703e3942010-01-24 05:50:09 +00005560 // Go through the outputs.
5561 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005562 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005563
Anders Carlsson703e3942010-01-24 05:50:09 +00005564 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005565 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 // Transform the output expr.
5568 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005569 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005571 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005572
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
John McCall9ae2f072010-08-23 23:25:46 +00005575 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 // Go through the inputs.
5579 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005580 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005581
Anders Carlsson703e3942010-01-24 05:50:09 +00005582 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005583 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Anders Carlsson703e3942010-01-24 05:50:09 +00005585 // Transform the input expr.
5586 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005587 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005588 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005589 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005590
Anders Carlsson703e3942010-01-24 05:50:09 +00005591 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005592
John McCall9ae2f072010-08-23 23:25:46 +00005593 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005594 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005595
Anders Carlsson703e3942010-01-24 05:50:09 +00005596 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005597 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005598
5599 // Go through the clobbers.
5600 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005601 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005602
5603 // No need to transform the asm string literal.
5604 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005605 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5606 S->isVolatile(), S->getNumOutputs(),
5607 S->getNumInputs(), Names.data(),
5608 Constraints, Exprs, AsmString.get(),
5609 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005610}
5611
Chad Rosier8cd64b42012-06-11 20:47:18 +00005612template<typename Derived>
5613StmtResult
5614TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005615 ArrayRef<Token> AsmToks =
5616 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005617
Chad Rosier7bd092b2012-08-15 16:53:30 +00005618 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5619 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005620}
Douglas Gregor43959a92009-08-20 07:17:43 +00005621
5622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005623StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005624TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005625 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005626 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005627 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005628 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005629
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005630 // Transform the @catch statements (if present).
5631 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005632 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005633 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005634 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005635 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005636 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005637 if (Catch.get() != S->getCatchStmt(I))
5638 AnyCatchChanged = true;
5639 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005640 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005641
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005642 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005643 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005644 if (S->getFinallyStmt()) {
5645 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5646 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005647 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005648 }
5649
5650 // If nothing changed, just retain this statement.
5651 if (!getDerived().AlwaysRebuild() &&
5652 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005653 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005654 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005655 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005656
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005657 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005658 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005659 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005660}
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Douglas Gregor43959a92009-08-20 07:17:43 +00005662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005663StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005664TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005665 // Transform the @catch parameter, if there is one.
5666 VarDecl *Var = 0;
5667 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5668 TypeSourceInfo *TSInfo = 0;
5669 if (FromVar->getTypeSourceInfo()) {
5670 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5671 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005672 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005673 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005674
Douglas Gregorbe270a02010-04-26 17:57:08 +00005675 QualType T;
5676 if (TSInfo)
5677 T = TSInfo->getType();
5678 else {
5679 T = getDerived().TransformType(FromVar->getType());
5680 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005681 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005682 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005683
Douglas Gregorbe270a02010-04-26 17:57:08 +00005684 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5685 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005686 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005687 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005688
John McCall60d7b3a2010-08-24 06:29:42 +00005689 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005690 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005691 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005692
5693 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005694 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005695 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005696}
Mike Stump1eb44332009-09-09 15:08:12 +00005697
Douglas Gregor43959a92009-08-20 07:17:43 +00005698template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005699StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005700TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005701 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005702 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005703 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005704 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005705
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005706 // If nothing changed, just retain this statement.
5707 if (!getDerived().AlwaysRebuild() &&
5708 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005709 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005710
5711 // Build a new statement.
5712 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005713 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005714}
Mike Stump1eb44332009-09-09 15:08:12 +00005715
Douglas Gregor43959a92009-08-20 07:17:43 +00005716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005717StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005718TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005719 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005720 if (S->getThrowExpr()) {
5721 Operand = getDerived().TransformExpr(S->getThrowExpr());
5722 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005723 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005724 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005725
Douglas Gregord1377b22010-04-22 21:44:01 +00005726 if (!getDerived().AlwaysRebuild() &&
5727 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005728 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005729
John McCall9ae2f072010-08-23 23:25:46 +00005730 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005731}
Mike Stump1eb44332009-09-09 15:08:12 +00005732
Douglas Gregor43959a92009-08-20 07:17:43 +00005733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005734StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005735TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005736 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005737 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005738 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005739 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005740 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005741 Object =
5742 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5743 Object.get());
5744 if (Object.isInvalid())
5745 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005746
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005747 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005748 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005749 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005750 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005751
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005752 // If nothing change, just retain the current statement.
5753 if (!getDerived().AlwaysRebuild() &&
5754 Object.get() == S->getSynchExpr() &&
5755 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005756 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005757
5758 // Build a new statement.
5759 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005760 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005761}
5762
5763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005764StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005765TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5766 ObjCAutoreleasePoolStmt *S) {
5767 // Transform the body.
5768 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5769 if (Body.isInvalid())
5770 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005771
John McCallf85e1932011-06-15 23:02:42 +00005772 // If nothing changed, just retain this statement.
5773 if (!getDerived().AlwaysRebuild() &&
5774 Body.get() == S->getSubStmt())
5775 return SemaRef.Owned(S);
5776
5777 // Build a new statement.
5778 return getDerived().RebuildObjCAutoreleasePoolStmt(
5779 S->getAtLoc(), Body.get());
5780}
5781
5782template<typename Derived>
5783StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005784TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005785 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005786 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005787 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 if (Element.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 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005792 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005794 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005795
Douglas Gregorc3203e72010-04-22 23:10:45 +00005796 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005797 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005798 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005799 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005800
Douglas Gregorc3203e72010-04-22 23:10:45 +00005801 // If nothing changed, just retain this statement.
5802 if (!getDerived().AlwaysRebuild() &&
5803 Element.get() == S->getElement() &&
5804 Collection.get() == S->getCollection() &&
5805 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005806 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005807
Douglas Gregorc3203e72010-04-22 23:10:45 +00005808 // Build a new statement.
5809 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005810 Element.get(),
5811 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005812 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005813 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005814}
5815
5816
5817template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005818StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005819TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5820 // Transform the exception declaration, if any.
5821 VarDecl *Var = 0;
5822 if (S->getExceptionDecl()) {
5823 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005824 TypeSourceInfo *T = getDerived().TransformType(
5825 ExceptionDecl->getTypeSourceInfo());
5826 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005827 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005828
Douglas Gregor83cb9422010-09-09 17:09:21 +00005829 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005830 ExceptionDecl->getInnerLocStart(),
5831 ExceptionDecl->getLocation(),
5832 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005833 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005834 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005835 }
Mike Stump1eb44332009-09-09 15:08:12 +00005836
Douglas Gregor43959a92009-08-20 07:17:43 +00005837 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005838 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005839 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005840 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005841
Douglas Gregor43959a92009-08-20 07:17:43 +00005842 if (!getDerived().AlwaysRebuild() &&
5843 !Var &&
5844 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005845 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005846
5847 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5848 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005849 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005850}
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregor43959a92009-08-20 07:17:43 +00005852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005853StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005854TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5855 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005856 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005857 = getDerived().TransformCompoundStmt(S->getTryBlock());
5858 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005859 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregor43959a92009-08-20 07:17:43 +00005861 // Transform the handlers.
5862 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005863 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005865 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005866 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5867 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005868 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Douglas Gregor43959a92009-08-20 07:17:43 +00005870 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5871 Handlers.push_back(Handler.takeAs<Stmt>());
5872 }
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregor43959a92009-08-20 07:17:43 +00005874 if (!getDerived().AlwaysRebuild() &&
5875 TryBlock.get() == S->getTryBlock() &&
5876 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005877 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005878
John McCall9ae2f072010-08-23 23:25:46 +00005879 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005880 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005881}
Mike Stump1eb44332009-09-09 15:08:12 +00005882
Richard Smithad762fc2011-04-14 22:09:26 +00005883template<typename Derived>
5884StmtResult
5885TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5886 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5887 if (Range.isInvalid())
5888 return StmtError();
5889
5890 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5891 if (BeginEnd.isInvalid())
5892 return StmtError();
5893
5894 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5895 if (Cond.isInvalid())
5896 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005897 if (Cond.get())
5898 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5899 if (Cond.isInvalid())
5900 return StmtError();
5901 if (Cond.get())
5902 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005903
5904 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5905 if (Inc.isInvalid())
5906 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005907 if (Inc.get())
5908 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005909
5910 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5911 if (LoopVar.isInvalid())
5912 return StmtError();
5913
5914 StmtResult NewStmt = S;
5915 if (getDerived().AlwaysRebuild() ||
5916 Range.get() != S->getRangeStmt() ||
5917 BeginEnd.get() != S->getBeginEndStmt() ||
5918 Cond.get() != S->getCond() ||
5919 Inc.get() != S->getInc() ||
5920 LoopVar.get() != S->getLoopVarStmt())
5921 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5922 S->getColonLoc(), Range.get(),
5923 BeginEnd.get(), Cond.get(),
5924 Inc.get(), LoopVar.get(),
5925 S->getRParenLoc());
5926
5927 StmtResult Body = getDerived().TransformStmt(S->getBody());
5928 if (Body.isInvalid())
5929 return StmtError();
5930
5931 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5932 // it now so we have a new statement to attach the body to.
5933 if (Body.get() != S->getBody() && NewStmt.get() == S)
5934 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5935 S->getColonLoc(), Range.get(),
5936 BeginEnd.get(), Cond.get(),
5937 Inc.get(), LoopVar.get(),
5938 S->getRParenLoc());
5939
5940 if (NewStmt.get() == S)
5941 return SemaRef.Owned(S);
5942
5943 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5944}
5945
John Wiegley28bbe4b2011-04-28 01:08:34 +00005946template<typename Derived>
5947StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005948TreeTransform<Derived>::TransformMSDependentExistsStmt(
5949 MSDependentExistsStmt *S) {
5950 // Transform the nested-name-specifier, if any.
5951 NestedNameSpecifierLoc QualifierLoc;
5952 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005953 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005954 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5955 if (!QualifierLoc)
5956 return StmtError();
5957 }
5958
5959 // Transform the declaration name.
5960 DeclarationNameInfo NameInfo = S->getNameInfo();
5961 if (NameInfo.getName()) {
5962 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5963 if (!NameInfo.getName())
5964 return StmtError();
5965 }
5966
5967 // Check whether anything changed.
5968 if (!getDerived().AlwaysRebuild() &&
5969 QualifierLoc == S->getQualifierLoc() &&
5970 NameInfo.getName() == S->getNameInfo().getName())
5971 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005972
Douglas Gregorba0513d2011-10-25 01:33:02 +00005973 // Determine whether this name exists, if we can.
5974 CXXScopeSpec SS;
5975 SS.Adopt(QualifierLoc);
5976 bool Dependent = false;
5977 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5978 case Sema::IER_Exists:
5979 if (S->isIfExists())
5980 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorba0513d2011-10-25 01:33:02 +00005982 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5983
5984 case Sema::IER_DoesNotExist:
5985 if (S->isIfNotExists())
5986 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005987
Douglas Gregorba0513d2011-10-25 01:33:02 +00005988 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005989
Douglas Gregorba0513d2011-10-25 01:33:02 +00005990 case Sema::IER_Dependent:
5991 Dependent = true;
5992 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005993
Douglas Gregor65019ac2011-10-25 03:44:56 +00005994 case Sema::IER_Error:
5995 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005996 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005997
Douglas Gregorba0513d2011-10-25 01:33:02 +00005998 // We need to continue with the instantiation, so do so now.
5999 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6000 if (SubStmt.isInvalid())
6001 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006002
Douglas Gregorba0513d2011-10-25 01:33:02 +00006003 // If we have resolved the name, just transform to the substatement.
6004 if (!Dependent)
6005 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006006
Douglas Gregorba0513d2011-10-25 01:33:02 +00006007 // The name is still dependent, so build a dependent expression again.
6008 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6009 S->isIfExists(),
6010 QualifierLoc,
6011 NameInfo,
6012 SubStmt.get());
6013}
6014
6015template<typename Derived>
6016StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006017TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6018 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6019 if(TryBlock.isInvalid()) return StmtError();
6020
6021 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6022 if(!getDerived().AlwaysRebuild() &&
6023 TryBlock.get() == S->getTryBlock() &&
6024 Handler.get() == S->getHandler())
6025 return SemaRef.Owned(S);
6026
6027 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6028 S->getTryLoc(),
6029 TryBlock.take(),
6030 Handler.take());
6031}
6032
6033template<typename Derived>
6034StmtResult
6035TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6036 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6037 if(Block.isInvalid()) return StmtError();
6038
6039 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6040 Block.take());
6041}
6042
6043template<typename Derived>
6044StmtResult
6045TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6046 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6047 if(FilterExpr.isInvalid()) return StmtError();
6048
6049 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6050 if(Block.isInvalid()) return StmtError();
6051
6052 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6053 FilterExpr.take(),
6054 Block.take());
6055}
6056
6057template<typename Derived>
6058StmtResult
6059TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6060 if(isa<SEHFinallyStmt>(Handler))
6061 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6062 else
6063 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6064}
6065
Douglas Gregor43959a92009-08-20 07:17:43 +00006066//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067// Expression transformation
6068//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006070ExprResult
John McCall454feb92009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006072 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073}
Mike Stump1eb44332009-09-09 15:08:12 +00006074
6075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006076ExprResult
John McCall454feb92009-12-08 09:21:05 +00006077TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006078 NestedNameSpecifierLoc QualifierLoc;
6079 if (E->getQualifierLoc()) {
6080 QualifierLoc
6081 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6082 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006083 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006084 }
John McCalldbd872f2009-12-08 09:08:17 +00006085
6086 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006087 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6088 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006089 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006091
John McCallec8045d2010-08-17 21:27:17 +00006092 DeclarationNameInfo NameInfo = E->getNameInfo();
6093 if (NameInfo.getName()) {
6094 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6095 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006096 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006097 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006098
6099 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006100 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006101 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006102 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006103 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006104
6105 // Mark it referenced in the new context regardless.
6106 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006107 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006108
John McCall3fa5cae2010-10-26 07:05:15 +00006109 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006110 }
John McCalldbd872f2009-12-08 09:08:17 +00006111
6112 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006113 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006114 TemplateArgs = &TransArgs;
6115 TransArgs.setLAngleLoc(E->getLAngleLoc());
6116 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006117 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6118 E->getNumTemplateArgs(),
6119 TransArgs))
6120 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006121 }
6122
Chad Rosier4a9d7952012-08-08 18:46:20 +00006123 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006124 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125}
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006128ExprResult
John McCall454feb92009-12-08 09:21:05 +00006129TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131}
Mike Stump1eb44332009-09-09 15:08:12 +00006132
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006136 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137}
Mike Stump1eb44332009-09-09 15:08:12 +00006138
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall454feb92009-12-08 09:21:05 +00006141TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006142 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143}
Mike Stump1eb44332009-09-09 15:08:12 +00006144
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006146ExprResult
John McCall454feb92009-12-08 09:21:05 +00006147TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149}
Mike Stump1eb44332009-09-09 15:08:12 +00006150
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006152ExprResult
John McCall454feb92009-12-08 09:21:05 +00006153TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006154 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006155}
6156
6157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006158ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006159TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6160 return SemaRef.MaybeBindToTemporary(E);
6161}
6162
6163template<typename Derived>
6164ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006165TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6166 ExprResult ControllingExpr =
6167 getDerived().TransformExpr(E->getControllingExpr());
6168 if (ControllingExpr.isInvalid())
6169 return ExprError();
6170
Chris Lattner686775d2011-07-20 06:58:45 +00006171 SmallVector<Expr *, 4> AssocExprs;
6172 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006173 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6174 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6175 if (TS) {
6176 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6177 if (!AssocType)
6178 return ExprError();
6179 AssocTypes.push_back(AssocType);
6180 } else {
6181 AssocTypes.push_back(0);
6182 }
6183
6184 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6185 if (AssocExpr.isInvalid())
6186 return ExprError();
6187 AssocExprs.push_back(AssocExpr.release());
6188 }
6189
6190 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6191 E->getDefaultLoc(),
6192 E->getRParenLoc(),
6193 ControllingExpr.release(),
6194 AssocTypes.data(),
6195 AssocExprs.data(),
6196 E->getNumAssocs());
6197}
6198
6199template<typename Derived>
6200ExprResult
John McCall454feb92009-12-08 09:21:05 +00006201TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006202 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006204 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006205
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006207 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006208
John McCall9ae2f072010-08-23 23:25:46 +00006209 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 E->getRParen());
6211}
6212
Richard Smithefeeccf2012-10-21 03:28:35 +00006213/// \brief The operand of a unary address-of operator has special rules: it's
6214/// allowed to refer to a non-static member of a class even if there's no 'this'
6215/// object available.
6216template<typename Derived>
6217ExprResult
6218TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6219 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6220 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6221 else
6222 return getDerived().TransformExpr(E);
6223}
6224
Mike Stump1eb44332009-09-09 15:08:12 +00006225template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006226ExprResult
John McCall454feb92009-12-08 09:21:05 +00006227TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006228 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006229 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006230 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006231
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006233 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6236 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006237 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238}
Mike Stump1eb44332009-09-09 15:08:12 +00006239
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006241ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006242TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6243 // Transform the type.
6244 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6245 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006246 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006247
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 // Transform all of the components into components similar to what the
6249 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006250 // FIXME: It would be slightly more efficient in the non-dependent case to
6251 // just map FieldDecls, rather than requiring the rebuilder to look for
6252 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006253 // template code that we don't care.
6254 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006255 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006256 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006257 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6259 const Node &ON = E->getComponent(I);
6260 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006261 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006262 Comp.LocStart = ON.getSourceRange().getBegin();
6263 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 switch (ON.getKind()) {
6265 case Node::Array: {
6266 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006267 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006268 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006269 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006270
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 ExprChanged = ExprChanged || Index.get() != FromIndex;
6272 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006273 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 break;
6275 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006276
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006277 case Node::Field:
6278 case Node::Identifier:
6279 Comp.isBrackets = false;
6280 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006281 if (!Comp.U.IdentInfo)
6282 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006283
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006284 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006285
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006286 case Node::Base:
6287 // Will be recomputed during the rebuild.
6288 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006289 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006290
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006291 Components.push_back(Comp);
6292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006293
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006294 // If nothing changed, retain the existing expression.
6295 if (!getDerived().AlwaysRebuild() &&
6296 Type == E->getTypeSourceInfo() &&
6297 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006298 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006299
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006300 // Build a new offsetof expression.
6301 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6302 Components.data(), Components.size(),
6303 E->getRParenLoc());
6304}
6305
6306template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006307ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006308TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6309 assert(getDerived().AlreadyTransformed(E->getType()) &&
6310 "opaque value expression requires transformation");
6311 return SemaRef.Owned(E);
6312}
6313
6314template<typename Derived>
6315ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006316TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006317 // Rebuild the syntactic form. The original syntactic form has
6318 // opaque-value expressions in it, so strip those away and rebuild
6319 // the result. This is a really awful way of doing this, but the
6320 // better solution (rebuilding the semantic expressions and
6321 // rebinding OVEs as necessary) doesn't work; we'd need
6322 // TreeTransform to not strip away implicit conversions.
6323 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6324 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006325 if (result.isInvalid()) return ExprError();
6326
6327 // If that gives us a pseudo-object result back, the pseudo-object
6328 // expression must have been an lvalue-to-rvalue conversion which we
6329 // should reapply.
6330 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6331 result = SemaRef.checkPseudoObjectRValue(result.take());
6332
6333 return result;
6334}
6335
6336template<typename Derived>
6337ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006338TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6339 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006341 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006342
John McCalla93c9342009-12-07 02:54:59 +00006343 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006344 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006346
John McCall5ab75172009-11-04 07:28:41 +00006347 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006348 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006350 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6351 E->getKind(),
6352 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353 }
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006355 // C++0x [expr.sizeof]p1:
6356 // The operand is either an expression, which is an unevaluated operand
6357 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006358 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6359 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006360
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006361 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6362 if (SubExpr.isInvalid())
6363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006365 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6366 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006368 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6369 E->getOperatorLoc(),
6370 E->getKind(),
6371 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372}
Mike Stump1eb44332009-09-09 15:08:12 +00006373
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006375ExprResult
John McCall454feb92009-12-08 09:21:05 +00006376TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006377 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006379 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006380
John McCall60d7b3a2010-08-24 06:29:42 +00006381 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006384
6385
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386 if (!getDerived().AlwaysRebuild() &&
6387 LHS.get() == E->getLHS() &&
6388 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006389 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006390
John McCall9ae2f072010-08-23 23:25:46 +00006391 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006393 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 E->getRBracketLoc());
6395}
Mike Stump1eb44332009-09-09 15:08:12 +00006396
6397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006398ExprResult
John McCall454feb92009-12-08 09:21:05 +00006399TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006401 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006403 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404
6405 // Transform arguments.
6406 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006407 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006408 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006409 &ArgChanged))
6410 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006411
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412 if (!getDerived().AlwaysRebuild() &&
6413 Callee.get() == E->getCallee() &&
6414 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006415 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006416
Douglas Gregorb98b1992009-08-11 05:31:07 +00006417 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006418 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006420 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006421 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422 E->getRParenLoc());
6423}
Mike Stump1eb44332009-09-09 15:08:12 +00006424
6425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006426ExprResult
John McCall454feb92009-12-08 09:21:05 +00006427TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006428 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregor40d96a62011-02-28 21:54:11 +00006432 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006433 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006434 QualifierLoc
6435 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006436
Douglas Gregor40d96a62011-02-28 21:54:11 +00006437 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006438 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006439 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006440 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Eli Friedmanf595cc42009-12-04 06:40:45 +00006442 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006443 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6444 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006446 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006447
John McCall6bb80172010-03-30 21:47:33 +00006448 NamedDecl *FoundDecl = E->getFoundDecl();
6449 if (FoundDecl == E->getMemberDecl()) {
6450 FoundDecl = Member;
6451 } else {
6452 FoundDecl = cast_or_null<NamedDecl>(
6453 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6454 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006455 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006456 }
6457
Douglas Gregorb98b1992009-08-11 05:31:07 +00006458 if (!getDerived().AlwaysRebuild() &&
6459 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006460 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006461 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006462 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006463 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006464
Anders Carlsson1f240322009-12-22 05:24:09 +00006465 // Mark it referenced in the new context regardless.
6466 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006467 SemaRef.MarkMemberReferenced(E);
6468
John McCall3fa5cae2010-10-26 07:05:15 +00006469 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006470 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471
John McCalld5532b62009-11-23 01:53:49 +00006472 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006473 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006474 TransArgs.setLAngleLoc(E->getLAngleLoc());
6475 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006476 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6477 E->getNumTemplateArgs(),
6478 TransArgs))
6479 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006480 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006481
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 // FIXME: Bogus source location for the operator
6483 SourceLocation FakeOperatorLoc
6484 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6485
John McCallc2233c52010-01-15 08:34:02 +00006486 // FIXME: to do this check properly, we will need to preserve the
6487 // first-qualifier-in-scope here, just in case we had a dependent
6488 // base (and therefore couldn't do the check) and a
6489 // nested-name-qualifier (and therefore could do the lookup).
6490 NamedDecl *FirstQualifierInScope = 0;
6491
John McCall9ae2f072010-08-23 23:25:46 +00006492 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006494 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006495 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006496 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006497 Member,
John McCall6bb80172010-03-30 21:47:33 +00006498 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006499 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006500 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006501 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502}
Mike Stump1eb44332009-09-09 15:08:12 +00006503
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006505ExprResult
John McCall454feb92009-12-08 09:21:05 +00006506TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006507 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006510
John McCall60d7b3a2010-08-24 06:29:42 +00006511 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006513 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006514
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 if (!getDerived().AlwaysRebuild() &&
6516 LHS.get() == E->getLHS() &&
6517 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006518 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006519
Lang Hamesbe9af122012-10-02 04:45:10 +00006520 Sema::FPContractStateRAII FPContractState(getSema());
6521 getSema().FPFeatures.fp_contract = E->isFPContractable();
6522
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006524 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525}
6526
Mike Stump1eb44332009-09-09 15:08:12 +00006527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006528ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006530 CompoundAssignOperator *E) {
6531 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532}
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006535ExprResult TreeTransform<Derived>::
6536TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6537 // Just rebuild the common and RHS expressions and see whether we
6538 // get any changes.
6539
6540 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6541 if (commonExpr.isInvalid())
6542 return ExprError();
6543
6544 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6545 if (rhs.isInvalid())
6546 return ExprError();
6547
6548 if (!getDerived().AlwaysRebuild() &&
6549 commonExpr.get() == e->getCommon() &&
6550 rhs.get() == e->getFalseExpr())
6551 return SemaRef.Owned(e);
6552
6553 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6554 e->getQuestionLoc(),
6555 0,
6556 e->getColonLoc(),
6557 rhs.get());
6558}
6559
6560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006561ExprResult
John McCall454feb92009-12-08 09:21:05 +00006562TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006563 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006564 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006565 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006566
John McCall60d7b3a2010-08-24 06:29:42 +00006567 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006569 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006570
John McCall60d7b3a2010-08-24 06:29:42 +00006571 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006573 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 if (!getDerived().AlwaysRebuild() &&
6576 Cond.get() == E->getCond() &&
6577 LHS.get() == E->getLHS() &&
6578 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006579 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006580
John McCall9ae2f072010-08-23 23:25:46 +00006581 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006582 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006583 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006584 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006585 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586}
Mike Stump1eb44332009-09-09 15:08:12 +00006587
6588template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006589ExprResult
John McCall454feb92009-12-08 09:21:05 +00006590TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006591 // Implicit casts are eliminated during transformation, since they
6592 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006593 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594}
Mike Stump1eb44332009-09-09 15:08:12 +00006595
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006597ExprResult
John McCall454feb92009-12-08 09:21:05 +00006598TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006599 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6600 if (!Type)
6601 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006602
John McCall60d7b3a2010-08-24 06:29:42 +00006603 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006604 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006609 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006611 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006612
John McCall9d125032010-01-15 18:39:57 +00006613 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006614 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006616 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617}
Mike Stump1eb44332009-09-09 15:08:12 +00006618
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006620ExprResult
John McCall454feb92009-12-08 09:21:05 +00006621TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006622 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6623 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6624 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006625 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006626
John McCall60d7b3a2010-08-24 06:29:42 +00006627 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006632 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006634 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635
John McCall1d7d8d62010-01-19 22:33:45 +00006636 // Note: the expression type doesn't necessarily match the
6637 // type-as-written, but that's okay, because it should always be
6638 // derivable from the initializer.
6639
John McCall42f56b52010-01-18 19:35:47 +00006640 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006642 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643}
Mike Stump1eb44332009-09-09 15:08:12 +00006644
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006646ExprResult
John McCall454feb92009-12-08 09:21:05 +00006647TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006648 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006650 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 if (!getDerived().AlwaysRebuild() &&
6653 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006654 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006655
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006657 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006659 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 E->getAccessorLoc(),
6661 E->getAccessor());
6662}
Mike Stump1eb44332009-09-09 15:08:12 +00006663
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006665ExprResult
John McCall454feb92009-12-08 09:21:05 +00006666TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006669 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006670 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006671 Inits, &InitChanged))
6672 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006673
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006675 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006677 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006678 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679}
Mike Stump1eb44332009-09-09 15:08:12 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006682ExprResult
John McCall454feb92009-12-08 09:21:05 +00006683TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregor43959a92009-08-20 07:17:43 +00006686 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006687 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006689 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006690
Douglas Gregor43959a92009-08-20 07:17:43 +00006691 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006692 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 bool ExprChanged = false;
6694 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6695 DEnd = E->designators_end();
6696 D != DEnd; ++D) {
6697 if (D->isFieldDesignator()) {
6698 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6699 D->getDotLoc(),
6700 D->getFieldLoc()));
6701 continue;
6702 }
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006705 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006707 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006708
6709 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6713 ArrayExprs.push_back(Index.release());
6714 continue;
6715 }
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006718 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6720 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006721 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006722
John McCall60d7b3a2010-08-24 06:29:42 +00006723 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006726
6727 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728 End.get(),
6729 D->getLBracketLoc(),
6730 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6733 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 ArrayExprs.push_back(Start.release());
6736 ArrayExprs.push_back(End.release());
6737 }
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 if (!getDerived().AlwaysRebuild() &&
6740 Init.get() == E->getInit() &&
6741 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006742 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006744 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006746 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747}
Mike Stump1eb44332009-09-09 15:08:12 +00006748
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006750ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006752 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006753 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006754
Douglas Gregor5557b252009-10-28 00:29:27 +00006755 // FIXME: Will we ever have proper type location here? Will we actually
6756 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 QualType T = getDerived().TransformType(E->getType());
6758 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006760
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761 if (!getDerived().AlwaysRebuild() &&
6762 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006763 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006764
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 return getDerived().RebuildImplicitValueInitExpr(T);
6766}
Mike Stump1eb44332009-09-09 15:08:12 +00006767
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006769ExprResult
John McCall454feb92009-12-08 09:21:05 +00006770TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006771 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6772 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006773 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006774
John McCall60d7b3a2010-08-24 06:29:42 +00006775 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006777 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006778
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006780 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006782 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006783
John McCall9ae2f072010-08-23 23:25:46 +00006784 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006785 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786}
6787
6788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006789ExprResult
John McCall454feb92009-12-08 09:21:05 +00006790TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006792 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006793 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6794 &ArgumentChanged))
6795 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006796
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006798 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 E->getRParenLoc());
6800}
Mike Stump1eb44332009-09-09 15:08:12 +00006801
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802/// \brief Transform an address-of-label expression.
6803///
6804/// By default, the transformation of an address-of-label expression always
6805/// rebuilds the expression, so that the label identifier can be resolved to
6806/// the corresponding label statement by semantic analysis.
6807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006808ExprResult
John McCall454feb92009-12-08 09:21:05 +00006809TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006810 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6811 E->getLabel());
6812 if (!LD)
6813 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006816 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817}
Mike Stump1eb44332009-09-09 15:08:12 +00006818
6819template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006820ExprResult
John McCall454feb92009-12-08 09:21:05 +00006821TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006822 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006823 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006825 if (SubStmt.isInvalid()) {
6826 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006828 }
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006831 SubStmt.get() == E->getSubStmt()) {
6832 // Calling this an 'error' is unintuitive, but it does the right thing.
6833 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006834 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006835 }
Mike Stump1eb44332009-09-09 15:08:12 +00006836
6837 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006838 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 E->getRParenLoc());
6840}
Mike Stump1eb44332009-09-09 15:08:12 +00006841
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006843ExprResult
John McCall454feb92009-12-08 09:21:05 +00006844TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006845 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006847 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006848
John McCall60d7b3a2010-08-24 06:29:42 +00006849 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006851 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006852
John McCall60d7b3a2010-08-24 06:29:42 +00006853 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006854 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (!getDerived().AlwaysRebuild() &&
6858 Cond.get() == E->getCond() &&
6859 LHS.get() == E->getLHS() &&
6860 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006861 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006862
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006864 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 E->getRParenLoc());
6866}
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006869ExprResult
John McCall454feb92009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006871 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872}
6873
6874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006875ExprResult
John McCall454feb92009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006877 switch (E->getOperator()) {
6878 case OO_New:
6879 case OO_Delete:
6880 case OO_Array_New:
6881 case OO_Array_Delete:
6882 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006883
Douglas Gregor668d6d92009-12-13 20:44:55 +00006884 case OO_Call: {
6885 // This is a call to an object's operator().
6886 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6887
6888 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006889 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006890 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006891 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006892
6893 // FIXME: Poor location information
6894 SourceLocation FakeLParenLoc
6895 = SemaRef.PP.getLocForEndOfToken(
6896 static_cast<Expr *>(Object.get())->getLocEnd());
6897
6898 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006899 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006900 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006901 Args))
6902 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006903
John McCall9ae2f072010-08-23 23:25:46 +00006904 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006905 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006906 E->getLocEnd());
6907 }
6908
6909#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6910 case OO_##Name:
6911#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6912#include "clang/Basic/OperatorKinds.def"
6913 case OO_Subscript:
6914 // Handled below.
6915 break;
6916
6917 case OO_Conditional:
6918 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006919
6920 case OO_None:
6921 case NUM_OVERLOADED_OPERATORS:
6922 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006923 }
6924
John McCall60d7b3a2010-08-24 06:29:42 +00006925 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006927 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006928
Richard Smithefeeccf2012-10-21 03:28:35 +00006929 ExprResult First;
6930 if (E->getOperator() == OO_Amp)
6931 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6932 else
6933 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006935 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936
John McCall60d7b3a2010-08-24 06:29:42 +00006937 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938 if (E->getNumArgs() == 2) {
6939 Second = getDerived().TransformExpr(E->getArg(1));
6940 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006941 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942 }
Mike Stump1eb44332009-09-09 15:08:12 +00006943
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 if (!getDerived().AlwaysRebuild() &&
6945 Callee.get() == E->getCallee() &&
6946 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006947 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006948 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006949
Lang Hamesbe9af122012-10-02 04:45:10 +00006950 Sema::FPContractStateRAII FPContractState(getSema());
6951 getSema().FPFeatures.fp_contract = E->isFPContractable();
6952
Douglas Gregorb98b1992009-08-11 05:31:07 +00006953 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6954 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006955 Callee.get(),
6956 First.get(),
6957 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006958}
Mike Stump1eb44332009-09-09 15:08:12 +00006959
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006961ExprResult
John McCall454feb92009-12-08 09:21:05 +00006962TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6963 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006964}
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006968TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6969 // Transform the callee.
6970 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6971 if (Callee.isInvalid())
6972 return ExprError();
6973
6974 // Transform exec config.
6975 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6976 if (EC.isInvalid())
6977 return ExprError();
6978
6979 // Transform arguments.
6980 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006981 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006982 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006983 &ArgChanged))
6984 return ExprError();
6985
6986 if (!getDerived().AlwaysRebuild() &&
6987 Callee.get() == E->getCallee() &&
6988 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006989 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006990
6991 // FIXME: Wrong source location information for the '('.
6992 SourceLocation FakeLParenLoc
6993 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6994 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006995 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006996 E->getRParenLoc(), EC.get());
6997}
6998
6999template<typename Derived>
7000ExprResult
John McCall454feb92009-12-08 09:21:05 +00007001TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007002 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7003 if (!Type)
7004 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007005
John McCall60d7b3a2010-08-24 06:29:42 +00007006 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007007 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007009 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007010
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007012 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007014 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007016 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007017 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007018 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007019 E->getAngleBrackets().getEnd(),
7020 // FIXME. this should be '(' location
7021 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007022 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007023 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024}
Mike Stump1eb44332009-09-09 15:08:12 +00007025
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007027ExprResult
John McCall454feb92009-12-08 09:21:05 +00007028TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7029 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030}
Mike Stump1eb44332009-09-09 15:08:12 +00007031
7032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007033ExprResult
John McCall454feb92009-12-08 09:21:05 +00007034TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7035 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007036}
7037
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007039ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007041 CXXReinterpretCastExpr *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
John McCall454feb92009-12-08 09:21:05 +00007047TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7048 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049}
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007052ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007054 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007055 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7056 if (!Type)
7057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007058
John McCall60d7b3a2010-08-24 06:29:42 +00007059 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007060 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007062 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007065 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007067 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007069 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007071 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 E->getRParenLoc());
7073}
Mike Stump1eb44332009-09-09 15:08:12 +00007074
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007076ExprResult
John McCall454feb92009-12-08 09:21:05 +00007077TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007079 TypeSourceInfo *TInfo
7080 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7081 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007082 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007085 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007086 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007087
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007088 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7089 E->getLocStart(),
7090 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091 E->getLocEnd());
7092 }
Mike Stump1eb44332009-09-09 15:08:12 +00007093
Eli Friedmanef331b72012-01-20 01:26:23 +00007094 // We don't know whether the subexpression is potentially evaluated until
7095 // after we perform semantic analysis. We speculatively assume it is
7096 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007097 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007098 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7099 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007100
John McCall60d7b3a2010-08-24 06:29:42 +00007101 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007103 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007104
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105 if (!getDerived().AlwaysRebuild() &&
7106 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007108
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007109 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7110 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007111 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 E->getLocEnd());
7113}
7114
7115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007116ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007117TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7118 if (E->isTypeOperand()) {
7119 TypeSourceInfo *TInfo
7120 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7121 if (!TInfo)
7122 return ExprError();
7123
7124 if (!getDerived().AlwaysRebuild() &&
7125 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007126 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007127
Douglas Gregor3c52a212011-03-06 17:40:41 +00007128 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007129 E->getLocStart(),
7130 TInfo,
7131 E->getLocEnd());
7132 }
7133
Francois Pichet01b7c302010-09-08 12:20:18 +00007134 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7135
7136 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7137 if (SubExpr.isInvalid())
7138 return ExprError();
7139
7140 if (!getDerived().AlwaysRebuild() &&
7141 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007142 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007143
7144 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7145 E->getLocStart(),
7146 SubExpr.get(),
7147 E->getLocEnd());
7148}
7149
7150template<typename Derived>
7151ExprResult
John McCall454feb92009-12-08 09:21:05 +00007152TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007153 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154}
Mike Stump1eb44332009-09-09 15:08:12 +00007155
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007157ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007159 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007160 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161}
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007164ExprResult
John McCall454feb92009-12-08 09:21:05 +00007165TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007166 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007167 QualType T;
7168 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7169 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007170 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007171 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007172 getSema().Context.getRecordType(Record));
7173 } else {
7174 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7175 "this in the wrong scope?");
7176 return ExprError();
7177 }
Mike Stump1eb44332009-09-09 15:08:12 +00007178
Douglas Gregorec79d872012-02-24 17:41:38 +00007179 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7180 // Make sure that we capture 'this'.
7181 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007182 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007183 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007184
Douglas Gregor828a1972010-01-07 23:12:05 +00007185 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186}
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007189ExprResult
John McCall454feb92009-12-08 09:21:05 +00007190TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007191 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007192 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007193 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195 if (!getDerived().AlwaysRebuild() &&
7196 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007197 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198
Douglas Gregorbca01b42011-07-06 22:04:06 +00007199 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7200 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201}
Mike Stump1eb44332009-09-09 15:08:12 +00007202
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007204ExprResult
John McCall454feb92009-12-08 09:21:05 +00007205TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007206 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007207 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7208 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007210 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007211
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007212 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007213 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007215
Douglas Gregor036aed12009-12-23 23:03:06 +00007216 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217}
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007220ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007221TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7222 CXXScalarValueInitExpr *E) {
7223 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7224 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007225 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007226
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007228 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007229 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007230
Chad Rosier4a9d7952012-08-08 18:46:20 +00007231 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007232 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007233 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234}
Mike Stump1eb44332009-09-09 15:08:12 +00007235
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007237ExprResult
John McCall454feb92009-12-08 09:21:05 +00007238TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007239 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007240 TypeSourceInfo *AllocTypeInfo
7241 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7242 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007244
Douglas Gregorb98b1992009-08-11 05:31:07 +00007245 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007246 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007249
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250 // Transform the placement arguments (if any).
7251 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007252 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007253 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007254 E->getNumPlacementArgs(), true,
7255 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007256 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007258 // Transform the initializer (if any).
7259 Expr *OldInit = E->getInitializer();
7260 ExprResult NewInit;
7261 if (OldInit)
7262 NewInit = getDerived().TransformExpr(OldInit);
7263 if (NewInit.isInvalid())
7264 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007265
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007266 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007267 FunctionDecl *OperatorNew = 0;
7268 if (E->getOperatorNew()) {
7269 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007270 getDerived().TransformDecl(E->getLocStart(),
7271 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007272 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007273 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 }
7275
7276 FunctionDecl *OperatorDelete = 0;
7277 if (E->getOperatorDelete()) {
7278 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007279 getDerived().TransformDecl(E->getLocStart(),
7280 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007281 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007282 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007283 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007284
Douglas Gregorb98b1992009-08-11 05:31:07 +00007285 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007286 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007288 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007289 OperatorNew == E->getOperatorNew() &&
7290 OperatorDelete == E->getOperatorDelete() &&
7291 !ArgumentChanged) {
7292 // Mark any declarations we need as referenced.
7293 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007294 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007295 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007296 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007297 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007298
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007299 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007300 QualType ElementType
7301 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7302 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7303 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7304 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007305 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007306 }
7307 }
7308 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007309
John McCall3fa5cae2010-10-26 07:05:15 +00007310 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007311 }
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007313 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007314 if (!ArraySize.get()) {
7315 // If no array size was specified, but the new expression was
7316 // instantiated with an array type (e.g., "new T" where T is
7317 // instantiated with "int[4]"), extract the outer bound from the
7318 // array type as our array size. We do this with constant and
7319 // dependently-sized array types.
7320 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7321 if (!ArrayT) {
7322 // Do nothing
7323 } else if (const ConstantArrayType *ConsArrayT
7324 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007325 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007326 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007327 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007328 SemaRef.Context.getSizeType(),
7329 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007330 AllocType = ConsArrayT->getElementType();
7331 } else if (const DependentSizedArrayType *DepArrayT
7332 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7333 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007334 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007335 AllocType = DepArrayT->getElementType();
7336 }
7337 }
7338 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007339
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7341 E->isGlobalNew(),
7342 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007343 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007344 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007345 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007347 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007348 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007349 E->getDirectInitRange(),
7350 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351}
Mike Stump1eb44332009-09-09 15:08:12 +00007352
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007354ExprResult
John McCall454feb92009-12-08 09:21:05 +00007355TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007356 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007359
Douglas Gregor1af74512010-02-26 00:38:10 +00007360 // Transform the delete operator, if known.
7361 FunctionDecl *OperatorDelete = 0;
7362 if (E->getOperatorDelete()) {
7363 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007364 getDerived().TransformDecl(E->getLocStart(),
7365 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007366 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007367 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007369
Douglas Gregorb98b1992009-08-11 05:31:07 +00007370 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007371 Operand.get() == E->getArgument() &&
7372 OperatorDelete == E->getOperatorDelete()) {
7373 // Mark any declarations we need as referenced.
7374 // FIXME: instantiation-specific.
7375 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007376 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007377
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007378 if (!E->getArgument()->isTypeDependent()) {
7379 QualType Destroyed = SemaRef.Context.getBaseElementType(
7380 E->getDestroyedType());
7381 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7382 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007383 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007384 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007385 }
7386 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007387
John McCall3fa5cae2010-10-26 07:05:15 +00007388 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007389 }
Mike Stump1eb44332009-09-09 15:08:12 +00007390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7392 E->isGlobalDelete(),
7393 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007394 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395}
Mike Stump1eb44332009-09-09 15:08:12 +00007396
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007398ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007399TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007400 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007401 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007402 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007403 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007404
John McCallb3d87482010-08-24 05:47:05 +00007405 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007406 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007407 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007408 E->getOperatorLoc(),
7409 E->isArrow()? tok::arrow : tok::period,
7410 ObjectTypePtr,
7411 MayBePseudoDestructor);
7412 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007413 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007414
John McCallb3d87482010-08-24 05:47:05 +00007415 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007416 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7417 if (QualifierLoc) {
7418 QualifierLoc
7419 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7420 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007421 return ExprError();
7422 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007423 CXXScopeSpec SS;
7424 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007425
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007426 PseudoDestructorTypeStorage Destroyed;
7427 if (E->getDestroyedTypeInfo()) {
7428 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007429 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007430 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007431 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007432 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007433 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007434 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007435 // We aren't likely to be able to resolve the identifier down to a type
7436 // now anyway, so just retain the identifier.
7437 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7438 E->getDestroyedTypeLoc());
7439 } else {
7440 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007441 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007442 *E->getDestroyedTypeIdentifier(),
7443 E->getDestroyedTypeLoc(),
7444 /*Scope=*/0,
7445 SS, ObjectTypePtr,
7446 false);
7447 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007448 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007449
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007450 Destroyed
7451 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7452 E->getDestroyedTypeLoc());
7453 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007454
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007455 TypeSourceInfo *ScopeTypeInfo = 0;
7456 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007457 CXXScopeSpec EmptySS;
7458 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7459 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007460 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007461 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007462 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007463
John McCall9ae2f072010-08-23 23:25:46 +00007464 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007465 E->getOperatorLoc(),
7466 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007467 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007468 ScopeTypeInfo,
7469 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007470 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007471 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007472}
Mike Stump1eb44332009-09-09 15:08:12 +00007473
Douglas Gregora71d8192009-09-04 17:36:40 +00007474template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007475ExprResult
John McCallba135432009-11-21 08:51:07 +00007476TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007477 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007478 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7479 Sema::LookupOrdinaryName);
7480
7481 // Transform all the decls.
7482 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7483 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007484 NamedDecl *InstD = static_cast<NamedDecl*>(
7485 getDerived().TransformDecl(Old->getNameLoc(),
7486 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007487 if (!InstD) {
7488 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7489 // This can happen because of dependent hiding.
7490 if (isa<UsingShadowDecl>(*I))
7491 continue;
7492 else
John McCallf312b1e2010-08-26 23:41:50 +00007493 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007494 }
John McCallf7a1a742009-11-24 19:00:30 +00007495
7496 // Expand using declarations.
7497 if (isa<UsingDecl>(InstD)) {
7498 UsingDecl *UD = cast<UsingDecl>(InstD);
7499 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7500 E = UD->shadow_end(); I != E; ++I)
7501 R.addDecl(*I);
7502 continue;
7503 }
7504
7505 R.addDecl(InstD);
7506 }
7507
7508 // Resolve a kind, but don't do any further analysis. If it's
7509 // ambiguous, the callee needs to deal with it.
7510 R.resolveKind();
7511
7512 // Rebuild the nested-name qualifier, if present.
7513 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007514 if (Old->getQualifierLoc()) {
7515 NestedNameSpecifierLoc QualifierLoc
7516 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7517 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007518 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007519
Douglas Gregor4c9be892011-02-28 20:01:57 +00007520 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007521 }
7522
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007523 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007524 CXXRecordDecl *NamingClass
7525 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7526 Old->getNameLoc(),
7527 Old->getNamingClass()));
7528 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007529 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007530
Douglas Gregor66c45152010-04-27 16:10:10 +00007531 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007532 }
7533
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007534 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7535
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007536 // If we have neither explicit template arguments, nor the template keyword,
7537 // it's a normal declaration name.
7538 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007539 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7540
7541 // If we have template arguments, rebuild them, then rebuild the
7542 // templateid expression.
7543 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007544 if (Old->hasExplicitTemplateArgs() &&
7545 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007546 Old->getNumTemplateArgs(),
7547 TransArgs))
7548 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007549
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007550 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007551 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007552}
Mike Stump1eb44332009-09-09 15:08:12 +00007553
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007555ExprResult
John McCall454feb92009-12-08 09:21:05 +00007556TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007557 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7558 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007560
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007562 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007563 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007564
Mike Stump1eb44332009-09-09 15:08:12 +00007565 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007566 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007567 T,
7568 E->getLocEnd());
7569}
Mike Stump1eb44332009-09-09 15:08:12 +00007570
Douglas Gregorb98b1992009-08-11 05:31:07 +00007571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007572ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007573TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7574 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7575 if (!LhsT)
7576 return ExprError();
7577
7578 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7579 if (!RhsT)
7580 return ExprError();
7581
7582 if (!getDerived().AlwaysRebuild() &&
7583 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7584 return SemaRef.Owned(E);
7585
7586 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7587 E->getLocStart(),
7588 LhsT, RhsT,
7589 E->getLocEnd());
7590}
7591
7592template<typename Derived>
7593ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007594TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7595 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007596 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007597 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7598 TypeSourceInfo *From = E->getArg(I);
7599 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007600 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007601 TypeLocBuilder TLB;
7602 TLB.reserve(FromTL.getFullDataSize());
7603 QualType To = getDerived().TransformType(TLB, FromTL);
7604 if (To.isNull())
7605 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007606
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007607 if (To == From->getType())
7608 Args.push_back(From);
7609 else {
7610 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7611 ArgChanged = true;
7612 }
7613 continue;
7614 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007615
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007616 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007617
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007618 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007619 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007620 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7621 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7622 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007623
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007624 // Determine whether the set of unexpanded parameter packs can and should
7625 // be expanded.
7626 bool Expand = true;
7627 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007628 Optional<unsigned> OrigNumExpansions =
7629 ExpansionTL.getTypePtr()->getNumExpansions();
7630 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007631 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7632 PatternTL.getSourceRange(),
7633 Unexpanded,
7634 Expand, RetainExpansion,
7635 NumExpansions))
7636 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007637
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007638 if (!Expand) {
7639 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007641 // expansion.
7642 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007644 TypeLocBuilder TLB;
7645 TLB.reserve(From->getTypeLoc().getFullDataSize());
7646
7647 QualType To = getDerived().TransformType(TLB, PatternTL);
7648 if (To.isNull())
7649 return ExprError();
7650
Chad Rosier4a9d7952012-08-08 18:46:20 +00007651 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007652 PatternTL.getSourceRange(),
7653 ExpansionTL.getEllipsisLoc(),
7654 NumExpansions);
7655 if (To.isNull())
7656 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007657
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007658 PackExpansionTypeLoc ToExpansionTL
7659 = TLB.push<PackExpansionTypeLoc>(To);
7660 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7661 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7662 continue;
7663 }
7664
7665 // Expand the pack expansion by substituting for each argument in the
7666 // pack(s).
7667 for (unsigned I = 0; I != *NumExpansions; ++I) {
7668 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7669 TypeLocBuilder TLB;
7670 TLB.reserve(PatternTL.getFullDataSize());
7671 QualType To = getDerived().TransformType(TLB, PatternTL);
7672 if (To.isNull())
7673 return ExprError();
7674
7675 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007677
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007678 if (!RetainExpansion)
7679 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007680
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007681 // If we're supposed to retain a pack expansion, do so by temporarily
7682 // forgetting the partially-substituted parameter pack.
7683 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7684
7685 TypeLocBuilder TLB;
7686 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007687
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007688 QualType To = getDerived().TransformType(TLB, PatternTL);
7689 if (To.isNull())
7690 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007691
7692 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007693 PatternTL.getSourceRange(),
7694 ExpansionTL.getEllipsisLoc(),
7695 NumExpansions);
7696 if (To.isNull())
7697 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007698
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007699 PackExpansionTypeLoc ToExpansionTL
7700 = TLB.push<PackExpansionTypeLoc>(To);
7701 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7702 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7703 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007704
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007705 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7706 return SemaRef.Owned(E);
7707
7708 return getDerived().RebuildTypeTrait(E->getTrait(),
7709 E->getLocStart(),
7710 Args,
7711 E->getLocEnd());
7712}
7713
7714template<typename Derived>
7715ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007716TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7717 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7718 if (!T)
7719 return ExprError();
7720
7721 if (!getDerived().AlwaysRebuild() &&
7722 T == E->getQueriedTypeSourceInfo())
7723 return SemaRef.Owned(E);
7724
7725 ExprResult SubExpr;
7726 {
7727 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7728 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7729 if (SubExpr.isInvalid())
7730 return ExprError();
7731
7732 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7733 return SemaRef.Owned(E);
7734 }
7735
7736 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7737 E->getLocStart(),
7738 T,
7739 SubExpr.get(),
7740 E->getLocEnd());
7741}
7742
7743template<typename Derived>
7744ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007745TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7746 ExprResult SubExpr;
7747 {
7748 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7749 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7750 if (SubExpr.isInvalid())
7751 return ExprError();
7752
7753 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7754 return SemaRef.Owned(E);
7755 }
7756
7757 return getDerived().RebuildExpressionTrait(
7758 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7759}
7760
7761template<typename Derived>
7762ExprResult
John McCall865d4472009-11-19 22:55:06 +00007763TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007764 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007765 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7766}
7767
7768template<typename Derived>
7769ExprResult
7770TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7771 DependentScopeDeclRefExpr *E,
7772 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007773 NestedNameSpecifierLoc QualifierLoc
7774 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7775 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007776 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007777 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007778
John McCall43fed0d2010-11-12 08:19:04 +00007779 // TODO: If this is a conversion-function-id, verify that the
7780 // destination type name (if present) resolves the same way after
7781 // instantiation as it did in the local scope.
7782
Abramo Bagnara25777432010-08-11 22:01:17 +00007783 DeclarationNameInfo NameInfo
7784 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7785 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007786 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007787
John McCallf7a1a742009-11-24 19:00:30 +00007788 if (!E->hasExplicitTemplateArgs()) {
7789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007790 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007791 // Note: it is sufficient to compare the Name component of NameInfo:
7792 // if name has not changed, DNLoc has not changed either.
7793 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007794 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +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 /*TemplateArgs*/ 0,
7800 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007801 }
John McCalld5532b62009-11-23 01:53:49 +00007802
7803 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007804 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7805 E->getNumTemplateArgs(),
7806 TransArgs))
7807 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007808
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007809 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007810 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007811 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007812 &TransArgs,
7813 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007814}
7815
7816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007817ExprResult
John McCall454feb92009-12-08 09:21:05 +00007818TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007819 // CXXConstructExprs other than for list-initialization and
7820 // CXXTemporaryObjectExpr are always implicit, so when we have
7821 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007822 if ((E->getNumArgs() == 1 ||
7823 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007824 (!getDerived().DropCallArgument(E->getArg(0))) &&
7825 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007826 return getDerived().TransformExpr(E->getArg(0));
7827
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7829
7830 QualType T = getDerived().TransformType(E->getType());
7831 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007832 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007833
7834 CXXConstructorDecl *Constructor
7835 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007836 getDerived().TransformDecl(E->getLocStart(),
7837 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007838 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007839 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007840
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007842 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007843 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007844 &ArgumentChanged))
7845 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007846
Douglas Gregorb98b1992009-08-11 05:31:07 +00007847 if (!getDerived().AlwaysRebuild() &&
7848 T == E->getType() &&
7849 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007850 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007851 // Mark the constructor as referenced.
7852 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007853 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007854 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007855 }
Mike Stump1eb44332009-09-09 15:08:12 +00007856
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007857 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7858 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007859 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007860 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007861 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007862 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007863 E->getConstructionKind(),
7864 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865}
Mike Stump1eb44332009-09-09 15:08:12 +00007866
Douglas Gregorb98b1992009-08-11 05:31:07 +00007867/// \brief Transform a C++ temporary-binding expression.
7868///
Douglas Gregor51326552009-12-24 18:51:59 +00007869/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7870/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007872ExprResult
John McCall454feb92009-12-08 09:21:05 +00007873TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007874 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875}
Mike Stump1eb44332009-09-09 15:08:12 +00007876
John McCall4765fa02010-12-06 08:20:24 +00007877/// \brief Transform a C++ expression that contains cleanups that should
7878/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007879///
John McCall4765fa02010-12-06 08:20:24 +00007880/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007881/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007882template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007883ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007884TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007885 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007886}
Mike Stump1eb44332009-09-09 15:08:12 +00007887
Douglas Gregorb98b1992009-08-11 05:31:07 +00007888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007889ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007891 CXXTemporaryObjectExpr *E) {
7892 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7893 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007895
Douglas Gregorb98b1992009-08-11 05:31:07 +00007896 CXXConstructorDecl *Constructor
7897 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007898 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007899 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007900 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007902
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007904 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007905 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007906 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007907 &ArgumentChanged))
7908 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007909
Douglas Gregorb98b1992009-08-11 05:31:07 +00007910 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007911 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007913 !ArgumentChanged) {
7914 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007915 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007916 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007917 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007918
Richard Smithc83c2302012-12-19 01:39:02 +00007919 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007920 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7921 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007922 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007923 E->getLocEnd());
7924}
Mike Stump1eb44332009-09-09 15:08:12 +00007925
Douglas Gregorb98b1992009-08-11 05:31:07 +00007926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007927ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007928TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007929 // Transform the type of the lambda parameters and start the definition of
7930 // the lambda itself.
7931 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007932 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007933 if (!MethodTy)
7934 return ExprError();
7935
Eli Friedman8da8a662012-09-19 01:18:11 +00007936 // Create the local class that will describe the lambda.
7937 CXXRecordDecl *Class
7938 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7939 MethodTy,
7940 /*KnownDependent=*/false);
7941 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7942
Douglas Gregorc6889e72012-02-14 22:28:59 +00007943 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007944 SmallVector<QualType, 4> ParamTypes;
7945 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007946 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7947 E->getCallOperator()->param_begin(),
7948 E->getCallOperator()->param_size(),
7949 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007950 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007951
Douglas Gregordfca6f52012-02-13 22:00:16 +00007952 // Build the call operator.
7953 CXXMethodDecl *CallOperator
7954 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007955 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007956 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007957 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007958 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007959
Richard Smith612409e2012-07-25 03:56:55 +00007960 return getDerived().TransformLambdaScope(E, CallOperator);
7961}
7962
7963template<typename Derived>
7964ExprResult
7965TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7966 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007967 // Introduce the context of the call operator.
7968 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7969
Douglas Gregordfca6f52012-02-13 22:00:16 +00007970 // Enter the scope of the lambda.
7971 sema::LambdaScopeInfo *LSI
7972 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7973 E->getCaptureDefault(),
7974 E->hasExplicitParameters(),
7975 E->hasExplicitResultType(),
7976 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007977
Douglas Gregordfca6f52012-02-13 22:00:16 +00007978 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007979 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007980 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007981 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007982 CEnd = E->capture_end();
7983 C != CEnd; ++C) {
7984 // When we hit the first implicit capture, tell Sema that we've finished
7985 // the list of explicit captures.
7986 if (!FinishedExplicitCaptures && C->isImplicit()) {
7987 getSema().finishLambdaExplicitCaptures(LSI);
7988 FinishedExplicitCaptures = true;
7989 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007990
Douglas Gregordfca6f52012-02-13 22:00:16 +00007991 // Capturing 'this' is trivial.
7992 if (C->capturesThis()) {
7993 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7994 continue;
7995 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007996
Douglas Gregora7365242012-02-14 19:27:52 +00007997 // Determine the capture kind for Sema.
7998 Sema::TryCaptureKind Kind
7999 = C->isImplicit()? Sema::TryCapture_Implicit
8000 : C->getCaptureKind() == LCK_ByCopy
8001 ? Sema::TryCapture_ExplicitByVal
8002 : Sema::TryCapture_ExplicitByRef;
8003 SourceLocation EllipsisLoc;
8004 if (C->isPackExpansion()) {
8005 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8006 bool ShouldExpand = false;
8007 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008008 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008009 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8010 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008011 Unexpanded,
8012 ShouldExpand, RetainExpansion,
8013 NumExpansions))
8014 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008015
Douglas Gregora7365242012-02-14 19:27:52 +00008016 if (ShouldExpand) {
8017 // The transform has determined that we should perform an expansion;
8018 // transform and capture each of the arguments.
8019 // expansion of the pattern. Do so.
8020 VarDecl *Pack = C->getCapturedVar();
8021 for (unsigned I = 0; I != *NumExpansions; ++I) {
8022 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8023 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008024 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008025 Pack));
8026 if (!CapturedVar) {
8027 Invalid = true;
8028 continue;
8029 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008030
Douglas Gregora7365242012-02-14 19:27:52 +00008031 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008032 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8033 }
Douglas Gregora7365242012-02-14 19:27:52 +00008034 continue;
8035 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008036
Douglas Gregora7365242012-02-14 19:27:52 +00008037 EllipsisLoc = C->getEllipsisLoc();
8038 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008039
Douglas Gregordfca6f52012-02-13 22:00:16 +00008040 // Transform the captured variable.
8041 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008043 C->getCapturedVar()));
8044 if (!CapturedVar) {
8045 Invalid = true;
8046 continue;
8047 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008048
Douglas Gregordfca6f52012-02-13 22:00:16 +00008049 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008050 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008051 }
8052 if (!FinishedExplicitCaptures)
8053 getSema().finishLambdaExplicitCaptures(LSI);
8054
Douglas Gregordfca6f52012-02-13 22:00:16 +00008055
8056 // Enter a new evaluation context to insulate the lambda from any
8057 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008058 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008059
8060 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008061 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008062 /*IsInstantiation=*/true);
8063 return ExprError();
8064 }
8065
8066 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008067 StmtResult Body = getDerived().TransformStmt(E->getBody());
8068 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008069 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008070 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008071 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008072 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008073
Chad Rosier4a9d7952012-08-08 18:46:20 +00008074 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008075 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008076}
8077
8078template<typename Derived>
8079ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008080TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008081 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008082 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8083 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008084 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008085
Douglas Gregorb98b1992009-08-11 05:31:07 +00008086 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008087 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008088 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008089 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008090 &ArgumentChanged))
8091 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008092
Douglas Gregorb98b1992009-08-11 05:31:07 +00008093 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008094 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008095 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008096 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008097
Douglas Gregorb98b1992009-08-11 05:31:07 +00008098 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008099 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008101 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008102 E->getRParenLoc());
8103}
Mike Stump1eb44332009-09-09 15:08:12 +00008104
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008106ExprResult
John McCall865d4472009-11-19 22:55:06 +00008107TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008108 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008109 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008110 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008111 Expr *OldBase;
8112 QualType BaseType;
8113 QualType ObjectType;
8114 if (!E->isImplicitAccess()) {
8115 OldBase = E->getBase();
8116 Base = getDerived().TransformExpr(OldBase);
8117 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008118 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008119
John McCallaa81e162009-12-01 22:10:20 +00008120 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008121 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008122 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008123 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008124 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008125 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008126 ObjectTy,
8127 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008128 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008129 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008130
John McCallb3d87482010-08-24 05:47:05 +00008131 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008132 BaseType = ((Expr*) Base.get())->getType();
8133 } else {
8134 OldBase = 0;
8135 BaseType = getDerived().TransformType(E->getBaseType());
8136 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8137 }
Mike Stump1eb44332009-09-09 15:08:12 +00008138
Douglas Gregor6cd21982009-10-20 05:58:46 +00008139 // Transform the first part of the nested-name-specifier that qualifies
8140 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008141 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008142 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008143 E->getFirstQualifierFoundInScope(),
8144 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008145
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008146 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008147 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008148 QualifierLoc
8149 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8150 ObjectType,
8151 FirstQualifierInScope);
8152 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008153 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008154 }
Mike Stump1eb44332009-09-09 15:08:12 +00008155
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008156 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8157
John McCall43fed0d2010-11-12 08:19:04 +00008158 // TODO: If this is a conversion-function-id, verify that the
8159 // destination type name (if present) resolves the same way after
8160 // instantiation as it did in the local scope.
8161
Abramo Bagnara25777432010-08-11 22:01:17 +00008162 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008163 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008164 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008166
John McCallaa81e162009-12-01 22:10:20 +00008167 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008168 // This is a reference to a member without an explicitly-specified
8169 // template argument list. Optimize for this common case.
8170 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008171 Base.get() == OldBase &&
8172 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008173 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008174 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008175 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008176 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008177
John McCall9ae2f072010-08-23 23:25:46 +00008178 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008179 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008180 E->isArrow(),
8181 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008182 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008183 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008184 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008185 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008186 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008187 }
8188
John McCalld5532b62009-11-23 01:53:49 +00008189 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008190 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8191 E->getNumTemplateArgs(),
8192 TransArgs))
8193 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008194
John McCall9ae2f072010-08-23 23:25:46 +00008195 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008196 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008197 E->isArrow(),
8198 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008199 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008200 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008201 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008202 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008203 &TransArgs);
8204}
8205
8206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008207ExprResult
John McCall454feb92009-12-08 09:21:05 +00008208TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008209 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008210 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008211 QualType BaseType;
8212 if (!Old->isImplicitAccess()) {
8213 Base = getDerived().TransformExpr(Old->getBase());
8214 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008215 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008216 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8217 Old->isArrow());
8218 if (Base.isInvalid())
8219 return ExprError();
8220 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008221 } else {
8222 BaseType = getDerived().TransformType(Old->getBaseType());
8223 }
John McCall129e2df2009-11-30 22:42:35 +00008224
Douglas Gregor4c9be892011-02-28 20:01:57 +00008225 NestedNameSpecifierLoc QualifierLoc;
8226 if (Old->getQualifierLoc()) {
8227 QualifierLoc
8228 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8229 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008230 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008231 }
8232
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008233 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8234
Abramo Bagnara25777432010-08-11 22:01:17 +00008235 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008236 Sema::LookupOrdinaryName);
8237
8238 // Transform all the decls.
8239 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8240 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008241 NamedDecl *InstD = static_cast<NamedDecl*>(
8242 getDerived().TransformDecl(Old->getMemberLoc(),
8243 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008244 if (!InstD) {
8245 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8246 // This can happen because of dependent hiding.
8247 if (isa<UsingShadowDecl>(*I))
8248 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008249 else {
8250 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008251 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008252 }
John McCall9f54ad42009-12-10 09:41:52 +00008253 }
John McCall129e2df2009-11-30 22:42:35 +00008254
8255 // Expand using declarations.
8256 if (isa<UsingDecl>(InstD)) {
8257 UsingDecl *UD = cast<UsingDecl>(InstD);
8258 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8259 E = UD->shadow_end(); I != E; ++I)
8260 R.addDecl(*I);
8261 continue;
8262 }
8263
8264 R.addDecl(InstD);
8265 }
8266
8267 R.resolveKind();
8268
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008269 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008270 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008271 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008272 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008273 Old->getMemberLoc(),
8274 Old->getNamingClass()));
8275 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008276 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008277
Douglas Gregor66c45152010-04-27 16:10:10 +00008278 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008279 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008280
John McCall129e2df2009-11-30 22:42:35 +00008281 TemplateArgumentListInfo TransArgs;
8282 if (Old->hasExplicitTemplateArgs()) {
8283 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8284 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008285 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8286 Old->getNumTemplateArgs(),
8287 TransArgs))
8288 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008289 }
John McCallc2233c52010-01-15 08:34:02 +00008290
8291 // FIXME: to do this check properly, we will need to preserve the
8292 // first-qualifier-in-scope here, just in case we had a dependent
8293 // base (and therefore couldn't do the check) and a
8294 // nested-name-qualifier (and therefore could do the lookup).
8295 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008296
John McCall9ae2f072010-08-23 23:25:46 +00008297 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008298 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008299 Old->getOperatorLoc(),
8300 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008301 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008302 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008303 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008304 R,
8305 (Old->hasExplicitTemplateArgs()
8306 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008307}
8308
8309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008310ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008311TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008312 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008313 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8314 if (SubExpr.isInvalid())
8315 return ExprError();
8316
8317 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008318 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008319
8320 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8321}
8322
8323template<typename Derived>
8324ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008325TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008326 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8327 if (Pattern.isInvalid())
8328 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008329
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008330 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8331 return SemaRef.Owned(E);
8332
Douglas Gregor67fd1252011-01-14 21:20:45 +00008333 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8334 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008335}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008336
8337template<typename Derived>
8338ExprResult
8339TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8340 // If E is not value-dependent, then nothing will change when we transform it.
8341 // Note: This is an instantiation-centric view.
8342 if (!E->isValueDependent())
8343 return SemaRef.Owned(E);
8344
8345 // Note: None of the implementations of TryExpandParameterPacks can ever
8346 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008347 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008348 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8349 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008350 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008351 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008352 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008353 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008354 ShouldExpand, RetainExpansion,
8355 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008356 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008357
Douglas Gregor089e8932011-10-10 18:59:29 +00008358 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008359 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregor089e8932011-10-10 18:59:29 +00008361 NamedDecl *Pack = E->getPack();
8362 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008364 Pack));
8365 if (!Pack)
8366 return ExprError();
8367 }
8368
Chad Rosier4a9d7952012-08-08 18:46:20 +00008369
Douglas Gregoree8aff02011-01-04 17:33:58 +00008370 // We now know the length of the parameter pack, so build a new expression
8371 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008372 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8373 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008374 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008375}
8376
Douglas Gregorbe230c32011-01-03 17:17:50 +00008377template<typename Derived>
8378ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008379TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8380 SubstNonTypeTemplateParmPackExpr *E) {
8381 // Default behavior is to do nothing with this transformation.
8382 return SemaRef.Owned(E);
8383}
8384
8385template<typename Derived>
8386ExprResult
John McCall91a57552011-07-15 05:09:51 +00008387TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8388 SubstNonTypeTemplateParmExpr *E) {
8389 // Default behavior is to do nothing with this transformation.
8390 return SemaRef.Owned(E);
8391}
8392
8393template<typename Derived>
8394ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008395TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8396 // Default behavior is to do nothing with this transformation.
8397 return SemaRef.Owned(E);
8398}
8399
8400template<typename Derived>
8401ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008402TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8403 MaterializeTemporaryExpr *E) {
8404 return getDerived().TransformExpr(E->GetTemporaryExpr());
8405}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008406
Douglas Gregor03e80032011-06-21 17:03:29 +00008407template<typename Derived>
8408ExprResult
John McCall454feb92009-12-08 09:21:05 +00008409TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008410 return SemaRef.MaybeBindToTemporary(E);
8411}
8412
8413template<typename Derived>
8414ExprResult
8415TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008416 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008417}
8418
8419template<typename Derived>
8420ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008421TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8422 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8423 if (SubExpr.isInvalid())
8424 return ExprError();
8425
8426 if (!getDerived().AlwaysRebuild() &&
8427 SubExpr.get() == E->getSubExpr())
8428 return SemaRef.Owned(E);
8429
8430 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008431}
8432
8433template<typename Derived>
8434ExprResult
8435TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8436 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008437 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008438 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008439 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008440 /*IsCall=*/false, Elements, &ArgChanged))
8441 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008443 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8444 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8447 Elements.data(),
8448 Elements.size());
8449}
8450
8451template<typename Derived>
8452ExprResult
8453TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008454 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008455 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008456 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 bool ArgChanged = false;
8458 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8459 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008460
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008461 if (OrigElement.isPackExpansion()) {
8462 // This key/value element is a pack expansion.
8463 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8464 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8465 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8466 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8467
8468 // Determine whether the set of unexpanded parameter packs can
8469 // and should be expanded.
8470 bool Expand = true;
8471 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008472 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8473 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008474 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8475 OrigElement.Value->getLocEnd());
8476 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8477 PatternRange,
8478 Unexpanded,
8479 Expand, RetainExpansion,
8480 NumExpansions))
8481 return ExprError();
8482
8483 if (!Expand) {
8484 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008485 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008486 // expansion.
8487 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8488 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8489 if (Key.isInvalid())
8490 return ExprError();
8491
8492 if (Key.get() != OrigElement.Key)
8493 ArgChanged = true;
8494
8495 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8496 if (Value.isInvalid())
8497 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008498
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008499 if (Value.get() != OrigElement.Value)
8500 ArgChanged = true;
8501
Chad Rosier4a9d7952012-08-08 18:46:20 +00008502 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008503 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8504 };
8505 Elements.push_back(Expansion);
8506 continue;
8507 }
8508
8509 // Record right away that the argument was changed. This needs
8510 // to happen even if the array expands to nothing.
8511 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008512
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008513 // The transform has determined that we should perform an elementwise
8514 // expansion of the pattern. Do so.
8515 for (unsigned I = 0; I != *NumExpansions; ++I) {
8516 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8517 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8518 if (Key.isInvalid())
8519 return ExprError();
8520
8521 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8522 if (Value.isInvalid())
8523 return ExprError();
8524
Chad Rosier4a9d7952012-08-08 18:46:20 +00008525 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008526 Key.get(), Value.get(), SourceLocation(), NumExpansions
8527 };
8528
8529 // If any unexpanded parameter packs remain, we still have a
8530 // pack expansion.
8531 if (Key.get()->containsUnexpandedParameterPack() ||
8532 Value.get()->containsUnexpandedParameterPack())
8533 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008534
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008535 Elements.push_back(Element);
8536 }
8537
8538 // We've finished with this pack expansion.
8539 continue;
8540 }
8541
8542 // Transform and check key.
8543 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8544 if (Key.isInvalid())
8545 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008546
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008547 if (Key.get() != OrigElement.Key)
8548 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008550 // Transform and check value.
8551 ExprResult Value
8552 = getDerived().TransformExpr(OrigElement.Value);
8553 if (Value.isInvalid())
8554 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008555
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008556 if (Value.get() != OrigElement.Value)
8557 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008558
8559 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008560 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008561 };
8562 Elements.push_back(Element);
8563 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008564
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008565 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8566 return SemaRef.MaybeBindToTemporary(E);
8567
8568 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8569 Elements.data(),
8570 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008571}
8572
Mike Stump1eb44332009-09-09 15:08:12 +00008573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008574ExprResult
John McCall454feb92009-12-08 09:21:05 +00008575TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008576 TypeSourceInfo *EncodedTypeInfo
8577 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8578 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008580
Douglas Gregorb98b1992009-08-11 05:31:07 +00008581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008582 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008583 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008584
8585 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008586 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008587 E->getRParenLoc());
8588}
Mike Stump1eb44332009-09-09 15:08:12 +00008589
Douglas Gregorb98b1992009-08-11 05:31:07 +00008590template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008591ExprResult TreeTransform<Derived>::
8592TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8593 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8594 if (result.isInvalid()) return ExprError();
8595 Expr *subExpr = result.take();
8596
8597 if (!getDerived().AlwaysRebuild() &&
8598 subExpr == E->getSubExpr())
8599 return SemaRef.Owned(E);
8600
8601 return SemaRef.Owned(new(SemaRef.Context)
8602 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8603}
8604
8605template<typename Derived>
8606ExprResult TreeTransform<Derived>::
8607TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008608 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008609 = getDerived().TransformType(E->getTypeInfoAsWritten());
8610 if (!TSInfo)
8611 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008612
John McCallf85e1932011-06-15 23:02:42 +00008613 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008614 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008615 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008616
John McCallf85e1932011-06-15 23:02:42 +00008617 if (!getDerived().AlwaysRebuild() &&
8618 TSInfo == E->getTypeInfoAsWritten() &&
8619 Result.get() == E->getSubExpr())
8620 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008621
John McCallf85e1932011-06-15 23:02:42 +00008622 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008623 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008624 Result.get());
8625}
8626
8627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008628ExprResult
John McCall454feb92009-12-08 09:21:05 +00008629TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008630 // Transform arguments.
8631 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008632 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008633 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008634 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008635 &ArgChanged))
8636 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008637
Douglas Gregor92e986e2010-04-22 16:44:27 +00008638 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8639 // Class message: transform the receiver type.
8640 TypeSourceInfo *ReceiverTypeInfo
8641 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8642 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008643 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008644
Douglas Gregor92e986e2010-04-22 16:44:27 +00008645 // If nothing changed, just retain the existing message send.
8646 if (!getDerived().AlwaysRebuild() &&
8647 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008648 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008649
8650 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008651 SmallVector<SourceLocation, 16> SelLocs;
8652 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008653 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8654 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008655 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008656 E->getMethodDecl(),
8657 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008658 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008659 E->getRightLoc());
8660 }
8661
8662 // Instance message: transform the receiver
8663 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8664 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008665 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008666 = getDerived().TransformExpr(E->getInstanceReceiver());
8667 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008668 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008669
8670 // If nothing changed, just retain the existing message send.
8671 if (!getDerived().AlwaysRebuild() &&
8672 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008673 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008674
Douglas Gregor92e986e2010-04-22 16:44:27 +00008675 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008676 SmallVector<SourceLocation, 16> SelLocs;
8677 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008678 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008679 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008680 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008681 E->getMethodDecl(),
8682 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008683 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008684 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008685}
8686
Mike Stump1eb44332009-09-09 15:08:12 +00008687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008688ExprResult
John McCall454feb92009-12-08 09:21:05 +00008689TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008690 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008691}
8692
Mike Stump1eb44332009-09-09 15:08:12 +00008693template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008694ExprResult
John McCall454feb92009-12-08 09:21:05 +00008695TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008696 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008697}
8698
Mike Stump1eb44332009-09-09 15:08:12 +00008699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008700ExprResult
John McCall454feb92009-12-08 09:21:05 +00008701TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008702 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008703 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008704 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008705 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008706
8707 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008708
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008709 // If nothing changed, just retain the existing expression.
8710 if (!getDerived().AlwaysRebuild() &&
8711 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008712 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713
John McCall9ae2f072010-08-23 23:25:46 +00008714 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008715 E->getLocation(),
8716 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008717}
8718
Mike Stump1eb44332009-09-09 15:08:12 +00008719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008720ExprResult
John McCall454feb92009-12-08 09:21:05 +00008721TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008722 // 'super' and types never change. Property never changes. Just
8723 // retain the existing expression.
8724 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008725 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008726
Douglas Gregore3303542010-04-26 20:47:02 +00008727 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008728 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008729 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008730 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
Douglas Gregore3303542010-04-26 20:47:02 +00008732 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008733
Douglas Gregore3303542010-04-26 20:47:02 +00008734 // If nothing changed, just retain the existing expression.
8735 if (!getDerived().AlwaysRebuild() &&
8736 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008737 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008738
John McCall12f78a62010-12-02 01:19:52 +00008739 if (E->isExplicitProperty())
8740 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8741 E->getExplicitProperty(),
8742 E->getLocation());
8743
8744 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008745 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008746 E->getImplicitPropertyGetter(),
8747 E->getImplicitPropertySetter(),
8748 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008749}
8750
Mike Stump1eb44332009-09-09 15:08:12 +00008751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008752ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008753TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8754 // Transform the base expression.
8755 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8756 if (Base.isInvalid())
8757 return ExprError();
8758
8759 // Transform the key expression.
8760 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8761 if (Key.isInvalid())
8762 return ExprError();
8763
8764 // If nothing changed, just retain the existing expression.
8765 if (!getDerived().AlwaysRebuild() &&
8766 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8767 return SemaRef.Owned(E);
8768
Chad Rosier4a9d7952012-08-08 18:46:20 +00008769 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008770 Base.get(), Key.get(),
8771 E->getAtIndexMethodDecl(),
8772 E->setAtIndexMethodDecl());
8773}
8774
8775template<typename Derived>
8776ExprResult
John McCall454feb92009-12-08 09:21:05 +00008777TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008778 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008779 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008780 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008781 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008782
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008783 // If nothing changed, just retain the existing expression.
8784 if (!getDerived().AlwaysRebuild() &&
8785 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008786 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008787
John McCall9ae2f072010-08-23 23:25:46 +00008788 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008789 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008790}
8791
Mike Stump1eb44332009-09-09 15:08:12 +00008792template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008793ExprResult
John McCall454feb92009-12-08 09:21:05 +00008794TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008795 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008796 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008797 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008798 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008799 SubExprs, &ArgumentChanged))
8800 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008801
Douglas Gregorb98b1992009-08-11 05:31:07 +00008802 if (!getDerived().AlwaysRebuild() &&
8803 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008804 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008805
Douglas Gregorb98b1992009-08-11 05:31:07 +00008806 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008807 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008808 E->getRParenLoc());
8809}
8810
Mike Stump1eb44332009-09-09 15:08:12 +00008811template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008812ExprResult
John McCall454feb92009-12-08 09:21:05 +00008813TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008814 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008815
John McCallc6ac9c32011-02-04 18:33:18 +00008816 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8817 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8818
8819 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008820 blockScope->TheDecl->setBlockMissingReturnType(
8821 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008822
Chris Lattner686775d2011-07-20 06:58:45 +00008823 SmallVector<ParmVarDecl*, 4> params;
8824 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008825
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008826 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008827 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8828 oldBlock->param_begin(),
8829 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008830 0, paramTypes, &params)) {
8831 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008832 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008833 }
John McCallc6ac9c32011-02-04 18:33:18 +00008834
Jordan Rose09189892013-03-08 22:25:36 +00008835 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008836 QualType exprResultType =
8837 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008838
8839 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008840 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008841 getSema().Diag(E->getCaretLocation(),
8842 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008843 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008844 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008845 return ExprError();
8846 }
John McCall711c52b2011-01-05 12:14:39 +00008847
Jordan Rosebea522f2013-03-08 21:51:21 +00008848 QualType functionType =
8849 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008850 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008851 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008852
8853 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008854 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008855 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008856
8857 if (!oldBlock->blockMissingReturnType()) {
8858 blockScope->HasImplicitReturnType = false;
8859 blockScope->ReturnType = exprResultType;
8860 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008861
John McCall711c52b2011-01-05 12:14:39 +00008862 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008863 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008864 if (body.isInvalid()) {
8865 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008866 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008867 }
John McCall711c52b2011-01-05 12:14:39 +00008868
John McCallc6ac9c32011-02-04 18:33:18 +00008869#ifndef NDEBUG
8870 // In builds with assertions, make sure that we captured everything we
8871 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008872 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8873 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8874 e = oldBlock->capture_end(); i != e; ++i) {
8875 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008876
Douglas Gregorfc921372011-05-20 15:32:55 +00008877 // Ignore parameter packs.
8878 if (isa<ParmVarDecl>(oldCapture) &&
8879 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8880 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008881
Douglas Gregorfc921372011-05-20 15:32:55 +00008882 VarDecl *newCapture =
8883 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8884 oldCapture));
8885 assert(blockScope->CaptureMap.count(newCapture));
8886 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008887 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008888 }
8889#endif
8890
8891 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8892 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008893}
8894
Mike Stump1eb44332009-09-09 15:08:12 +00008895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008896ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008897TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008898 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008899}
Eli Friedman276b0612011-10-11 02:20:01 +00008900
8901template<typename Derived>
8902ExprResult
8903TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008904 QualType RetTy = getDerived().TransformType(E->getType());
8905 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008906 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008907 SubExprs.reserve(E->getNumSubExprs());
8908 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8909 SubExprs, &ArgumentChanged))
8910 return ExprError();
8911
8912 if (!getDerived().AlwaysRebuild() &&
8913 !ArgumentChanged)
8914 return SemaRef.Owned(E);
8915
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008916 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008917 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008918}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008919
Douglas Gregorb98b1992009-08-11 05:31:07 +00008920//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008921// Type reconstruction
8922//===----------------------------------------------------------------------===//
8923
Mike Stump1eb44332009-09-09 15:08:12 +00008924template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008925QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8926 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008927 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008928 getDerived().getBaseEntity());
8929}
8930
Mike Stump1eb44332009-09-09 15:08:12 +00008931template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008932QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8933 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008934 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008935 getDerived().getBaseEntity());
8936}
8937
Mike Stump1eb44332009-09-09 15:08:12 +00008938template<typename Derived>
8939QualType
John McCall85737a72009-10-30 00:06:24 +00008940TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8941 bool WrittenAsLValue,
8942 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008943 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
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
John McCall85737a72009-10-30 00:06:24 +00008949TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8950 QualType ClassType,
8951 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008952 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008953 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954}
8955
8956template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008957QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8959 ArrayType::ArraySizeModifier SizeMod,
8960 const llvm::APInt *Size,
8961 Expr *SizeExpr,
8962 unsigned IndexTypeQuals,
8963 SourceRange BracketsRange) {
8964 if (SizeExpr || !Size)
8965 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8966 IndexTypeQuals, BracketsRange,
8967 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008968
8969 QualType Types[] = {
8970 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8971 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8972 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008973 };
8974 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8975 QualType SizeType;
8976 for (unsigned I = 0; I != NumTypes; ++I)
8977 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8978 SizeType = Types[I];
8979 break;
8980 }
Mike Stump1eb44332009-09-09 15:08:12 +00008981
Eli Friedman01f276d2012-01-25 23:20:27 +00008982 // Note that we can return a VariableArrayType here in the case where
8983 // the element type was a dependent VariableArrayType.
8984 IntegerLiteral *ArraySize
8985 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8986 /*FIXME*/BracketsRange.getBegin());
8987 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008988 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008989 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008990}
Mike Stump1eb44332009-09-09 15:08:12 +00008991
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008993QualType
8994TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995 ArrayType::ArraySizeModifier SizeMod,
8996 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008997 unsigned IndexTypeQuals,
8998 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008999 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009000 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009001}
9002
9003template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009004QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009005TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009006 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009007 unsigned IndexTypeQuals,
9008 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009009 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009010 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011}
Mike Stump1eb44332009-09-09 15:08:12 +00009012
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009014QualType
9015TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009017 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009018 unsigned IndexTypeQuals,
9019 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009020 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009021 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009022 IndexTypeQuals, BracketsRange);
9023}
9024
9025template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009026QualType
9027TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009028 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009029 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009030 unsigned IndexTypeQuals,
9031 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009032 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009033 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034 IndexTypeQuals, BracketsRange);
9035}
9036
9037template<typename Derived>
9038QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009039 unsigned NumElements,
9040 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009041 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009042 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009043}
Mike Stump1eb44332009-09-09 15:08:12 +00009044
Douglas Gregor577f75a2009-08-04 16:50:30 +00009045template<typename Derived>
9046QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9047 unsigned NumElements,
9048 SourceLocation AttributeLoc) {
9049 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9050 NumElements, true);
9051 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009052 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9053 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009054 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009055}
Mike Stump1eb44332009-09-09 15:08:12 +00009056
Douglas Gregor577f75a2009-08-04 16:50:30 +00009057template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009058QualType
9059TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009060 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009061 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009062 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009063}
Mike Stump1eb44332009-09-09 15:08:12 +00009064
Douglas Gregor577f75a2009-08-04 16:50:30 +00009065template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009066QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9067 QualType T,
9068 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009069 const FunctionProtoType::ExtProtoInfo &EPI) {
9070 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009071 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009072 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009073 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074}
Mike Stump1eb44332009-09-09 15:08:12 +00009075
Douglas Gregor577f75a2009-08-04 16:50:30 +00009076template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009077QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9078 return SemaRef.Context.getFunctionNoProtoType(T);
9079}
9080
9081template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009082QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9083 assert(D && "no decl found");
9084 if (D->isInvalidDecl()) return QualType();
9085
Douglas Gregor92e986e2010-04-22 16:44:27 +00009086 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009087 TypeDecl *Ty;
9088 if (isa<UsingDecl>(D)) {
9089 UsingDecl *Using = cast<UsingDecl>(D);
9090 assert(Using->isTypeName() &&
9091 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9092
9093 // A valid resolved using typename decl points to exactly one type decl.
9094 assert(++Using->shadow_begin() == Using->shadow_end());
9095 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009096
John McCalled976492009-12-04 22:46:56 +00009097 } else {
9098 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9099 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9100 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9101 }
9102
9103 return SemaRef.Context.getTypeDeclType(Ty);
9104}
9105
9106template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009107QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9108 SourceLocation Loc) {
9109 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009110}
9111
9112template<typename Derived>
9113QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9114 return SemaRef.Context.getTypeOfType(Underlying);
9115}
9116
9117template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009118QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9119 SourceLocation Loc) {
9120 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009121}
9122
9123template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009124QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9125 UnaryTransformType::UTTKind UKind,
9126 SourceLocation Loc) {
9127 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9128}
9129
9130template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009131QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009132 TemplateName Template,
9133 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009134 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009135 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009136}
Mike Stump1eb44332009-09-09 15:08:12 +00009137
Douglas Gregordcee1a12009-08-06 05:28:30 +00009138template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009139QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9140 SourceLocation KWLoc) {
9141 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9142}
9143
9144template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009145TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009146TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009147 bool TemplateKW,
9148 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009149 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009150 Template);
9151}
9152
9153template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009154TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009155TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9156 const IdentifierInfo &Name,
9157 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009158 QualType ObjectType,
9159 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009160 UnqualifiedId TemplateName;
9161 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009162 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009163 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009164 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009165 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009166 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009167 /*EnteringContext=*/false,
9168 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009169 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009170}
Mike Stump1eb44332009-09-09 15:08:12 +00009171
Douglas Gregorb98b1992009-08-11 05:31:07 +00009172template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009173TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009174TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009175 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009176 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009177 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009178 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009179 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009180 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009181 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009182 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009183 Sema::TemplateTy Template;
9184 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009185 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009186 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009187 /*EnteringContext=*/false,
9188 Template);
9189 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009190}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009191
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009193ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009194TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9195 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009196 Expr *OrigCallee,
9197 Expr *First,
9198 Expr *Second) {
9199 Expr *Callee = OrigCallee->IgnoreParenCasts();
9200 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009201
Douglas Gregorb98b1992009-08-11 05:31:07 +00009202 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009203 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009204 if (!First->getType()->isOverloadableType() &&
9205 !Second->getType()->isOverloadableType())
9206 return getSema().CreateBuiltinArraySubscriptExpr(First,
9207 Callee->getLocStart(),
9208 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009209 } else if (Op == OO_Arrow) {
9210 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009211 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9212 } else if (Second == 0 || isPostIncDec) {
9213 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009214 // The argument is not of overloadable type, so try to create a
9215 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009216 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009217 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009218
John McCall9ae2f072010-08-23 23:25:46 +00009219 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009220 }
9221 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009222 if (!First->getType()->isOverloadableType() &&
9223 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009224 // Neither of the arguments is an overloadable type, so try to
9225 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009226 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009227 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009228 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009230 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009231
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009232 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 }
9234 }
Mike Stump1eb44332009-09-09 15:08:12 +00009235
9236 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009237 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009238 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009239
John McCall9ae2f072010-08-23 23:25:46 +00009240 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009241 assert(ULE->requiresADL());
9242
9243 // FIXME: Do we have to check
9244 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009245 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009246 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009247 // If we've resolved this to a particular non-member function, just call
9248 // that function. If we resolved it to a member function,
9249 // CreateOverloaded* will find that function for us.
9250 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9251 if (!isa<CXXMethodDecl>(ND))
9252 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009253 }
Mike Stump1eb44332009-09-09 15:08:12 +00009254
Douglas Gregorb98b1992009-08-11 05:31:07 +00009255 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009256 Expr *Args[2] = { First, Second };
9257 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009258
Douglas Gregorb98b1992009-08-11 05:31:07 +00009259 // Create the overloaded operator invocation for unary operators.
9260 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009261 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009262 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009263 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009264 }
Mike Stump1eb44332009-09-09 15:08:12 +00009265
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009266 if (Op == OO_Subscript) {
9267 SourceLocation LBrace;
9268 SourceLocation RBrace;
9269
9270 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9271 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9272 LBrace = SourceLocation::getFromRawEncoding(
9273 NameLoc.CXXOperatorName.BeginOpNameLoc);
9274 RBrace = SourceLocation::getFromRawEncoding(
9275 NameLoc.CXXOperatorName.EndOpNameLoc);
9276 } else {
9277 LBrace = Callee->getLocStart();
9278 RBrace = OpLoc;
9279 }
9280
9281 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9282 First, Second);
9283 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009284
Douglas Gregorb98b1992009-08-11 05:31:07 +00009285 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009286 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009287 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009288 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9289 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009290 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009291
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009292 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009293}
Mike Stump1eb44332009-09-09 15:08:12 +00009294
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009295template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009296ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009297TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009298 SourceLocation OperatorLoc,
9299 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009300 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009301 TypeSourceInfo *ScopeType,
9302 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009303 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009304 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009305 QualType BaseType = Base->getType();
9306 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009307 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009308 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009309 !BaseType->getAs<PointerType>()->getPointeeType()
9310 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009311 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009312 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009313 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009314 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009315 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009316 /*FIXME?*/true);
9317 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009318
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009319 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009320 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9321 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9322 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9323 NameInfo.setNamedTypeInfo(DestroyedType);
9324
Richard Smith6314db92012-05-15 06:15:11 +00009325 // The scope type is now known to be a valid nested name specifier
9326 // component. Tack it on to the end of the nested name specifier.
9327 if (ScopeType)
9328 SS.Extend(SemaRef.Context, SourceLocation(),
9329 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009330
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009331 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009332 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009333 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009334 SS, TemplateKWLoc,
9335 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009336 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009337 /*TemplateArgs*/ 0);
9338}
9339
Douglas Gregor577f75a2009-08-04 16:50:30 +00009340} // end namespace clang
9341
9342#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H