blob: bdd68a7bde90e3560e67e3f2af938ab4a8c65fb6 [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,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002392 SourceLocation OpLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002393 bool IsArrow) {
2394 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002395 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002396 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2397 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002398 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002399 OpLoc,
John McCalld226f652010-08-21 09:40:31 +00002400 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002401 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002402 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002403
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002405 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002406
John Wiegley429bb272011-04-08 18:41:53 +00002407 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00002408 OpLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002409 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002410 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002411 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /*TemplateArgs=*/0);
2413 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002414
Douglas Gregorb98b1992009-08-11 05:31:07 +00002415 /// \brief Build a new shuffle vector expression.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002419 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002420 MultiExprArg SubExprs,
2421 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002422 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002423 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2425 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2426 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002427 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002428
Douglas Gregorb98b1992009-08-11 05:31:07 +00002429 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002430 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002431 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2432 SemaRef.Context.BuiltinFnTy,
2433 VK_RValue, BuiltinLoc);
2434 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2435 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2436 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002437
2438 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002439 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002440 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002441 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002442 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002443 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002444
Douglas Gregorb98b1992009-08-11 05:31:07 +00002445 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002446 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002447 }
John McCall43fed0d2010-11-12 08:19:04 +00002448
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002449 /// \brief Build a new template argument pack expansion.
2450 ///
2451 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002452 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002453 /// different behavior.
2454 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002455 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002456 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002457 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002458 case TemplateArgument::Expression: {
2459 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002460 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2461 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002462 if (Result.isInvalid())
2463 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002464
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002465 return TemplateArgumentLoc(Result.get(), Result.get());
2466 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002467
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002468 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002469 return TemplateArgumentLoc(TemplateArgument(
2470 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002471 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002472 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002473 Pattern.getTemplateNameLoc(),
2474 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002475
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002476 case TemplateArgument::Null:
2477 case TemplateArgument::Integral:
2478 case TemplateArgument::Declaration:
2479 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002480 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002481 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002482 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002483
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002485 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002487 EllipsisLoc,
2488 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002489 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2490 Expansion);
2491 break;
2492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002493
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002494 return TemplateArgumentLoc();
2495 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002496
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002497 /// \brief Build a new expression pack expansion.
2498 ///
2499 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002500 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002501 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002502 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002503 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002504 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002505 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002506
2507 /// \brief Build a new atomic operation expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
2511 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2512 MultiExprArg SubExprs,
2513 QualType RetTy,
2514 AtomicExpr::AtomicOp Op,
2515 SourceLocation RParenLoc) {
2516 // Just create the expression; there is not any interesting semantic
2517 // analysis here because we can't actually build an AtomicExpr until
2518 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002519 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002520 RParenLoc);
2521 }
2522
John McCall43fed0d2010-11-12 08:19:04 +00002523private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002524 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2525 QualType ObjectType,
2526 NamedDecl *FirstQualifierInScope,
2527 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002528
2529 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2530 QualType ObjectType,
2531 NamedDecl *FirstQualifierInScope,
2532 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002533};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002534
Douglas Gregor43959a92009-08-20 07:17:43 +00002535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002536StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002537 if (!S)
2538 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002539
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 switch (S->getStmtClass()) {
2541 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002542
Douglas Gregor43959a92009-08-20 07:17:43 +00002543 // Transform individual statement nodes
2544#define STMT(Node, Parent) \
2545 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002546#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002547#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002548#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002549
Douglas Gregor43959a92009-08-20 07:17:43 +00002550 // Transform expressions by calling TransformExpr.
2551#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002552#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002553#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002554#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002555 {
John McCall60d7b3a2010-08-24 06:29:42 +00002556 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002557 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002558 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002559
Richard Smith41956372013-01-14 22:39:08 +00002560 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002561 }
Mike Stump1eb44332009-09-09 15:08:12 +00002562 }
2563
John McCall3fa5cae2010-10-26 07:05:15 +00002564 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002565}
Mike Stump1eb44332009-09-09 15:08:12 +00002566
2567
Douglas Gregor670444e2009-08-04 22:27:00 +00002568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002569ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002570 if (!E)
2571 return SemaRef.Owned(E);
2572
2573 switch (E->getStmtClass()) {
2574 case Stmt::NoStmtClass: break;
2575#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002576#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002577#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002578 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002579#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002580 }
2581
John McCall3fa5cae2010-10-26 07:05:15 +00002582 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002583}
2584
2585template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002586ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2587 bool CXXDirectInit) {
2588 // Initializers are instantiated like expressions, except that various outer
2589 // layers are stripped.
2590 if (!Init)
2591 return SemaRef.Owned(Init);
2592
2593 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2594 Init = ExprTemp->getSubExpr();
2595
2596 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2597 Init = Binder->getSubExpr();
2598
2599 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2600 Init = ICE->getSubExprAsWritten();
2601
Richard Smith5cf15892012-12-21 08:13:35 +00002602 // If this is not a direct-initializer, we only need to reconstruct
2603 // InitListExprs. Other forms of copy-initialization will be a no-op if
2604 // the initializer is already the right type.
2605 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2606 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2607 return getDerived().TransformExpr(Init);
2608
2609 // Revert value-initialization back to empty parens.
2610 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2611 SourceRange Parens = VIE->getSourceRange();
2612 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2613 Parens.getEnd());
2614 }
2615
2616 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2617 if (isa<ImplicitValueInitExpr>(Init))
2618 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2619 SourceLocation());
2620
2621 // Revert initialization by constructor back to a parenthesized or braced list
2622 // of expressions. Any other form of initializer can just be reused directly.
2623 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002624 return getDerived().TransformExpr(Init);
2625
2626 SmallVector<Expr*, 8> NewArgs;
2627 bool ArgChanged = false;
2628 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2629 /*IsCall*/true, NewArgs, &ArgChanged))
2630 return ExprError();
2631
2632 // If this was list initialization, revert to list form.
2633 if (Construct->isListInitialization())
2634 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2635 Construct->getLocEnd(),
2636 Construct->getType());
2637
Richard Smithc83c2302012-12-19 01:39:02 +00002638 // Build a ParenListExpr to represent anything else.
2639 SourceRange Parens = Construct->getParenRange();
2640 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2641 Parens.getEnd());
2642}
2643
2644template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002645bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2646 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002647 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002648 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002649 bool *ArgChanged) {
2650 for (unsigned I = 0; I != NumInputs; ++I) {
2651 // If requested, drop call arguments that need to be dropped.
2652 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2653 if (ArgChanged)
2654 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002655
Douglas Gregoraa165f82011-01-03 19:04:46 +00002656 break;
2657 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002658
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002659 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2660 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002661
Chris Lattner686775d2011-07-20 06:58:45 +00002662 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002663 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2664 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002665
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002666 // Determine whether the set of unexpanded parameter packs can and should
2667 // be expanded.
2668 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002669 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002670 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2671 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002672 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2673 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002674 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002675 Expand, RetainExpansion,
2676 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002677 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002678
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002679 if (!Expand) {
2680 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002681 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002682 // expansion.
2683 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2684 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2685 if (OutPattern.isInvalid())
2686 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002687
2688 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002689 Expansion->getEllipsisLoc(),
2690 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002691 if (Out.isInvalid())
2692 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002693
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002694 if (ArgChanged)
2695 *ArgChanged = true;
2696 Outputs.push_back(Out.get());
2697 continue;
2698 }
John McCallc8fc90a2011-07-06 07:30:07 +00002699
2700 // Record right away that the argument was changed. This needs
2701 // to happen even if the array expands to nothing.
2702 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002703
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002704 // The transform has determined that we should perform an elementwise
2705 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002706 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002707 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2708 ExprResult Out = getDerived().TransformExpr(Pattern);
2709 if (Out.isInvalid())
2710 return true;
2711
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002712 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002713 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2714 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002715 if (Out.isInvalid())
2716 return true;
2717 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002718
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002719 Outputs.push_back(Out.get());
2720 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002721
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002722 continue;
2723 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002724
Richard Smithc83c2302012-12-19 01:39:02 +00002725 ExprResult Result =
2726 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2727 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002728 if (Result.isInvalid())
2729 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002730
Douglas Gregoraa165f82011-01-03 19:04:46 +00002731 if (Result.get() != Inputs[I] && ArgChanged)
2732 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002733
2734 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002735 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002736
Douglas Gregoraa165f82011-01-03 19:04:46 +00002737 return false;
2738}
2739
2740template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002741NestedNameSpecifierLoc
2742TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2743 NestedNameSpecifierLoc NNS,
2744 QualType ObjectType,
2745 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002746 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002747 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002748 Qualifier = Qualifier.getPrefix())
2749 Qualifiers.push_back(Qualifier);
2750
2751 CXXScopeSpec SS;
2752 while (!Qualifiers.empty()) {
2753 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2754 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002755
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002756 switch (QNNS->getKind()) {
2757 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002759 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002761 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002762 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002763 FirstQualifierInScope, false))
2764 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002765
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002768 case NestedNameSpecifier::Namespace: {
2769 NamespaceDecl *NS
2770 = cast_or_null<NamespaceDecl>(
2771 getDerived().TransformDecl(
2772 Q.getLocalBeginLoc(),
2773 QNNS->getAsNamespace()));
2774 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2775 break;
2776 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002777
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002778 case NestedNameSpecifier::NamespaceAlias: {
2779 NamespaceAliasDecl *Alias
2780 = cast_or_null<NamespaceAliasDecl>(
2781 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2782 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002783 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002784 Q.getLocalEndLoc());
2785 break;
2786 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002787
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002788 case NestedNameSpecifier::Global:
2789 // There is no meaningful transformation that one could perform on the
2790 // global scope.
2791 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2792 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002793
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002794 case NestedNameSpecifier::TypeSpecWithTemplate:
2795 case NestedNameSpecifier::TypeSpec: {
2796 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2797 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002798
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002799 if (!TL)
2800 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002801
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002802 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002803 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002804 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002805 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002806 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002807 if (TL.getType()->isEnumeralType())
2808 SemaRef.Diag(TL.getBeginLoc(),
2809 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002810 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2811 Q.getLocalEndLoc());
2812 break;
2813 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002814 // If the nested-name-specifier is an invalid type def, don't emit an
2815 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002816 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2817 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002818 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002819 << TL.getType() << SS.getRange();
2820 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002821 return NestedNameSpecifierLoc();
2822 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002823 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002824
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002825 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002826 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002827 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002828 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002829
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002830 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002831 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002832 !getDerived().AlwaysRebuild())
2833 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002834
2835 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002836 // nested-name-specifier, do so.
2837 if (SS.location_size() == NNS.getDataLength() &&
2838 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2839 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2840
2841 // Allocate new nested-name-specifier location information.
2842 return SS.getWithLocInContext(SemaRef.Context);
2843}
2844
2845template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002846DeclarationNameInfo
2847TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002848::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002849 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002850 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002851 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002852
2853 switch (Name.getNameKind()) {
2854 case DeclarationName::Identifier:
2855 case DeclarationName::ObjCZeroArgSelector:
2856 case DeclarationName::ObjCOneArgSelector:
2857 case DeclarationName::ObjCMultiArgSelector:
2858 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002859 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002860 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002861 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002862
Douglas Gregor81499bb2009-09-03 22:13:48 +00002863 case DeclarationName::CXXConstructorName:
2864 case DeclarationName::CXXDestructorName:
2865 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002866 TypeSourceInfo *NewTInfo;
2867 CanQualType NewCanTy;
2868 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002869 NewTInfo = getDerived().TransformType(OldTInfo);
2870 if (!NewTInfo)
2871 return DeclarationNameInfo();
2872 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002873 }
2874 else {
2875 NewTInfo = 0;
2876 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002877 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002878 if (NewT.isNull())
2879 return DeclarationNameInfo();
2880 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2881 }
Mike Stump1eb44332009-09-09 15:08:12 +00002882
Abramo Bagnara25777432010-08-11 22:01:17 +00002883 DeclarationName NewName
2884 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2885 NewCanTy);
2886 DeclarationNameInfo NewNameInfo(NameInfo);
2887 NewNameInfo.setName(NewName);
2888 NewNameInfo.setNamedTypeInfo(NewTInfo);
2889 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002890 }
Mike Stump1eb44332009-09-09 15:08:12 +00002891 }
2892
David Blaikieb219cfc2011-09-23 05:06:16 +00002893 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002894}
2895
2896template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002897TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002898TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2899 TemplateName Name,
2900 SourceLocation NameLoc,
2901 QualType ObjectType,
2902 NamedDecl *FirstQualifierInScope) {
2903 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2904 TemplateDecl *Template = QTN->getTemplateDecl();
2905 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002906
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002907 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002908 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002909 Template));
2910 if (!TransTemplate)
2911 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002912
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002913 if (!getDerived().AlwaysRebuild() &&
2914 SS.getScopeRep() == QTN->getQualifier() &&
2915 TransTemplate == Template)
2916 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002917
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002918 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2919 TransTemplate);
2920 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002921
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002922 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2923 if (SS.getScopeRep()) {
2924 // These apply to the scope specifier, not the template.
2925 ObjectType = QualType();
2926 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002927 }
2928
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002929 if (!getDerived().AlwaysRebuild() &&
2930 SS.getScopeRep() == DTN->getQualifier() &&
2931 ObjectType.isNull())
2932 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002934 if (DTN->isIdentifier()) {
2935 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002936 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002937 NameLoc,
2938 ObjectType,
2939 FirstQualifierInScope);
2940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002941
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002942 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2943 ObjectType);
2944 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002945
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002946 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2947 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002948 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002949 Template));
2950 if (!TransTemplate)
2951 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002952
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002953 if (!getDerived().AlwaysRebuild() &&
2954 TransTemplate == Template)
2955 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002956
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002957 return TemplateName(TransTemplate);
2958 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002959
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002960 if (SubstTemplateTemplateParmPackStorage *SubstPack
2961 = Name.getAsSubstTemplateTemplateParmPack()) {
2962 TemplateTemplateParmDecl *TransParam
2963 = cast_or_null<TemplateTemplateParmDecl>(
2964 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2965 if (!TransParam)
2966 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002967
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002968 if (!getDerived().AlwaysRebuild() &&
2969 TransParam == SubstPack->getParameterPack())
2970 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002971
2972 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002973 SubstPack->getArgumentPack());
2974 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002975
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002976 // These should be getting filtered out before they reach the AST.
2977 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002978}
2979
2980template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002981void TreeTransform<Derived>::InventTemplateArgumentLoc(
2982 const TemplateArgument &Arg,
2983 TemplateArgumentLoc &Output) {
2984 SourceLocation Loc = getDerived().getBaseLocation();
2985 switch (Arg.getKind()) {
2986 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002987 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002988 break;
2989
2990 case TemplateArgument::Type:
2991 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002992 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002993
John McCall833ca992009-10-29 08:12:44 +00002994 break;
2995
Douglas Gregor788cd062009-11-11 01:00:40 +00002996 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002997 case TemplateArgument::TemplateExpansion: {
2998 NestedNameSpecifierLocBuilder Builder;
2999 TemplateName Template = Arg.getAsTemplate();
3000 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3001 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3002 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3003 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003004
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003005 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003006 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003007 Builder.getWithLocInContext(SemaRef.Context),
3008 Loc);
3009 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003010 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003011 Builder.getWithLocInContext(SemaRef.Context),
3012 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003013
Douglas Gregor788cd062009-11-11 01:00:40 +00003014 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003015 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003016
John McCall833ca992009-10-29 08:12:44 +00003017 case TemplateArgument::Expression:
3018 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3019 break;
3020
3021 case TemplateArgument::Declaration:
3022 case TemplateArgument::Integral:
3023 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003024 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003025 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003026 break;
3027 }
3028}
3029
3030template<typename Derived>
3031bool TreeTransform<Derived>::TransformTemplateArgument(
3032 const TemplateArgumentLoc &Input,
3033 TemplateArgumentLoc &Output) {
3034 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003035 switch (Arg.getKind()) {
3036 case TemplateArgument::Null:
3037 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003038 case TemplateArgument::Pack:
3039 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003040 case TemplateArgument::NullPtr:
3041 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003042
Douglas Gregor670444e2009-08-04 22:27:00 +00003043 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003044 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003045 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003046 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003047
3048 DI = getDerived().TransformType(DI);
3049 if (!DI) return true;
3050
3051 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3052 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003053 }
Mike Stump1eb44332009-09-09 15:08:12 +00003054
Douglas Gregor788cd062009-11-11 01:00:40 +00003055 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003056 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3057 if (QualifierLoc) {
3058 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3059 if (!QualifierLoc)
3060 return true;
3061 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003062
Douglas Gregor1d752d72011-03-02 18:46:51 +00003063 CXXScopeSpec SS;
3064 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003065 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003066 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3067 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003068 if (Template.isNull())
3069 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003070
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003071 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003072 Input.getTemplateNameLoc());
3073 return false;
3074 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003075
3076 case TemplateArgument::TemplateExpansion:
3077 llvm_unreachable("Caller should expand pack expansions");
3078
Douglas Gregor670444e2009-08-04 22:27:00 +00003079 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003080 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003081 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003082 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003083
John McCall833ca992009-10-29 08:12:44 +00003084 Expr *InputExpr = Input.getSourceExpression();
3085 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3086
Chris Lattner223de242011-04-25 20:37:58 +00003087 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003088 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003089 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003090 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003091 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003092 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003093 }
Mike Stump1eb44332009-09-09 15:08:12 +00003094
Douglas Gregor670444e2009-08-04 22:27:00 +00003095 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003096 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003097}
3098
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003099/// \brief Iterator adaptor that invents template argument location information
3100/// for each of the template arguments in its underlying iterator.
3101template<typename Derived, typename InputIterator>
3102class TemplateArgumentLocInventIterator {
3103 TreeTransform<Derived> &Self;
3104 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003105
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003106public:
3107 typedef TemplateArgumentLoc value_type;
3108 typedef TemplateArgumentLoc reference;
3109 typedef typename std::iterator_traits<InputIterator>::difference_type
3110 difference_type;
3111 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003112
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003113 class pointer {
3114 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003116 public:
3117 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003118
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003119 const TemplateArgumentLoc *operator->() const { return &Arg; }
3120 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003121
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003122 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003123
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003124 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3125 InputIterator Iter)
3126 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003127
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003128 TemplateArgumentLocInventIterator &operator++() {
3129 ++Iter;
3130 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003132
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003133 TemplateArgumentLocInventIterator operator++(int) {
3134 TemplateArgumentLocInventIterator Old(*this);
3135 ++(*this);
3136 return Old;
3137 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003138
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003139 reference operator*() const {
3140 TemplateArgumentLoc Result;
3141 Self.InventTemplateArgumentLoc(*Iter, Result);
3142 return Result;
3143 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003144
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003145 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3148 const TemplateArgumentLocInventIterator &Y) {
3149 return X.Iter == Y.Iter;
3150 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003151
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003152 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3153 const TemplateArgumentLocInventIterator &Y) {
3154 return X.Iter != Y.Iter;
3155 }
3156};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003157
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003158template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003159template<typename InputIterator>
3160bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3161 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003162 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003163 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003164 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003166
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003167 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3168 // Unpack argument packs, which we translate them into separate
3169 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003170 // FIXME: We could do much better if we could guarantee that the
3171 // TemplateArgumentLocInfo for the pack expansion would be usable for
3172 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003173 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003174 TemplateArgument::pack_iterator>
3175 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003176 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003177 In.getArgument().pack_begin()),
3178 PackLocIterator(*this,
3179 In.getArgument().pack_end()),
3180 Outputs))
3181 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003183 continue;
3184 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003185
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003186 if (In.getArgument().isPackExpansion()) {
3187 // We have a pack expansion, for which we will be substituting into
3188 // the pattern.
3189 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003190 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003191 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003192 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003193 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194
Chris Lattner686775d2011-07-20 06:58:45 +00003195 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003196 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3197 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003198
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003199 // Determine whether the set of unexpanded parameter packs can and should
3200 // be expanded.
3201 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003202 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003203 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003204 if (getDerived().TryExpandParameterPacks(Ellipsis,
3205 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003206 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003207 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003208 RetainExpansion,
3209 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003210 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003211
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003212 if (!Expand) {
3213 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003214 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003215 // expansion.
3216 TemplateArgumentLoc OutPattern;
3217 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3218 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3219 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003220
Douglas Gregorcded4f62011-01-14 17:04:44 +00003221 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3222 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003223 if (Out.getArgument().isNull())
3224 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003226 Outputs.addArgument(Out);
3227 continue;
3228 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003229
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003230 // The transform has determined that we should perform an elementwise
3231 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003232 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003233 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3234
3235 if (getDerived().TransformTemplateArgument(Pattern, Out))
3236 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003237
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003238 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003239 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3240 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003241 if (Out.getArgument().isNull())
3242 return true;
3243 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003244
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003245 Outputs.addArgument(Out);
3246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003247
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003248 // If we're supposed to retain a pack expansion, do so by temporarily
3249 // forgetting the partially-substituted parameter pack.
3250 if (RetainExpansion) {
3251 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003252
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003253 if (getDerived().TransformTemplateArgument(Pattern, Out))
3254 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003255
Douglas Gregorcded4f62011-01-14 17:04:44 +00003256 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3257 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003258 if (Out.getArgument().isNull())
3259 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003260
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003261 Outputs.addArgument(Out);
3262 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003263
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003264 continue;
3265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003266
3267 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003268 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003269 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003270
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003271 Outputs.addArgument(Out);
3272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003273
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003274 return false;
3275
3276}
3277
Douglas Gregor577f75a2009-08-04 16:50:30 +00003278//===----------------------------------------------------------------------===//
3279// Type transformation
3280//===----------------------------------------------------------------------===//
3281
3282template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003283QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003284 if (getDerived().AlreadyTransformed(T))
3285 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003286
John McCalla2becad2009-10-21 00:40:46 +00003287 // Temporary workaround. All of these transformations should
3288 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003289 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3290 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003291
John McCall43fed0d2010-11-12 08:19:04 +00003292 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003293
John McCalla2becad2009-10-21 00:40:46 +00003294 if (!NewDI)
3295 return QualType();
3296
3297 return NewDI->getType();
3298}
3299
3300template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003301TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003302 // Refine the base location to the type's location.
3303 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3304 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003305 if (getDerived().AlreadyTransformed(DI->getType()))
3306 return DI;
3307
3308 TypeLocBuilder TLB;
3309
3310 TypeLoc TL = DI->getTypeLoc();
3311 TLB.reserve(TL.getFullDataSize());
3312
John McCall43fed0d2010-11-12 08:19:04 +00003313 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003314 if (Result.isNull())
3315 return 0;
3316
John McCalla93c9342009-12-07 02:54:59 +00003317 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003318}
3319
3320template<typename Derived>
3321QualType
John McCall43fed0d2010-11-12 08:19:04 +00003322TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003323 switch (T.getTypeLocClass()) {
3324#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003325#define TYPELOC(CLASS, PARENT) \
3326 case TypeLoc::CLASS: \
3327 return getDerived().Transform##CLASS##Type(TLB, \
3328 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003329#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003330 }
Mike Stump1eb44332009-09-09 15:08:12 +00003331
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003332 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003333}
3334
3335/// FIXME: By default, this routine adds type qualifiers only to types
3336/// that can have qualifiers, and silently suppresses those qualifiers
3337/// that are not permitted (e.g., qualifiers on reference or function
3338/// types). This is the right thing for template instantiation, but
3339/// probably not for other clients.
3340template<typename Derived>
3341QualType
3342TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003343 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003344 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003345
John McCall43fed0d2010-11-12 08:19:04 +00003346 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003347 if (Result.isNull())
3348 return QualType();
3349
3350 // Silently suppress qualifiers if the result type can't be qualified.
3351 // FIXME: this is the right thing for template instantiation, but
3352 // probably not for other clients.
3353 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003354 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003355
John McCallf85e1932011-06-15 23:02:42 +00003356 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003357 // resulting type.
3358 if (Quals.hasObjCLifetime()) {
3359 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3360 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003361 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003362 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003363 // A lifetime qualifier applied to a substituted template parameter
3364 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003365 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003366 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003367 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3368 QualType Replacement = SubstTypeParam->getReplacementType();
3369 Qualifiers Qs = Replacement.getQualifiers();
3370 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003371 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003372 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3373 Qs);
3374 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003375 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003376 Replacement);
3377 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003378 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3379 // 'auto' types behave the same way as template parameters.
3380 QualType Deduced = AutoTy->getDeducedType();
3381 Qualifiers Qs = Deduced.getQualifiers();
3382 Qs.removeObjCLifetime();
3383 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3384 Qs);
3385 Result = SemaRef.Context.getAutoType(Deduced);
3386 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003387 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003388 // Otherwise, complain about the addition of a qualifier to an
3389 // already-qualified type.
3390 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003391 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003392 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
Douglas Gregore559ca12011-06-17 22:11:49 +00003394 Quals.removeObjCLifetime();
3395 }
3396 }
3397 }
John McCall28654742010-06-05 06:41:15 +00003398 if (!Quals.empty()) {
3399 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smith9807a2e2013-03-27 23:36:39 +00003400 // BuildQualifiedType might not add qualifiers if they are invalid.
3401 if (Result.hasLocalQualifiers())
3402 TLB.push<QualifiedTypeLoc>(Result);
John McCall28654742010-06-05 06:41:15 +00003403 // No location information to preserve.
3404 }
John McCalla2becad2009-10-21 00:40:46 +00003405
3406 return Result;
3407}
3408
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003409template<typename Derived>
3410TypeLoc
3411TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3412 QualType ObjectType,
3413 NamedDecl *UnqualLookup,
3414 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003415 QualType T = TL.getType();
3416 if (getDerived().AlreadyTransformed(T))
3417 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003418
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003419 TypeLocBuilder TLB;
3420 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003421
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003422 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003423 TemplateSpecializationTypeLoc SpecTL =
3424 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003425
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003426 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003427 getDerived().TransformTemplateName(SS,
3428 SpecTL.getTypePtr()->getTemplateName(),
3429 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003430 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003431 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003432 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003433
3434 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003435 Template);
3436 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003437 DependentTemplateSpecializationTypeLoc SpecTL =
3438 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003439
Douglas Gregora88f09f2011-02-28 17:23:35 +00003440 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003441 = getDerived().RebuildTemplateName(SS,
3442 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003443 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003444 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003445 if (Template.isNull())
3446 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003447
3448 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003449 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003450 Template,
3451 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003452 } else {
3453 // Nothing special needs to be done for these.
3454 Result = getDerived().TransformType(TLB, TL);
3455 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003456
3457 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003458 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003459
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003460 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3461}
3462
Douglas Gregorb71d8212011-03-02 18:32:08 +00003463template<typename Derived>
3464TypeSourceInfo *
3465TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3466 QualType ObjectType,
3467 NamedDecl *UnqualLookup,
3468 CXXScopeSpec &SS) {
3469 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003470
Douglas Gregorb71d8212011-03-02 18:32:08 +00003471 QualType T = TSInfo->getType();
3472 if (getDerived().AlreadyTransformed(T))
3473 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003474
Douglas Gregorb71d8212011-03-02 18:32:08 +00003475 TypeLocBuilder TLB;
3476 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003477
Douglas Gregorb71d8212011-03-02 18:32:08 +00003478 TypeLoc TL = TSInfo->getTypeLoc();
3479 if (isa<TemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003480 TemplateSpecializationTypeLoc SpecTL =
3481 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003482
Douglas Gregorb71d8212011-03-02 18:32:08 +00003483 TemplateName Template
3484 = getDerived().TransformTemplateName(SS,
3485 SpecTL.getTypePtr()->getTemplateName(),
3486 SpecTL.getTemplateNameLoc(),
3487 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003488 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003489 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003490
3491 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 Template);
3493 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie39e6ab42013-02-18 22:06:02 +00003494 DependentTemplateSpecializationTypeLoc SpecTL =
3495 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003496
Douglas Gregorb71d8212011-03-02 18:32:08 +00003497 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003498 = getDerived().RebuildTemplateName(SS,
3499 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003500 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003501 ObjectType, UnqualLookup);
3502 if (Template.isNull())
3503 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003504
3505 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003506 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003507 Template,
3508 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003509 } else {
3510 // Nothing special needs to be done for these.
3511 Result = getDerived().TransformType(TLB, TL);
3512 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003513
3514 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003515 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003516
Douglas Gregorb71d8212011-03-02 18:32:08 +00003517 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3518}
3519
John McCalla2becad2009-10-21 00:40:46 +00003520template <class TyLoc> static inline
3521QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3522 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3523 NewT.setNameLoc(T.getNameLoc());
3524 return T.getType();
3525}
3526
John McCalla2becad2009-10-21 00:40:46 +00003527template<typename Derived>
3528QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003529 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003530 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3531 NewT.setBuiltinLoc(T.getBuiltinLoc());
3532 if (T.needsExtraLocalData())
3533 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3534 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535}
Mike Stump1eb44332009-09-09 15:08:12 +00003536
Douglas Gregor577f75a2009-08-04 16:50:30 +00003537template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003538QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003539 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003540 // FIXME: recurse?
3541 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003542}
Mike Stump1eb44332009-09-09 15:08:12 +00003543
Douglas Gregor577f75a2009-08-04 16:50:30 +00003544template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003545QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003546 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003547 QualType PointeeType
3548 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003549 if (PointeeType.isNull())
3550 return QualType();
3551
3552 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003553 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003554 // A dependent pointer type 'T *' has is being transformed such
3555 // that an Objective-C class type is being replaced for 'T'. The
3556 // resulting pointer type is an ObjCObjectPointerType, not a
3557 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003558 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003559
John McCallc12c5bb2010-05-15 11:32:37 +00003560 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3561 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003562 return Result;
3563 }
John McCall43fed0d2010-11-12 08:19:04 +00003564
Douglas Gregor92e986e2010-04-22 16:44:27 +00003565 if (getDerived().AlwaysRebuild() ||
3566 PointeeType != TL.getPointeeLoc().getType()) {
3567 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3568 if (Result.isNull())
3569 return QualType();
3570 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003571
John McCallf85e1932011-06-15 23:02:42 +00003572 // Objective-C ARC can add lifetime qualifiers to the type that we're
3573 // pointing to.
3574 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003575
Douglas Gregor92e986e2010-04-22 16:44:27 +00003576 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3577 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003578 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579}
Mike Stump1eb44332009-09-09 15:08:12 +00003580
3581template<typename Derived>
3582QualType
John McCalla2becad2009-10-21 00:40:46 +00003583TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003584 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003585 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003586 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3587 if (PointeeType.isNull())
3588 return QualType();
3589
3590 QualType Result = TL.getType();
3591 if (getDerived().AlwaysRebuild() ||
3592 PointeeType != TL.getPointeeLoc().getType()) {
3593 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003594 TL.getSigilLoc());
3595 if (Result.isNull())
3596 return QualType();
3597 }
3598
Douglas Gregor39968ad2010-04-22 16:50:51 +00003599 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003600 NewT.setSigilLoc(TL.getSigilLoc());
3601 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003602}
3603
John McCall85737a72009-10-30 00:06:24 +00003604/// Transforms a reference type. Note that somewhat paradoxically we
3605/// don't care whether the type itself is an l-value type or an r-value
3606/// type; we only care if the type was *written* as an l-value type
3607/// or an r-value type.
3608template<typename Derived>
3609QualType
3610TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003611 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003612 const ReferenceType *T = TL.getTypePtr();
3613
3614 // Note that this works with the pointee-as-written.
3615 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3616 if (PointeeType.isNull())
3617 return QualType();
3618
3619 QualType Result = TL.getType();
3620 if (getDerived().AlwaysRebuild() ||
3621 PointeeType != T->getPointeeTypeAsWritten()) {
3622 Result = getDerived().RebuildReferenceType(PointeeType,
3623 T->isSpelledAsLValue(),
3624 TL.getSigilLoc());
3625 if (Result.isNull())
3626 return QualType();
3627 }
3628
John McCallf85e1932011-06-15 23:02:42 +00003629 // Objective-C ARC can add lifetime qualifiers to the type that we're
3630 // referring to.
3631 TLB.TypeWasModifiedSafely(
3632 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3633
John McCall85737a72009-10-30 00:06:24 +00003634 // r-value references can be rebuilt as l-value references.
3635 ReferenceTypeLoc NewTL;
3636 if (isa<LValueReferenceType>(Result))
3637 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3638 else
3639 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3640 NewTL.setSigilLoc(TL.getSigilLoc());
3641
3642 return Result;
3643}
3644
Mike Stump1eb44332009-09-09 15:08:12 +00003645template<typename Derived>
3646QualType
John McCalla2becad2009-10-21 00:40:46 +00003647TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003648 LValueReferenceTypeLoc TL) {
3649 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003650}
3651
Mike Stump1eb44332009-09-09 15:08:12 +00003652template<typename Derived>
3653QualType
John McCalla2becad2009-10-21 00:40:46 +00003654TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003655 RValueReferenceTypeLoc TL) {
3656 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003657}
Mike Stump1eb44332009-09-09 15:08:12 +00003658
Douglas Gregor577f75a2009-08-04 16:50:30 +00003659template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003660QualType
John McCalla2becad2009-10-21 00:40:46 +00003661TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003662 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003663 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003664 if (PointeeType.isNull())
3665 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003666
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003667 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3668 TypeSourceInfo* NewClsTInfo = 0;
3669 if (OldClsTInfo) {
3670 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3671 if (!NewClsTInfo)
3672 return QualType();
3673 }
3674
3675 const MemberPointerType *T = TL.getTypePtr();
3676 QualType OldClsType = QualType(T->getClass(), 0);
3677 QualType NewClsType;
3678 if (NewClsTInfo)
3679 NewClsType = NewClsTInfo->getType();
3680 else {
3681 NewClsType = getDerived().TransformType(OldClsType);
3682 if (NewClsType.isNull())
3683 return QualType();
3684 }
Mike Stump1eb44332009-09-09 15:08:12 +00003685
John McCalla2becad2009-10-21 00:40:46 +00003686 QualType Result = TL.getType();
3687 if (getDerived().AlwaysRebuild() ||
3688 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003689 NewClsType != OldClsType) {
3690 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003691 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003692 if (Result.isNull())
3693 return QualType();
3694 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695
John McCalla2becad2009-10-21 00:40:46 +00003696 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3697 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003698 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003699
3700 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003701}
3702
Mike Stump1eb44332009-09-09 15:08:12 +00003703template<typename Derived>
3704QualType
John McCalla2becad2009-10-21 00:40:46 +00003705TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003706 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003707 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003708 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003709 if (ElementType.isNull())
3710 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003711
John McCalla2becad2009-10-21 00:40:46 +00003712 QualType Result = TL.getType();
3713 if (getDerived().AlwaysRebuild() ||
3714 ElementType != T->getElementType()) {
3715 Result = getDerived().RebuildConstantArrayType(ElementType,
3716 T->getSizeModifier(),
3717 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003718 T->getIndexTypeCVRQualifiers(),
3719 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003720 if (Result.isNull())
3721 return QualType();
3722 }
Eli Friedman457a3772012-01-25 22:19:07 +00003723
3724 // We might have either a ConstantArrayType or a VariableArrayType now:
3725 // a ConstantArrayType is allowed to have an element type which is a
3726 // VariableArrayType if the type is dependent. Fortunately, all array
3727 // types have the same location layout.
3728 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003729 NewTL.setLBracketLoc(TL.getLBracketLoc());
3730 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003731
John McCalla2becad2009-10-21 00:40:46 +00003732 Expr *Size = TL.getSizeExpr();
3733 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003734 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3735 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003736 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003737 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003738 }
3739 NewTL.setSizeExpr(Size);
3740
3741 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742}
Mike Stump1eb44332009-09-09 15:08:12 +00003743
Douglas Gregor577f75a2009-08-04 16:50:30 +00003744template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003745QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003746 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003747 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003748 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003749 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003750 if (ElementType.isNull())
3751 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003752
John McCalla2becad2009-10-21 00:40:46 +00003753 QualType Result = TL.getType();
3754 if (getDerived().AlwaysRebuild() ||
3755 ElementType != T->getElementType()) {
3756 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003757 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003758 T->getIndexTypeCVRQualifiers(),
3759 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003760 if (Result.isNull())
3761 return QualType();
3762 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003763
John McCalla2becad2009-10-21 00:40:46 +00003764 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3765 NewTL.setLBracketLoc(TL.getLBracketLoc());
3766 NewTL.setRBracketLoc(TL.getRBracketLoc());
3767 NewTL.setSizeExpr(0);
3768
3769 return Result;
3770}
3771
3772template<typename Derived>
3773QualType
3774TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003775 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003776 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003777 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3778 if (ElementType.isNull())
3779 return QualType();
3780
John McCall60d7b3a2010-08-24 06:29:42 +00003781 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003782 = getDerived().TransformExpr(T->getSizeExpr());
3783 if (SizeResult.isInvalid())
3784 return QualType();
3785
John McCall9ae2f072010-08-23 23:25:46 +00003786 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003787
3788 QualType Result = TL.getType();
3789 if (getDerived().AlwaysRebuild() ||
3790 ElementType != T->getElementType() ||
3791 Size != T->getSizeExpr()) {
3792 Result = getDerived().RebuildVariableArrayType(ElementType,
3793 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003794 Size,
John McCalla2becad2009-10-21 00:40:46 +00003795 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003796 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003797 if (Result.isNull())
3798 return QualType();
3799 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003800
John McCalla2becad2009-10-21 00:40:46 +00003801 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3802 NewTL.setLBracketLoc(TL.getLBracketLoc());
3803 NewTL.setRBracketLoc(TL.getRBracketLoc());
3804 NewTL.setSizeExpr(Size);
3805
3806 return Result;
3807}
3808
3809template<typename Derived>
3810QualType
3811TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003812 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003813 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003814 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3815 if (ElementType.isNull())
3816 return QualType();
3817
Richard Smithf6702a32011-12-20 02:08:33 +00003818 // Array bounds are constant expressions.
3819 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3820 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003821
John McCall3b657512011-01-19 10:06:00 +00003822 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3823 Expr *origSize = TL.getSizeExpr();
3824 if (!origSize) origSize = T->getSizeExpr();
3825
3826 ExprResult sizeResult
3827 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003828 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003829 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003830 return QualType();
3831
John McCall3b657512011-01-19 10:06:00 +00003832 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003833
3834 QualType Result = TL.getType();
3835 if (getDerived().AlwaysRebuild() ||
3836 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003837 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003838 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3839 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003840 size,
John McCalla2becad2009-10-21 00:40:46 +00003841 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003842 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003843 if (Result.isNull())
3844 return QualType();
3845 }
John McCalla2becad2009-10-21 00:40:46 +00003846
3847 // We might have any sort of array type now, but fortunately they
3848 // all have the same location layout.
3849 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3850 NewTL.setLBracketLoc(TL.getLBracketLoc());
3851 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003852 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003853
3854 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003855}
Mike Stump1eb44332009-09-09 15:08:12 +00003856
3857template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003859 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003860 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003861 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003862
3863 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003864 QualType ElementType = getDerived().TransformType(T->getElementType());
3865 if (ElementType.isNull())
3866 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003867
Richard Smithf6702a32011-12-20 02:08:33 +00003868 // Vector sizes are constant expressions.
3869 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3870 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003871
John McCall60d7b3a2010-08-24 06:29:42 +00003872 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003873 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874 if (Size.isInvalid())
3875 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003876
John McCalla2becad2009-10-21 00:40:46 +00003877 QualType Result = TL.getType();
3878 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003879 ElementType != T->getElementType() ||
3880 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003881 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003882 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003883 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003884 if (Result.isNull())
3885 return QualType();
3886 }
John McCalla2becad2009-10-21 00:40:46 +00003887
3888 // Result might be dependent or not.
3889 if (isa<DependentSizedExtVectorType>(Result)) {
3890 DependentSizedExtVectorTypeLoc NewTL
3891 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3892 NewTL.setNameLoc(TL.getNameLoc());
3893 } else {
3894 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3895 NewTL.setNameLoc(TL.getNameLoc());
3896 }
3897
3898 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003899}
Mike Stump1eb44332009-09-09 15:08:12 +00003900
3901template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003902QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003903 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003904 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003905 QualType ElementType = getDerived().TransformType(T->getElementType());
3906 if (ElementType.isNull())
3907 return QualType();
3908
John McCalla2becad2009-10-21 00:40:46 +00003909 QualType Result = TL.getType();
3910 if (getDerived().AlwaysRebuild() ||
3911 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003912 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003913 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003914 if (Result.isNull())
3915 return QualType();
3916 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003917
John McCalla2becad2009-10-21 00:40:46 +00003918 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3919 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003920
John McCalla2becad2009-10-21 00:40:46 +00003921 return Result;
3922}
3923
3924template<typename Derived>
3925QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003926 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003927 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003928 QualType ElementType = getDerived().TransformType(T->getElementType());
3929 if (ElementType.isNull())
3930 return QualType();
3931
3932 QualType Result = TL.getType();
3933 if (getDerived().AlwaysRebuild() ||
3934 ElementType != T->getElementType()) {
3935 Result = getDerived().RebuildExtVectorType(ElementType,
3936 T->getNumElements(),
3937 /*FIXME*/ SourceLocation());
3938 if (Result.isNull())
3939 return QualType();
3940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003941
John McCalla2becad2009-10-21 00:40:46 +00003942 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3943 NewTL.setNameLoc(TL.getNameLoc());
3944
3945 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003946}
Mike Stump1eb44332009-09-09 15:08:12 +00003947
David Blaikiedc84cd52013-02-20 22:23:23 +00003948template <typename Derived>
3949ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
3950 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
3951 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003952 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003953 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003954
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003955 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003956 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003957 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003958 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00003959 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003960
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003961 TypeLocBuilder TLB;
3962 TypeLoc NewTL = OldDI->getTypeLoc();
3963 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003964
3965 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003966 OldExpansionTL.getPatternLoc());
3967 if (Result.isNull())
3968 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003969
3970 Result = RebuildPackExpansionType(Result,
3971 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003972 OldExpansionTL.getEllipsisLoc(),
3973 NumExpansions);
3974 if (Result.isNull())
3975 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003976
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003977 PackExpansionTypeLoc NewExpansionTL
3978 = TLB.push<PackExpansionTypeLoc>(Result);
3979 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3980 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3981 } else
3982 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003983 if (!NewDI)
3984 return 0;
3985
John McCallfb44de92011-05-01 22:35:37 +00003986 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003987 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003988
3989 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3990 OldParm->getDeclContext(),
3991 OldParm->getInnerLocStart(),
3992 OldParm->getLocation(),
3993 OldParm->getIdentifier(),
3994 NewDI->getType(),
3995 NewDI,
3996 OldParm->getStorageClass(),
John McCallfb44de92011-05-01 22:35:37 +00003997 /* DefArg */ NULL);
3998 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3999 OldParm->getFunctionScopeIndex() + indexAdjustment);
4000 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004001}
4002
4003template<typename Derived>
4004bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004005 TransformFunctionTypeParams(SourceLocation Loc,
4006 ParmVarDecl **Params, unsigned NumParams,
4007 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004008 SmallVectorImpl<QualType> &OutParamTypes,
4009 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004010 int indexAdjustment = 0;
4011
Douglas Gregora009b592011-01-07 00:20:55 +00004012 for (unsigned i = 0; i != NumParams; ++i) {
4013 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004014 assert(OldParm->getFunctionScopeIndex() == i);
4015
David Blaikiedc84cd52013-02-20 22:23:23 +00004016 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004017 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004018 if (OldParm->isParameterPack()) {
4019 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004020 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004021
Douglas Gregor603cfb42011-01-05 23:12:31 +00004022 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004023 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004024 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004025 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4026 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004027 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4028
Douglas Gregor603cfb42011-01-05 23:12:31 +00004029 // Determine whether we should expand the parameter packs.
4030 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004031 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004032 Optional<unsigned> OrigNumExpansions =
4033 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004034 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004035 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4036 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004037 Unexpanded,
4038 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004039 RetainExpansion,
4040 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004041 return true;
4042 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004043
Douglas Gregor603cfb42011-01-05 23:12:31 +00004044 if (ShouldExpand) {
4045 // Expand the function parameter pack into multiple, separate
4046 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004047 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004048 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004049 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004050 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004051 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004052 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004053 OrigNumExpansions,
4054 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004055 if (!NewParm)
4056 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004057
Douglas Gregora009b592011-01-07 00:20:55 +00004058 OutParamTypes.push_back(NewParm->getType());
4059 if (PVars)
4060 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004061 }
Douglas Gregord3731192011-01-10 07:32:04 +00004062
4063 // If we're supposed to retain a pack expansion, do so by temporarily
4064 // forgetting the partially-substituted parameter pack.
4065 if (RetainExpansion) {
4066 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004067 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004068 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004069 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004070 OrigNumExpansions,
4071 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004072 if (!NewParm)
4073 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004074
Douglas Gregord3731192011-01-10 07:32:04 +00004075 OutParamTypes.push_back(NewParm->getType());
4076 if (PVars)
4077 PVars->push_back(NewParm);
4078 }
4079
John McCallfb44de92011-05-01 22:35:37 +00004080 // The next parameter should have the same adjustment as the
4081 // last thing we pushed, but we post-incremented indexAdjustment
4082 // on every push. Also, if we push nothing, the adjustment should
4083 // go down by one.
4084 indexAdjustment--;
4085
Douglas Gregor603cfb42011-01-05 23:12:31 +00004086 // We're done with the pack expansion.
4087 continue;
4088 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004089
4090 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004091 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004092 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4093 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004094 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004095 NumExpansions,
4096 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004097 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004098 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004099 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004100 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004101
John McCall21ef0fa2010-03-11 09:03:00 +00004102 if (!NewParm)
4103 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004104
Douglas Gregora009b592011-01-07 00:20:55 +00004105 OutParamTypes.push_back(NewParm->getType());
4106 if (PVars)
4107 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004108 continue;
4109 }
John McCall21ef0fa2010-03-11 09:03:00 +00004110
4111 // Deal with the possibility that we don't have a parameter
4112 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004113 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004114 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004115 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004116 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004117 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004118 = dyn_cast<PackExpansionType>(OldType)) {
4119 // We have a function parameter pack that may need to be expanded.
4120 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004121 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004122 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004123
Douglas Gregor603cfb42011-01-05 23:12:31 +00004124 // Determine whether we should expand the parameter packs.
4125 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004126 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004127 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004128 Unexpanded,
4129 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004130 RetainExpansion,
4131 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004132 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004133 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004134
Douglas Gregor603cfb42011-01-05 23:12:31 +00004135 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004136 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004137 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004138 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004139 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4140 QualType NewType = getDerived().TransformType(Pattern);
4141 if (NewType.isNull())
4142 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004143
Douglas Gregora009b592011-01-07 00:20:55 +00004144 OutParamTypes.push_back(NewType);
4145 if (PVars)
4146 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004148
Douglas Gregor603cfb42011-01-05 23:12:31 +00004149 // We're done with the pack expansion.
4150 continue;
4151 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004152
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004153 // If we're supposed to retain a pack expansion, do so by temporarily
4154 // forgetting the partially-substituted parameter pack.
4155 if (RetainExpansion) {
4156 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4157 QualType NewType = getDerived().TransformType(Pattern);
4158 if (NewType.isNull())
4159 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004160
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004161 OutParamTypes.push_back(NewType);
4162 if (PVars)
4163 PVars->push_back(0);
4164 }
Douglas Gregord3731192011-01-10 07:32:04 +00004165
Chad Rosier4a9d7952012-08-08 18:46:20 +00004166 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004167 // expansion.
4168 OldType = Expansion->getPattern();
4169 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004170 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4171 NewType = getDerived().TransformType(OldType);
4172 } else {
4173 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004174 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004175
Douglas Gregor603cfb42011-01-05 23:12:31 +00004176 if (NewType.isNull())
4177 return true;
4178
4179 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004180 NewType = getSema().Context.getPackExpansionType(NewType,
4181 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004182
Douglas Gregora009b592011-01-07 00:20:55 +00004183 OutParamTypes.push_back(NewType);
4184 if (PVars)
4185 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004186 }
4187
John McCallfb44de92011-05-01 22:35:37 +00004188#ifndef NDEBUG
4189 if (PVars) {
4190 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4191 if (ParmVarDecl *parm = (*PVars)[i])
4192 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004193 }
John McCallfb44de92011-05-01 22:35:37 +00004194#endif
4195
4196 return false;
4197}
John McCall21ef0fa2010-03-11 09:03:00 +00004198
4199template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004200QualType
John McCalla2becad2009-10-21 00:40:46 +00004201TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004202 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004203 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4204}
4205
4206template<typename Derived>
4207QualType
4208TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4209 FunctionProtoTypeLoc TL,
4210 CXXRecordDecl *ThisContext,
4211 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004212 // Transform the parameters and return type.
4213 //
Richard Smithe6975e92012-04-17 00:58:00 +00004214 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004215 // When the function has a trailing return type, we instantiate the
4216 // parameters before the return type, since the return type can then refer
4217 // to the parameters themselves (via decltype, sizeof, etc.).
4218 //
Chris Lattner686775d2011-07-20 06:58:45 +00004219 SmallVector<QualType, 4> ParamTypes;
4220 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004221 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004222
Douglas Gregordab60ad2010-10-01 18:44:50 +00004223 QualType ResultType;
4224
Richard Smith9fbf3272012-08-14 22:51:13 +00004225 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004226 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004227 TL.getParmArray(),
4228 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004229 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004230 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004231 return QualType();
4232
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004233 {
4234 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004235 // If a declaration declares a member function or member function
4236 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004237 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004238 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004239 // declarator.
4240 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004241
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004242 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4243 if (ResultType.isNull())
4244 return QualType();
4245 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004246 }
4247 else {
4248 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4249 if (ResultType.isNull())
4250 return QualType();
4251
Chad Rosier4a9d7952012-08-08 18:46:20 +00004252 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004253 TL.getParmArray(),
4254 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004255 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004256 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004257 return QualType();
4258 }
4259
Richard Smithe6975e92012-04-17 00:58:00 +00004260 // FIXME: Need to transform the exception-specification too.
4261
John McCalla2becad2009-10-21 00:40:46 +00004262 QualType Result = TL.getType();
4263 if (getDerived().AlwaysRebuild() ||
4264 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004265 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004266 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004267 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004268 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004269 if (Result.isNull())
4270 return QualType();
4271 }
Mike Stump1eb44332009-09-09 15:08:12 +00004272
John McCalla2becad2009-10-21 00:40:46 +00004273 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004274 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004275 NewTL.setLParenLoc(TL.getLParenLoc());
4276 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004277 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004278 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4279 NewTL.setArg(i, ParamDecls[i]);
4280
4281 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004282}
Mike Stump1eb44332009-09-09 15:08:12 +00004283
Douglas Gregor577f75a2009-08-04 16:50:30 +00004284template<typename Derived>
4285QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004286 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004287 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004288 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004289 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4290 if (ResultType.isNull())
4291 return QualType();
4292
4293 QualType Result = TL.getType();
4294 if (getDerived().AlwaysRebuild() ||
4295 ResultType != T->getResultType())
4296 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4297
4298 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004299 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004300 NewTL.setLParenLoc(TL.getLParenLoc());
4301 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004302 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004303
4304 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004305}
Mike Stump1eb44332009-09-09 15:08:12 +00004306
John McCalled976492009-12-04 22:46:56 +00004307template<typename Derived> QualType
4308TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004309 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004310 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004311 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004312 if (!D)
4313 return QualType();
4314
4315 QualType Result = TL.getType();
4316 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4317 Result = getDerived().RebuildUnresolvedUsingType(D);
4318 if (Result.isNull())
4319 return QualType();
4320 }
4321
4322 // We might get an arbitrary type spec type back. We should at
4323 // least always get a type spec type, though.
4324 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4325 NewTL.setNameLoc(TL.getNameLoc());
4326
4327 return Result;
4328}
4329
Douglas Gregor577f75a2009-08-04 16:50:30 +00004330template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004331QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004332 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004333 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004334 TypedefNameDecl *Typedef
4335 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4336 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004337 if (!Typedef)
4338 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004339
John McCalla2becad2009-10-21 00:40:46 +00004340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() ||
4342 Typedef != T->getDecl()) {
4343 Result = getDerived().RebuildTypedefType(Typedef);
4344 if (Result.isNull())
4345 return QualType();
4346 }
Mike Stump1eb44332009-09-09 15:08:12 +00004347
John McCalla2becad2009-10-21 00:40:46 +00004348 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4349 NewTL.setNameLoc(TL.getNameLoc());
4350
4351 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004352}
Mike Stump1eb44332009-09-09 15:08:12 +00004353
Douglas Gregor577f75a2009-08-04 16:50:30 +00004354template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004355QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004356 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004357 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004358 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4359 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004360
John McCall60d7b3a2010-08-24 06:29:42 +00004361 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004362 if (E.isInvalid())
4363 return QualType();
4364
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004365 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4366 if (E.isInvalid())
4367 return QualType();
4368
John McCalla2becad2009-10-21 00:40:46 +00004369 QualType Result = TL.getType();
4370 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004371 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004372 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004373 if (Result.isNull())
4374 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375 }
John McCalla2becad2009-10-21 00:40:46 +00004376 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004377
John McCalla2becad2009-10-21 00:40:46 +00004378 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004379 NewTL.setTypeofLoc(TL.getTypeofLoc());
4380 NewTL.setLParenLoc(TL.getLParenLoc());
4381 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004382
4383 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004384}
Mike Stump1eb44332009-09-09 15:08:12 +00004385
4386template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004387QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004388 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004389 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4390 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4391 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004392 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004393
John McCalla2becad2009-10-21 00:40:46 +00004394 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004395 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4396 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004397 if (Result.isNull())
4398 return QualType();
4399 }
Mike Stump1eb44332009-09-09 15:08:12 +00004400
John McCalla2becad2009-10-21 00:40:46 +00004401 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004402 NewTL.setTypeofLoc(TL.getTypeofLoc());
4403 NewTL.setLParenLoc(TL.getLParenLoc());
4404 NewTL.setRParenLoc(TL.getRParenLoc());
4405 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004406
4407 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004408}
Mike Stump1eb44332009-09-09 15:08:12 +00004409
4410template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004411QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004412 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004413 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004414
Douglas Gregor670444e2009-08-04 22:27:00 +00004415 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004416 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4417 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004418
John McCall60d7b3a2010-08-24 06:29:42 +00004419 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004420 if (E.isInvalid())
4421 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004422
Richard Smith76f3f692012-02-22 02:04:18 +00004423 E = getSema().ActOnDecltypeExpression(E.take());
4424 if (E.isInvalid())
4425 return QualType();
4426
John McCalla2becad2009-10-21 00:40:46 +00004427 QualType Result = TL.getType();
4428 if (getDerived().AlwaysRebuild() ||
4429 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004430 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004431 if (Result.isNull())
4432 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004433 }
John McCalla2becad2009-10-21 00:40:46 +00004434 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004435
John McCalla2becad2009-10-21 00:40:46 +00004436 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4437 NewTL.setNameLoc(TL.getNameLoc());
4438
4439 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004440}
4441
4442template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004443QualType TreeTransform<Derived>::TransformUnaryTransformType(
4444 TypeLocBuilder &TLB,
4445 UnaryTransformTypeLoc TL) {
4446 QualType Result = TL.getType();
4447 if (Result->isDependentType()) {
4448 const UnaryTransformType *T = TL.getTypePtr();
4449 QualType NewBase =
4450 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4451 Result = getDerived().RebuildUnaryTransformType(NewBase,
4452 T->getUTTKind(),
4453 TL.getKWLoc());
4454 if (Result.isNull())
4455 return QualType();
4456 }
4457
4458 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4459 NewTL.setKWLoc(TL.getKWLoc());
4460 NewTL.setParensRange(TL.getParensRange());
4461 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4462 return Result;
4463}
4464
4465template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004466QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4467 AutoTypeLoc TL) {
4468 const AutoType *T = TL.getTypePtr();
4469 QualType OldDeduced = T->getDeducedType();
4470 QualType NewDeduced;
4471 if (!OldDeduced.isNull()) {
4472 NewDeduced = getDerived().TransformType(OldDeduced);
4473 if (NewDeduced.isNull())
4474 return QualType();
4475 }
4476
4477 QualType Result = TL.getType();
4478 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4479 Result = getDerived().RebuildAutoType(NewDeduced);
4480 if (Result.isNull())
4481 return QualType();
4482 }
4483
4484 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4485 NewTL.setNameLoc(TL.getNameLoc());
4486
4487 return Result;
4488}
4489
4490template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004491QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004492 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004493 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004494 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004495 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4496 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004497 if (!Record)
4498 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004499
John McCalla2becad2009-10-21 00:40:46 +00004500 QualType Result = TL.getType();
4501 if (getDerived().AlwaysRebuild() ||
4502 Record != T->getDecl()) {
4503 Result = getDerived().RebuildRecordType(Record);
4504 if (Result.isNull())
4505 return QualType();
4506 }
Mike Stump1eb44332009-09-09 15:08:12 +00004507
John McCalla2becad2009-10-21 00:40:46 +00004508 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4509 NewTL.setNameLoc(TL.getNameLoc());
4510
4511 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004512}
Mike Stump1eb44332009-09-09 15:08:12 +00004513
4514template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004515QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004516 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004517 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004518 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004519 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4520 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004521 if (!Enum)
4522 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004523
John McCalla2becad2009-10-21 00:40:46 +00004524 QualType Result = TL.getType();
4525 if (getDerived().AlwaysRebuild() ||
4526 Enum != T->getDecl()) {
4527 Result = getDerived().RebuildEnumType(Enum);
4528 if (Result.isNull())
4529 return QualType();
4530 }
Mike Stump1eb44332009-09-09 15:08:12 +00004531
John McCalla2becad2009-10-21 00:40:46 +00004532 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4533 NewTL.setNameLoc(TL.getNameLoc());
4534
4535 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004536}
John McCall7da24312009-09-05 00:15:47 +00004537
John McCall3cb0ebd2010-03-10 03:28:59 +00004538template<typename Derived>
4539QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4540 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004541 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004542 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4543 TL.getTypePtr()->getDecl());
4544 if (!D) return QualType();
4545
4546 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4547 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4548 return T;
4549}
4550
Douglas Gregor577f75a2009-08-04 16:50:30 +00004551template<typename Derived>
4552QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004553 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004554 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004555 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004556}
4557
Mike Stump1eb44332009-09-09 15:08:12 +00004558template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004559QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004560 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004561 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004562 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004563
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004564 // Substitute into the replacement type, which itself might involve something
4565 // that needs to be transformed. This only tends to occur with default
4566 // template arguments of template template parameters.
4567 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4568 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4569 if (Replacement.isNull())
4570 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004571
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004572 // Always canonicalize the replacement type.
4573 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4574 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004575 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004576 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004577
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004578 // Propagate type-source information.
4579 SubstTemplateTypeParmTypeLoc NewTL
4580 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4581 NewTL.setNameLoc(TL.getNameLoc());
4582 return Result;
4583
John McCall49a832b2009-10-18 09:09:24 +00004584}
4585
4586template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004587QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4588 TypeLocBuilder &TLB,
4589 SubstTemplateTypeParmPackTypeLoc TL) {
4590 return TransformTypeSpecType(TLB, TL);
4591}
4592
4593template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004594QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004595 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004596 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004597 const TemplateSpecializationType *T = TL.getTypePtr();
4598
Douglas Gregor1d752d72011-03-02 18:46:51 +00004599 // The nested-name-specifier never matters in a TemplateSpecializationType,
4600 // because we can't have a dependent nested-name-specifier anyway.
4601 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004602 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004603 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4604 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004605 if (Template.isNull())
4606 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004607
John McCall43fed0d2010-11-12 08:19:04 +00004608 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4609}
4610
Eli Friedmanb001de72011-10-06 23:00:33 +00004611template<typename Derived>
4612QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4613 AtomicTypeLoc TL) {
4614 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4615 if (ValueType.isNull())
4616 return QualType();
4617
4618 QualType Result = TL.getType();
4619 if (getDerived().AlwaysRebuild() ||
4620 ValueType != TL.getValueLoc().getType()) {
4621 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4622 if (Result.isNull())
4623 return QualType();
4624 }
4625
4626 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4627 NewTL.setKWLoc(TL.getKWLoc());
4628 NewTL.setLParenLoc(TL.getLParenLoc());
4629 NewTL.setRParenLoc(TL.getRParenLoc());
4630
4631 return Result;
4632}
4633
Chad Rosier4a9d7952012-08-08 18:46:20 +00004634 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004635 /// container that provides a \c getArgLoc() member function.
4636 ///
4637 /// This iterator is intended to be used with the iterator form of
4638 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4639 template<typename ArgLocContainer>
4640 class TemplateArgumentLocContainerIterator {
4641 ArgLocContainer *Container;
4642 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004643
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004644 public:
4645 typedef TemplateArgumentLoc value_type;
4646 typedef TemplateArgumentLoc reference;
4647 typedef int difference_type;
4648 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004649
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004650 class pointer {
4651 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004652
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004653 public:
4654 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004655
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004656 const TemplateArgumentLoc *operator->() const {
4657 return &Arg;
4658 }
4659 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004660
4661
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004662 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004663
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004664 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4665 unsigned Index)
4666 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004667
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004668 TemplateArgumentLocContainerIterator &operator++() {
4669 ++Index;
4670 return *this;
4671 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004672
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 TemplateArgumentLocContainerIterator operator++(int) {
4674 TemplateArgumentLocContainerIterator Old(*this);
4675 ++(*this);
4676 return Old;
4677 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004678
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004679 TemplateArgumentLoc operator*() const {
4680 return Container->getArgLoc(Index);
4681 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004682
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004683 pointer operator->() const {
4684 return pointer(Container->getArgLoc(Index));
4685 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004686
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004687 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004688 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004689 return X.Container == Y.Container && X.Index == Y.Index;
4690 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004691
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004693 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004694 return !(X == Y);
4695 }
4696 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004697
4698
John McCall43fed0d2010-11-12 08:19:04 +00004699template <typename Derived>
4700QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4701 TypeLocBuilder &TLB,
4702 TemplateSpecializationTypeLoc TL,
4703 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004704 TemplateArgumentListInfo NewTemplateArgs;
4705 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4706 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004707 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4708 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004709 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004710 ArgIterator(TL, TL.getNumArgs()),
4711 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004712 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004713
John McCall833ca992009-10-29 08:12:44 +00004714 // FIXME: maybe don't rebuild if all the template arguments are the same.
4715
4716 QualType Result =
4717 getDerived().RebuildTemplateSpecializationType(Template,
4718 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004719 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004720
4721 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004722 // Specializations of template template parameters are represented as
4723 // TemplateSpecializationTypes, and substitution of type alias templates
4724 // within a dependent context can transform them into
4725 // DependentTemplateSpecializationTypes.
4726 if (isa<DependentTemplateSpecializationType>(Result)) {
4727 DependentTemplateSpecializationTypeLoc NewTL
4728 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004729 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004730 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004731 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004732 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004733 NewTL.setLAngleLoc(TL.getLAngleLoc());
4734 NewTL.setRAngleLoc(TL.getRAngleLoc());
4735 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4736 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4737 return Result;
4738 }
4739
John McCall833ca992009-10-29 08:12:44 +00004740 TemplateSpecializationTypeLoc NewTL
4741 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004742 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004743 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4744 NewTL.setLAngleLoc(TL.getLAngleLoc());
4745 NewTL.setRAngleLoc(TL.getRAngleLoc());
4746 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4747 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004748 }
Mike Stump1eb44332009-09-09 15:08:12 +00004749
John McCall833ca992009-10-29 08:12:44 +00004750 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004751}
Mike Stump1eb44332009-09-09 15:08:12 +00004752
Douglas Gregora88f09f2011-02-28 17:23:35 +00004753template <typename Derived>
4754QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4755 TypeLocBuilder &TLB,
4756 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004757 TemplateName Template,
4758 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004759 TemplateArgumentListInfo NewTemplateArgs;
4760 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4761 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4762 typedef TemplateArgumentLocContainerIterator<
4763 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004764 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004765 ArgIterator(TL, TL.getNumArgs()),
4766 NewTemplateArgs))
4767 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004768
Douglas Gregora88f09f2011-02-28 17:23:35 +00004769 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004770
Douglas Gregora88f09f2011-02-28 17:23:35 +00004771 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4772 QualType Result
4773 = getSema().Context.getDependentTemplateSpecializationType(
4774 TL.getTypePtr()->getKeyword(),
4775 DTN->getQualifier(),
4776 DTN->getIdentifier(),
4777 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004778
Douglas Gregora88f09f2011-02-28 17:23:35 +00004779 DependentTemplateSpecializationTypeLoc NewTL
4780 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004781 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004782 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004783 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004784 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004785 NewTL.setLAngleLoc(TL.getLAngleLoc());
4786 NewTL.setRAngleLoc(TL.getRAngleLoc());
4787 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4788 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4789 return Result;
4790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004791
4792 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004793 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004794 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004795 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
Douglas Gregora88f09f2011-02-28 17:23:35 +00004797 if (!Result.isNull()) {
4798 /// FIXME: Wrap this in an elaborated-type-specifier?
4799 TemplateSpecializationTypeLoc NewTL
4800 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004801 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004802 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004803 NewTL.setLAngleLoc(TL.getLAngleLoc());
4804 NewTL.setRAngleLoc(TL.getRAngleLoc());
4805 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4806 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4807 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004808
Douglas Gregora88f09f2011-02-28 17:23:35 +00004809 return Result;
4810}
4811
Mike Stump1eb44332009-09-09 15:08:12 +00004812template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004813QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004814TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004815 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004816 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004817
Douglas Gregor9e876872011-03-01 18:12:44 +00004818 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004819 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004820 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004821 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004822 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4823 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004824 return QualType();
4825 }
Mike Stump1eb44332009-09-09 15:08:12 +00004826
John McCall43fed0d2010-11-12 08:19:04 +00004827 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4828 if (NamedT.isNull())
4829 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004830
Richard Smith3e4c6c42011-05-05 21:57:07 +00004831 // C++0x [dcl.type.elab]p2:
4832 // If the identifier resolves to a typedef-name or the simple-template-id
4833 // resolves to an alias template specialization, the
4834 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004835 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4836 if (const TemplateSpecializationType *TST =
4837 NamedT->getAs<TemplateSpecializationType>()) {
4838 TemplateName Template = TST->getTemplateName();
4839 if (TypeAliasTemplateDecl *TAT =
4840 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4841 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4842 diag::err_tag_reference_non_tag) << 4;
4843 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4844 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004845 }
4846 }
4847
John McCalla2becad2009-10-21 00:40:46 +00004848 QualType Result = TL.getType();
4849 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004850 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004851 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004852 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004853 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004854 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004855 if (Result.isNull())
4856 return QualType();
4857 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004858
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004859 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004860 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004861 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004862 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004863}
Mike Stump1eb44332009-09-09 15:08:12 +00004864
4865template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004866QualType TreeTransform<Derived>::TransformAttributedType(
4867 TypeLocBuilder &TLB,
4868 AttributedTypeLoc TL) {
4869 const AttributedType *oldType = TL.getTypePtr();
4870 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4871 if (modifiedType.isNull())
4872 return QualType();
4873
4874 QualType result = TL.getType();
4875
4876 // FIXME: dependent operand expressions?
4877 if (getDerived().AlwaysRebuild() ||
4878 modifiedType != oldType->getModifiedType()) {
4879 // TODO: this is really lame; we should really be rebuilding the
4880 // equivalent type from first principles.
4881 QualType equivalentType
4882 = getDerived().TransformType(oldType->getEquivalentType());
4883 if (equivalentType.isNull())
4884 return QualType();
4885 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4886 modifiedType,
4887 equivalentType);
4888 }
4889
4890 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4891 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4892 if (TL.hasAttrOperand())
4893 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4894 if (TL.hasAttrExprOperand())
4895 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4896 else if (TL.hasAttrEnumOperand())
4897 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4898
4899 return result;
4900}
4901
4902template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004903QualType
4904TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4905 ParenTypeLoc TL) {
4906 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4907 if (Inner.isNull())
4908 return QualType();
4909
4910 QualType Result = TL.getType();
4911 if (getDerived().AlwaysRebuild() ||
4912 Inner != TL.getInnerLoc().getType()) {
4913 Result = getDerived().RebuildParenType(Inner);
4914 if (Result.isNull())
4915 return QualType();
4916 }
4917
4918 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4919 NewTL.setLParenLoc(TL.getLParenLoc());
4920 NewTL.setRParenLoc(TL.getRParenLoc());
4921 return Result;
4922}
4923
4924template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004925QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004926 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004927 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004928
Douglas Gregor2494dd02011-03-01 01:34:45 +00004929 NestedNameSpecifierLoc QualifierLoc
4930 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4931 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004932 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004933
John McCall33500952010-06-11 00:33:02 +00004934 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004935 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004936 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004937 QualifierLoc,
4938 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004939 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004940 if (Result.isNull())
4941 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004942
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004943 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4944 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004945 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4946
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004947 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004948 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004949 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004950 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004951 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004952 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004953 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004954 NewTL.setNameLoc(TL.getNameLoc());
4955 }
John McCalla2becad2009-10-21 00:40:46 +00004956 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004957}
Mike Stump1eb44332009-09-09 15:08:12 +00004958
Douglas Gregor577f75a2009-08-04 16:50:30 +00004959template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004960QualType TreeTransform<Derived>::
4961 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004962 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004963 NestedNameSpecifierLoc QualifierLoc;
4964 if (TL.getQualifierLoc()) {
4965 QualifierLoc
4966 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4967 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004968 return QualType();
4969 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004970
John McCall43fed0d2010-11-12 08:19:04 +00004971 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004972 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004973}
4974
4975template<typename Derived>
4976QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004977TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4978 DependentTemplateSpecializationTypeLoc TL,
4979 NestedNameSpecifierLoc QualifierLoc) {
4980 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004981
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982 TemplateArgumentListInfo NewTemplateArgs;
4983 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4984 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004985
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004986 typedef TemplateArgumentLocContainerIterator<
4987 DependentTemplateSpecializationTypeLoc> ArgIterator;
4988 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4989 ArgIterator(TL, TL.getNumArgs()),
4990 NewTemplateArgs))
4991 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004992
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 QualType Result
4994 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4995 QualifierLoc,
4996 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004997 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998 NewTemplateArgs);
4999 if (Result.isNull())
5000 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005001
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005002 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5003 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005004
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005005 // Copy information relevant to the template specialization.
5006 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005007 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005008 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005009 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005010 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5011 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005012 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005013 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005014
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005015 // Copy information relevant to the elaborated type.
5016 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005017 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005018 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005019 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5020 DependentTemplateSpecializationTypeLoc SpecTL
5021 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005022 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005023 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005024 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005025 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005026 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5027 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005028 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005029 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005030 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005031 TemplateSpecializationTypeLoc SpecTL
5032 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005033 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005034 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005035 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5036 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005037 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005038 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005039 }
5040 return Result;
5041}
5042
5043template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005044QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5045 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005046 QualType Pattern
5047 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005048 if (Pattern.isNull())
5049 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005050
5051 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005052 if (getDerived().AlwaysRebuild() ||
5053 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005054 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005055 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005056 TL.getEllipsisLoc(),
5057 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005058 if (Result.isNull())
5059 return QualType();
5060 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005061
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005062 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5063 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5064 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005065}
5066
5067template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005068QualType
5069TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005070 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005071 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005072 TLB.pushFullCopy(TL);
5073 return TL.getType();
5074}
5075
5076template<typename Derived>
5077QualType
5078TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005079 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005080 // ObjCObjectType is never dependent.
5081 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005082 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005083}
Mike Stump1eb44332009-09-09 15:08:12 +00005084
5085template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005086QualType
5087TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005088 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005089 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005090 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005091 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005092}
5093
Douglas Gregor577f75a2009-08-04 16:50:30 +00005094//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005095// Statement transformation
5096//===----------------------------------------------------------------------===//
5097template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005098StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005099TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005100 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005101}
5102
5103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005104StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005105TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5106 return getDerived().TransformCompoundStmt(S, false);
5107}
5108
5109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005110StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005111TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005113 Sema::CompoundScopeRAII CompoundScope(getSema());
5114
John McCall7114cba2010-08-27 19:56:05 +00005115 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005117 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005118 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5119 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005120 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005121 if (Result.isInvalid()) {
5122 // Immediately fail if this was a DeclStmt, since it's very
5123 // likely that this will cause problems for future statements.
5124 if (isa<DeclStmt>(*B))
5125 return StmtError();
5126
5127 // Otherwise, just keep processing substatements and fail later.
5128 SubStmtInvalid = true;
5129 continue;
5130 }
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5133 Statements.push_back(Result.takeAs<Stmt>());
5134 }
Mike Stump1eb44332009-09-09 15:08:12 +00005135
John McCall7114cba2010-08-27 19:56:05 +00005136 if (SubStmtInvalid)
5137 return StmtError();
5138
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 if (!getDerived().AlwaysRebuild() &&
5140 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005141 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005142
5143 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005144 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005145 S->getRBracLoc(),
5146 IsStmtExpr);
5147}
Mike Stump1eb44332009-09-09 15:08:12 +00005148
Douglas Gregor43959a92009-08-20 07:17:43 +00005149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005150StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005151TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005152 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005153 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005154 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5155 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005156
Eli Friedman264c1f82009-11-19 03:14:00 +00005157 // Transform the left-hand case value.
5158 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005159 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005160 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005161 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005162
Eli Friedman264c1f82009-11-19 03:14:00 +00005163 // Transform the right-hand case value (for the GNU case-range extension).
5164 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005165 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005166 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005168 }
Mike Stump1eb44332009-09-09 15:08:12 +00005169
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 // Build the case statement.
5171 // Case statements are always rebuilt so that they will attached to their
5172 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005173 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005174 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005176 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 S->getColonLoc());
5178 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005179 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005182 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005187 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005188}
5189
5190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005191StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005192TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005193 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005194 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005196 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005197
Douglas Gregor43959a92009-08-20 07:17:43 +00005198 // Default statements are always rebuilt
5199 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005200 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005201}
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregor43959a92009-08-20 07:17:43 +00005203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005204StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005205TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005206 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Chris Lattner57ad3782011-02-17 20:34:02 +00005210 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5211 S->getDecl());
5212 if (!LD)
5213 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005214
5215
Douglas Gregor43959a92009-08-20 07:17:43 +00005216 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005217 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005218 cast<LabelDecl>(LD), SourceLocation(),
5219 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005220}
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregor43959a92009-08-20 07:17:43 +00005222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005223StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005224TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5225 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5226 if (SubStmt.isInvalid())
5227 return StmtError();
5228
5229 // TODO: transform attributes
5230 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5231 return S;
5232
5233 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5234 S->getAttrs(),
5235 SubStmt.get());
5236}
5237
5238template<typename Derived>
5239StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005240TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005242 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005243 VarDecl *ConditionVar = 0;
5244 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005245 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005246 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005247 getDerived().TransformDefinition(
5248 S->getConditionVariable()->getLocation(),
5249 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005250 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005251 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005252 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005253 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005254
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005255 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005257
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005258 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005259 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005260 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005261 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005262 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005264
John McCall9ae2f072010-08-23 23:25:46 +00005265 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005266 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005268
John McCall9ae2f072010-08-23 23:25:46 +00005269 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5270 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005271 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005272
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005274 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005275 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005276 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005279 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005284 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005285 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005286 Then.get() == S->getThen() &&
5287 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005288 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005289
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005290 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005291 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005292 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005293}
5294
5295template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005296StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005297TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005298 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005299 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005300 VarDecl *ConditionVar = 0;
5301 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005302 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005303 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005304 getDerived().TransformDefinition(
5305 S->getConditionVariable()->getLocation(),
5306 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005307 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005309 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005310 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005311
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005312 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005314 }
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005317 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005318 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005319 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005321 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005324 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005325 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005326 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005329 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5330 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005331}
Mike Stump1eb44332009-09-09 15:08:12 +00005332
Douglas Gregor43959a92009-08-20 07:17:43 +00005333template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005334StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005335TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005336 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005337 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005338 VarDecl *ConditionVar = 0;
5339 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005340 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005341 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005342 getDerived().TransformDefinition(
5343 S->getConditionVariable()->getLocation(),
5344 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005345 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005346 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005347 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005348 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005349
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005350 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005352
5353 if (S->getCond()) {
5354 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005355 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005356 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005357 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005358 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005359 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005360 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005361 }
Mike Stump1eb44332009-09-09 15:08:12 +00005362
John McCall9ae2f072010-08-23 23:25:46 +00005363 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5364 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005365 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005366
Douglas Gregor43959a92009-08-20 07:17:43 +00005367 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005368 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005369 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005370 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005371
Douglas Gregor43959a92009-08-20 07:17:43 +00005372 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005373 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005374 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005376 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005378 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005379 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005380}
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregor43959a92009-08-20 07:17:43 +00005382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005383StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005384TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005386 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005387 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005388 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005389
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005390 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005391 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005392 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005393 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005394
Douglas Gregor43959a92009-08-20 07:17:43 +00005395 if (!getDerived().AlwaysRebuild() &&
5396 Cond.get() == S->getCond() &&
5397 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005398 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005399
John McCall9ae2f072010-08-23 23:25:46 +00005400 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5401 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005402 S->getRParenLoc());
5403}
Mike Stump1eb44332009-09-09 15:08:12 +00005404
Douglas Gregor43959a92009-08-20 07:17:43 +00005405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005406StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005407TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005408 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005409 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005414 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005415 VarDecl *ConditionVar = 0;
5416 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005417 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005418 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005419 getDerived().TransformDefinition(
5420 S->getConditionVariable()->getLocation(),
5421 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005423 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005424 } else {
5425 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005426
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005427 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005429
5430 if (S->getCond()) {
5431 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005432 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005433 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005434 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005436
John McCall9ae2f072010-08-23 23:25:46 +00005437 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005438 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005439 }
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Chad Rosier4a9d7952012-08-08 18:46:20 +00005441 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005442 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005443 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005444
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005446 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005447 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005449
Richard Smith41956372013-01-14 22:39:08 +00005450 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005451 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005453
Douglas Gregor43959a92009-08-20 07:17:43 +00005454 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005455 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005456 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 if (!getDerived().AlwaysRebuild() &&
5460 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005461 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 Inc.get() == S->getInc() &&
5463 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005464 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregor43959a92009-08-20 07:17:43 +00005466 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005467 Init.get(), FullCond, ConditionVar,
5468 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005469}
5470
5471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005472StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005473TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005474 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5475 S->getLabel());
5476 if (!LD)
5477 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005478
Douglas Gregor43959a92009-08-20 07:17:43 +00005479 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005480 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005481 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005482}
5483
5484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005485StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005486TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005487 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005488 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005490 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005491
Douglas Gregor43959a92009-08-20 07:17:43 +00005492 if (!getDerived().AlwaysRebuild() &&
5493 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005494 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005495
5496 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005497 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005498}
5499
5500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005501StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005502TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005503 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005504}
Mike Stump1eb44332009-09-09 15:08:12 +00005505
Douglas Gregor43959a92009-08-20 07:17:43 +00005506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005507StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005508TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005509 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005510}
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregor43959a92009-08-20 07:17:43 +00005512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005513StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005514TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005515 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005518
Mike Stump1eb44332009-09-09 15:08:12 +00005519 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005521 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005522}
Mike Stump1eb44332009-09-09 15:08:12 +00005523
Douglas Gregor43959a92009-08-20 07:17:43 +00005524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005525StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005526TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005527 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005528 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5530 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005531 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5532 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005533 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005534 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005535
Douglas Gregor43959a92009-08-20 07:17:43 +00005536 if (Transformed != *D)
5537 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005538
Douglas Gregor43959a92009-08-20 07:17:43 +00005539 Decls.push_back(Transformed);
5540 }
Mike Stump1eb44332009-09-09 15:08:12 +00005541
Douglas Gregor43959a92009-08-20 07:17:43 +00005542 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005543 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005544
5545 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005546 S->getStartLoc(), S->getEndLoc());
5547}
Mike Stump1eb44332009-09-09 15:08:12 +00005548
Douglas Gregor43959a92009-08-20 07:17:43 +00005549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005550StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005551TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005552
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005553 SmallVector<Expr*, 8> Constraints;
5554 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005555 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005556
John McCall60d7b3a2010-08-24 06:29:42 +00005557 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005558 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005559
5560 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005561
Anders Carlsson703e3942010-01-24 05:50:09 +00005562 // Go through the outputs.
5563 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005564 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005565
Anders Carlsson703e3942010-01-24 05:50:09 +00005566 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005567 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005568
Anders Carlsson703e3942010-01-24 05:50:09 +00005569 // Transform the output expr.
5570 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005571 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005572 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005573 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005574
Anders Carlsson703e3942010-01-24 05:50:09 +00005575 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005576
John McCall9ae2f072010-08-23 23:25:46 +00005577 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005578 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005579
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 // Go through the inputs.
5581 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005582 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005583
Anders Carlsson703e3942010-01-24 05:50:09 +00005584 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005585 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005586
Anders Carlsson703e3942010-01-24 05:50:09 +00005587 // Transform the input expr.
5588 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005589 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005590 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005591 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005592
Anders Carlsson703e3942010-01-24 05:50:09 +00005593 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005594
John McCall9ae2f072010-08-23 23:25:46 +00005595 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005596 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005597
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005599 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005600
5601 // Go through the clobbers.
5602 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005603 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005604
5605 // No need to transform the asm string literal.
5606 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005607 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5608 S->isVolatile(), S->getNumOutputs(),
5609 S->getNumInputs(), Names.data(),
5610 Constraints, Exprs, AsmString.get(),
5611 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005612}
5613
Chad Rosier8cd64b42012-06-11 20:47:18 +00005614template<typename Derived>
5615StmtResult
5616TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005617 ArrayRef<Token> AsmToks =
5618 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005619
Chad Rosier7bd092b2012-08-15 16:53:30 +00005620 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5621 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005622}
Douglas Gregor43959a92009-08-20 07:17:43 +00005623
5624template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005625StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005626TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005627 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005628 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005629 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005630 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005631
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005632 // Transform the @catch statements (if present).
5633 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005634 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005635 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005636 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005637 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005638 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005639 if (Catch.get() != S->getCatchStmt(I))
5640 AnyCatchChanged = true;
5641 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005642 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005643
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005644 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005645 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005646 if (S->getFinallyStmt()) {
5647 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5648 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005649 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005650 }
5651
5652 // If nothing changed, just retain this statement.
5653 if (!getDerived().AlwaysRebuild() &&
5654 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005655 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005656 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005657 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005658
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005659 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005660 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005661 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005662}
Mike Stump1eb44332009-09-09 15:08:12 +00005663
Douglas Gregor43959a92009-08-20 07:17:43 +00005664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005665StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005666TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005667 // Transform the @catch parameter, if there is one.
5668 VarDecl *Var = 0;
5669 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5670 TypeSourceInfo *TSInfo = 0;
5671 if (FromVar->getTypeSourceInfo()) {
5672 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5673 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005674 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005675 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005676
Douglas Gregorbe270a02010-04-26 17:57:08 +00005677 QualType T;
5678 if (TSInfo)
5679 T = TSInfo->getType();
5680 else {
5681 T = getDerived().TransformType(FromVar->getType());
5682 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005683 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005684 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005685
Douglas Gregorbe270a02010-04-26 17:57:08 +00005686 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5687 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005688 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005689 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005690
John McCall60d7b3a2010-08-24 06:29:42 +00005691 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005692 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005694
5695 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005696 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005697 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005698}
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregor43959a92009-08-20 07:17:43 +00005700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005701StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005702TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005703 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005704 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005705 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005706 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005707
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005708 // If nothing changed, just retain this statement.
5709 if (!getDerived().AlwaysRebuild() &&
5710 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005711 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005712
5713 // Build a new statement.
5714 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005715 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005716}
Mike Stump1eb44332009-09-09 15:08:12 +00005717
Douglas Gregor43959a92009-08-20 07:17:43 +00005718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005719StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005720TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005721 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005722 if (S->getThrowExpr()) {
5723 Operand = getDerived().TransformExpr(S->getThrowExpr());
5724 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005725 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005726 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005727
Douglas Gregord1377b22010-04-22 21:44:01 +00005728 if (!getDerived().AlwaysRebuild() &&
5729 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005730 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005731
John McCall9ae2f072010-08-23 23:25:46 +00005732 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005733}
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Douglas Gregor43959a92009-08-20 07:17:43 +00005735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005736StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005737TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005738 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005739 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005740 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005741 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005742 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005743 Object =
5744 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5745 Object.get());
5746 if (Object.isInvalid())
5747 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005748
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005749 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005750 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005751 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005752 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005753
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005754 // If nothing change, just retain the current statement.
5755 if (!getDerived().AlwaysRebuild() &&
5756 Object.get() == S->getSynchExpr() &&
5757 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005758 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005759
5760 // Build a new statement.
5761 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005762 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005763}
5764
5765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005766StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005767TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5768 ObjCAutoreleasePoolStmt *S) {
5769 // Transform the body.
5770 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5771 if (Body.isInvalid())
5772 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005773
John McCallf85e1932011-06-15 23:02:42 +00005774 // If nothing changed, just retain this statement.
5775 if (!getDerived().AlwaysRebuild() &&
5776 Body.get() == S->getSubStmt())
5777 return SemaRef.Owned(S);
5778
5779 // Build a new statement.
5780 return getDerived().RebuildObjCAutoreleasePoolStmt(
5781 S->getAtLoc(), Body.get());
5782}
5783
5784template<typename Derived>
5785StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005786TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005787 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005789 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005790 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005792
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005794 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005795 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005796 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005797
Douglas Gregorc3203e72010-04-22 23:10:45 +00005798 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005799 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005800 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005801 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005802
Douglas Gregorc3203e72010-04-22 23:10:45 +00005803 // If nothing changed, just retain this statement.
5804 if (!getDerived().AlwaysRebuild() &&
5805 Element.get() == S->getElement() &&
5806 Collection.get() == S->getCollection() &&
5807 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005808 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005809
Douglas Gregorc3203e72010-04-22 23:10:45 +00005810 // Build a new statement.
5811 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005812 Element.get(),
5813 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005814 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005815 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005816}
5817
5818
5819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005820StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005821TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5822 // Transform the exception declaration, if any.
5823 VarDecl *Var = 0;
5824 if (S->getExceptionDecl()) {
5825 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005826 TypeSourceInfo *T = getDerived().TransformType(
5827 ExceptionDecl->getTypeSourceInfo());
5828 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005829 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregor83cb9422010-09-09 17:09:21 +00005831 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005832 ExceptionDecl->getInnerLocStart(),
5833 ExceptionDecl->getLocation(),
5834 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005835 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005836 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005837 }
Mike Stump1eb44332009-09-09 15:08:12 +00005838
Douglas Gregor43959a92009-08-20 07:17:43 +00005839 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005840 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005841 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005842 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor43959a92009-08-20 07:17:43 +00005844 if (!getDerived().AlwaysRebuild() &&
5845 !Var &&
5846 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005847 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005848
5849 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5850 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005851 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005852}
Mike Stump1eb44332009-09-09 15:08:12 +00005853
Douglas Gregor43959a92009-08-20 07:17:43 +00005854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005855StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005856TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5857 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005858 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005859 = getDerived().TransformCompoundStmt(S->getTryBlock());
5860 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005861 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005862
Douglas Gregor43959a92009-08-20 07:17:43 +00005863 // Transform the handlers.
5864 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005865 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005866 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005867 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5869 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005870 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregor43959a92009-08-20 07:17:43 +00005872 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5873 Handlers.push_back(Handler.takeAs<Stmt>());
5874 }
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregor43959a92009-08-20 07:17:43 +00005876 if (!getDerived().AlwaysRebuild() &&
5877 TryBlock.get() == S->getTryBlock() &&
5878 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005879 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005880
John McCall9ae2f072010-08-23 23:25:46 +00005881 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005882 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005883}
Mike Stump1eb44332009-09-09 15:08:12 +00005884
Richard Smithad762fc2011-04-14 22:09:26 +00005885template<typename Derived>
5886StmtResult
5887TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5888 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5889 if (Range.isInvalid())
5890 return StmtError();
5891
5892 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5893 if (BeginEnd.isInvalid())
5894 return StmtError();
5895
5896 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5897 if (Cond.isInvalid())
5898 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005899 if (Cond.get())
5900 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5901 if (Cond.isInvalid())
5902 return StmtError();
5903 if (Cond.get())
5904 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005905
5906 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5907 if (Inc.isInvalid())
5908 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005909 if (Inc.get())
5910 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005911
5912 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5913 if (LoopVar.isInvalid())
5914 return StmtError();
5915
5916 StmtResult NewStmt = S;
5917 if (getDerived().AlwaysRebuild() ||
5918 Range.get() != S->getRangeStmt() ||
5919 BeginEnd.get() != S->getBeginEndStmt() ||
5920 Cond.get() != S->getCond() ||
5921 Inc.get() != S->getInc() ||
5922 LoopVar.get() != S->getLoopVarStmt())
5923 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5924 S->getColonLoc(), Range.get(),
5925 BeginEnd.get(), Cond.get(),
5926 Inc.get(), LoopVar.get(),
5927 S->getRParenLoc());
5928
5929 StmtResult Body = getDerived().TransformStmt(S->getBody());
5930 if (Body.isInvalid())
5931 return StmtError();
5932
5933 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5934 // it now so we have a new statement to attach the body to.
5935 if (Body.get() != S->getBody() && NewStmt.get() == S)
5936 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5937 S->getColonLoc(), Range.get(),
5938 BeginEnd.get(), Cond.get(),
5939 Inc.get(), LoopVar.get(),
5940 S->getRParenLoc());
5941
5942 if (NewStmt.get() == S)
5943 return SemaRef.Owned(S);
5944
5945 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5946}
5947
John Wiegley28bbe4b2011-04-28 01:08:34 +00005948template<typename Derived>
5949StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005950TreeTransform<Derived>::TransformMSDependentExistsStmt(
5951 MSDependentExistsStmt *S) {
5952 // Transform the nested-name-specifier, if any.
5953 NestedNameSpecifierLoc QualifierLoc;
5954 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005955 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005956 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5957 if (!QualifierLoc)
5958 return StmtError();
5959 }
5960
5961 // Transform the declaration name.
5962 DeclarationNameInfo NameInfo = S->getNameInfo();
5963 if (NameInfo.getName()) {
5964 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5965 if (!NameInfo.getName())
5966 return StmtError();
5967 }
5968
5969 // Check whether anything changed.
5970 if (!getDerived().AlwaysRebuild() &&
5971 QualifierLoc == S->getQualifierLoc() &&
5972 NameInfo.getName() == S->getNameInfo().getName())
5973 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005974
Douglas Gregorba0513d2011-10-25 01:33:02 +00005975 // Determine whether this name exists, if we can.
5976 CXXScopeSpec SS;
5977 SS.Adopt(QualifierLoc);
5978 bool Dependent = false;
5979 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5980 case Sema::IER_Exists:
5981 if (S->isIfExists())
5982 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005983
Douglas Gregorba0513d2011-10-25 01:33:02 +00005984 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5985
5986 case Sema::IER_DoesNotExist:
5987 if (S->isIfNotExists())
5988 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005989
Douglas Gregorba0513d2011-10-25 01:33:02 +00005990 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005991
Douglas Gregorba0513d2011-10-25 01:33:02 +00005992 case Sema::IER_Dependent:
5993 Dependent = true;
5994 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005995
Douglas Gregor65019ac2011-10-25 03:44:56 +00005996 case Sema::IER_Error:
5997 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005999
Douglas Gregorba0513d2011-10-25 01:33:02 +00006000 // We need to continue with the instantiation, so do so now.
6001 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6002 if (SubStmt.isInvalid())
6003 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006004
Douglas Gregorba0513d2011-10-25 01:33:02 +00006005 // If we have resolved the name, just transform to the substatement.
6006 if (!Dependent)
6007 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006008
Douglas Gregorba0513d2011-10-25 01:33:02 +00006009 // The name is still dependent, so build a dependent expression again.
6010 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6011 S->isIfExists(),
6012 QualifierLoc,
6013 NameInfo,
6014 SubStmt.get());
6015}
6016
6017template<typename Derived>
6018StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006019TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6020 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6021 if(TryBlock.isInvalid()) return StmtError();
6022
6023 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6024 if(!getDerived().AlwaysRebuild() &&
6025 TryBlock.get() == S->getTryBlock() &&
6026 Handler.get() == S->getHandler())
6027 return SemaRef.Owned(S);
6028
6029 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6030 S->getTryLoc(),
6031 TryBlock.take(),
6032 Handler.take());
6033}
6034
6035template<typename Derived>
6036StmtResult
6037TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6038 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6039 if(Block.isInvalid()) return StmtError();
6040
6041 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6042 Block.take());
6043}
6044
6045template<typename Derived>
6046StmtResult
6047TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6048 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6049 if(FilterExpr.isInvalid()) return StmtError();
6050
6051 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6052 if(Block.isInvalid()) return StmtError();
6053
6054 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6055 FilterExpr.take(),
6056 Block.take());
6057}
6058
6059template<typename Derived>
6060StmtResult
6061TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6062 if(isa<SEHFinallyStmt>(Handler))
6063 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6064 else
6065 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6066}
6067
Douglas Gregor43959a92009-08-20 07:17:43 +00006068//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069// Expression transformation
6070//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006072ExprResult
John McCall454feb92009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006075}
Mike Stump1eb44332009-09-09 15:08:12 +00006076
6077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006078ExprResult
John McCall454feb92009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006080 NestedNameSpecifierLoc QualifierLoc;
6081 if (E->getQualifierLoc()) {
6082 QualifierLoc
6083 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6084 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006085 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006086 }
John McCalldbd872f2009-12-08 09:08:17 +00006087
6088 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006089 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6090 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006091 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006092 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006093
John McCallec8045d2010-08-17 21:27:17 +00006094 DeclarationNameInfo NameInfo = E->getNameInfo();
6095 if (NameInfo.getName()) {
6096 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6097 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006098 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006099 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006100
6101 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006102 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006103 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006104 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006105 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006106
6107 // Mark it referenced in the new context regardless.
6108 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006109 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006110
John McCall3fa5cae2010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006112 }
John McCalldbd872f2009-12-08 09:08:17 +00006113
6114 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006115 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006116 TemplateArgs = &TransArgs;
6117 TransArgs.setLAngleLoc(E->getLAngleLoc());
6118 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006119 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6120 E->getNumTemplateArgs(),
6121 TransArgs))
6122 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006123 }
6124
Chad Rosier4a9d7952012-08-08 18:46:20 +00006125 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006126 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127}
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006130ExprResult
John McCall454feb92009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133}
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCall454feb92009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139}
Mike Stump1eb44332009-09-09 15:08:12 +00006140
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006142ExprResult
John McCall454feb92009-12-08 09:21:05 +00006143TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145}
Mike Stump1eb44332009-09-09 15:08:12 +00006146
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006148ExprResult
John McCall454feb92009-12-08 09:21:05 +00006149TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006150 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006151}
Mike Stump1eb44332009-09-09 15:08:12 +00006152
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006154ExprResult
John McCall454feb92009-12-08 09:21:05 +00006155TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006156 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006157}
6158
6159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006160ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006161TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6162 return SemaRef.MaybeBindToTemporary(E);
6163}
6164
6165template<typename Derived>
6166ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006167TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6168 ExprResult ControllingExpr =
6169 getDerived().TransformExpr(E->getControllingExpr());
6170 if (ControllingExpr.isInvalid())
6171 return ExprError();
6172
Chris Lattner686775d2011-07-20 06:58:45 +00006173 SmallVector<Expr *, 4> AssocExprs;
6174 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006175 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6176 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6177 if (TS) {
6178 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6179 if (!AssocType)
6180 return ExprError();
6181 AssocTypes.push_back(AssocType);
6182 } else {
6183 AssocTypes.push_back(0);
6184 }
6185
6186 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6187 if (AssocExpr.isInvalid())
6188 return ExprError();
6189 AssocExprs.push_back(AssocExpr.release());
6190 }
6191
6192 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6193 E->getDefaultLoc(),
6194 E->getRParenLoc(),
6195 ControllingExpr.release(),
6196 AssocTypes.data(),
6197 AssocExprs.data(),
6198 E->getNumAssocs());
6199}
6200
6201template<typename Derived>
6202ExprResult
John McCall454feb92009-12-08 09:21:05 +00006203TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006204 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006206 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006210
John McCall9ae2f072010-08-23 23:25:46 +00006211 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 E->getRParen());
6213}
6214
Richard Smithefeeccf2012-10-21 03:28:35 +00006215/// \brief The operand of a unary address-of operator has special rules: it's
6216/// allowed to refer to a non-static member of a class even if there's no 'this'
6217/// object available.
6218template<typename Derived>
6219ExprResult
6220TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6221 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6222 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6223 else
6224 return getDerived().TransformExpr(E);
6225}
6226
Mike Stump1eb44332009-09-09 15:08:12 +00006227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006228ExprResult
John McCall454feb92009-12-08 09:21:05 +00006229TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006230 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006231 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006232 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006233
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006235 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006236
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6238 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006239 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240}
Mike Stump1eb44332009-09-09 15:08:12 +00006241
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006243ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006244TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6245 // Transform the type.
6246 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6247 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006248 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006249
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006250 // Transform all of the components into components similar to what the
6251 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006252 // FIXME: It would be slightly more efficient in the non-dependent case to
6253 // just map FieldDecls, rather than requiring the rebuilder to look for
6254 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006255 // template code that we don't care.
6256 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006257 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006258 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006259 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006260 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6261 const Node &ON = E->getComponent(I);
6262 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006263 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006264 Comp.LocStart = ON.getSourceRange().getBegin();
6265 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006266 switch (ON.getKind()) {
6267 case Node::Array: {
6268 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006269 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006270 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006271 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006272
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006273 ExprChanged = ExprChanged || Index.get() != FromIndex;
6274 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006275 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006276 break;
6277 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006278
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006279 case Node::Field:
6280 case Node::Identifier:
6281 Comp.isBrackets = false;
6282 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006283 if (!Comp.U.IdentInfo)
6284 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006285
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006286 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006287
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006288 case Node::Base:
6289 // Will be recomputed during the rebuild.
6290 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006291 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006292
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006293 Components.push_back(Comp);
6294 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006295
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006296 // If nothing changed, retain the existing expression.
6297 if (!getDerived().AlwaysRebuild() &&
6298 Type == E->getTypeSourceInfo() &&
6299 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006300 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006301
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006302 // Build a new offsetof expression.
6303 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6304 Components.data(), Components.size(),
6305 E->getRParenLoc());
6306}
6307
6308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006309ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006310TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6311 assert(getDerived().AlreadyTransformed(E->getType()) &&
6312 "opaque value expression requires transformation");
6313 return SemaRef.Owned(E);
6314}
6315
6316template<typename Derived>
6317ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006318TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006319 // Rebuild the syntactic form. The original syntactic form has
6320 // opaque-value expressions in it, so strip those away and rebuild
6321 // the result. This is a really awful way of doing this, but the
6322 // better solution (rebuilding the semantic expressions and
6323 // rebinding OVEs as necessary) doesn't work; we'd need
6324 // TreeTransform to not strip away implicit conversions.
6325 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6326 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006327 if (result.isInvalid()) return ExprError();
6328
6329 // If that gives us a pseudo-object result back, the pseudo-object
6330 // expression must have been an lvalue-to-rvalue conversion which we
6331 // should reapply.
6332 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6333 result = SemaRef.checkPseudoObjectRValue(result.take());
6334
6335 return result;
6336}
6337
6338template<typename Derived>
6339ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006340TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6341 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006342 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006343 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006344
John McCalla93c9342009-12-07 02:54:59 +00006345 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006346 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006348
John McCall5ab75172009-11-04 07:28:41 +00006349 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006350 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006351
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006352 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6353 E->getKind(),
6354 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 }
Mike Stump1eb44332009-09-09 15:08:12 +00006356
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006357 // C++0x [expr.sizeof]p1:
6358 // The operand is either an expression, which is an unevaluated operand
6359 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006360 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6361 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006362
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006363 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6364 if (SubExpr.isInvalid())
6365 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006367 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6368 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006369
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006370 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6371 E->getOperatorLoc(),
6372 E->getKind(),
6373 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374}
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006377ExprResult
John McCall454feb92009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006379 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006381 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006382
John McCall60d7b3a2010-08-24 06:29:42 +00006383 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006386
6387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 if (!getDerived().AlwaysRebuild() &&
6389 LHS.get() == E->getLHS() &&
6390 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006391 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006392
John McCall9ae2f072010-08-23 23:25:46 +00006393 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006395 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 E->getRBracketLoc());
6397}
Mike Stump1eb44332009-09-09 15:08:12 +00006398
6399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006400ExprResult
John McCall454feb92009-12-08 09:21:05 +00006401TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006402 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006403 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006405 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406
6407 // Transform arguments.
6408 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006409 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006410 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006411 &ArgChanged))
6412 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006413
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414 if (!getDerived().AlwaysRebuild() &&
6415 Callee.get() == E->getCallee() &&
6416 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006417 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006418
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006420 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006422 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006423 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 E->getRParenLoc());
6425}
Mike Stump1eb44332009-09-09 15:08:12 +00006426
6427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006428ExprResult
John McCall454feb92009-12-08 09:21:05 +00006429TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006430 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006432 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006433
Douglas Gregor40d96a62011-02-28 21:54:11 +00006434 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006435 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006436 QualifierLoc
6437 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006438
Douglas Gregor40d96a62011-02-28 21:54:11 +00006439 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006441 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006442 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006443
Eli Friedmanf595cc42009-12-04 06:40:45 +00006444 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006445 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6446 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006448 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006449
John McCall6bb80172010-03-30 21:47:33 +00006450 NamedDecl *FoundDecl = E->getFoundDecl();
6451 if (FoundDecl == E->getMemberDecl()) {
6452 FoundDecl = Member;
6453 } else {
6454 FoundDecl = cast_or_null<NamedDecl>(
6455 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6456 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006457 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006458 }
6459
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (!getDerived().AlwaysRebuild() &&
6461 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006462 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006463 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006464 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006465 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006466
Anders Carlsson1f240322009-12-22 05:24:09 +00006467 // Mark it referenced in the new context regardless.
6468 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006469 SemaRef.MarkMemberReferenced(E);
6470
John McCall3fa5cae2010-10-26 07:05:15 +00006471 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006472 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473
John McCalld5532b62009-11-23 01:53:49 +00006474 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006475 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006476 TransArgs.setLAngleLoc(E->getLAngleLoc());
6477 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006478 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6479 E->getNumTemplateArgs(),
6480 TransArgs))
6481 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006482 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 // FIXME: Bogus source location for the operator
6485 SourceLocation FakeOperatorLoc
6486 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6487
John McCallc2233c52010-01-15 08:34:02 +00006488 // FIXME: to do this check properly, we will need to preserve the
6489 // first-qualifier-in-scope here, just in case we had a dependent
6490 // base (and therefore couldn't do the check) and a
6491 // nested-name-qualifier (and therefore could do the lookup).
6492 NamedDecl *FirstQualifierInScope = 0;
6493
John McCall9ae2f072010-08-23 23:25:46 +00006494 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006496 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006497 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006498 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006499 Member,
John McCall6bb80172010-03-30 21:47:33 +00006500 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006501 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006502 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006503 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504}
Mike Stump1eb44332009-09-09 15:08:12 +00006505
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006507ExprResult
John McCall454feb92009-12-08 09:21:05 +00006508TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006509 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006512
John McCall60d7b3a2010-08-24 06:29:42 +00006513 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 if (!getDerived().AlwaysRebuild() &&
6518 LHS.get() == E->getLHS() &&
6519 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006520 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Lang Hamesbe9af122012-10-02 04:45:10 +00006522 Sema::FPContractStateRAII FPContractState(getSema());
6523 getSema().FPFeatures.fp_contract = E->isFPContractable();
6524
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006526 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527}
6528
Mike Stump1eb44332009-09-09 15:08:12 +00006529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006530ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006532 CompoundAssignOperator *E) {
6533 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534}
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006537ExprResult TreeTransform<Derived>::
6538TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6539 // Just rebuild the common and RHS expressions and see whether we
6540 // get any changes.
6541
6542 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6543 if (commonExpr.isInvalid())
6544 return ExprError();
6545
6546 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6547 if (rhs.isInvalid())
6548 return ExprError();
6549
6550 if (!getDerived().AlwaysRebuild() &&
6551 commonExpr.get() == e->getCommon() &&
6552 rhs.get() == e->getFalseExpr())
6553 return SemaRef.Owned(e);
6554
6555 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6556 e->getQuestionLoc(),
6557 0,
6558 e->getColonLoc(),
6559 rhs.get());
6560}
6561
6562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006563ExprResult
John McCall454feb92009-12-08 09:21:05 +00006564TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006565 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006568
John McCall60d7b3a2010-08-24 06:29:42 +00006569 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006572
John McCall60d7b3a2010-08-24 06:29:42 +00006573 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006575 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006576
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 if (!getDerived().AlwaysRebuild() &&
6578 Cond.get() == E->getCond() &&
6579 LHS.get() == E->getLHS() &&
6580 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006582
John McCall9ae2f072010-08-23 23:25:46 +00006583 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006584 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006585 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006586 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006587 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006588}
Mike Stump1eb44332009-09-09 15:08:12 +00006589
6590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006591ExprResult
John McCall454feb92009-12-08 09:21:05 +00006592TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006593 // Implicit casts are eliminated during transformation, since they
6594 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006595 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596}
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall454feb92009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006601 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6602 if (!Type)
6603 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006604
John McCall60d7b3a2010-08-24 06:29:42 +00006605 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006606 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006608 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006611 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006613 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006614
John McCall9d125032010-01-15 18:39:57 +00006615 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006616 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006618 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619}
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006622ExprResult
John McCall454feb92009-12-08 09:21:05 +00006623TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006624 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6625 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6626 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006627 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006628
John McCall60d7b3a2010-08-24 06:29:42 +00006629 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006631 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006632
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006634 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006636 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637
John McCall1d7d8d62010-01-19 22:33:45 +00006638 // Note: the expression type doesn't necessarily match the
6639 // type-as-written, but that's okay, because it should always be
6640 // derivable from the initializer.
6641
John McCall42f56b52010-01-18 19:35:47 +00006642 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006644 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645}
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006648ExprResult
John McCall454feb92009-12-08 09:21:05 +00006649TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006650 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006652 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 if (!getDerived().AlwaysRebuild() &&
6655 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006656 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006659 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006661 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 E->getAccessorLoc(),
6663 E->getAccessor());
6664}
Mike Stump1eb44332009-09-09 15:08:12 +00006665
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006667ExprResult
John McCall454feb92009-12-08 09:21:05 +00006668TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006671 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006672 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006673 Inits, &InitChanged))
6674 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006677 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006678
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006679 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006680 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681}
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006684ExprResult
John McCall454feb92009-12-08 09:21:05 +00006685TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregor43959a92009-08-20 07:17:43 +00006688 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006689 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006691 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Douglas Gregor43959a92009-08-20 07:17:43 +00006693 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006694 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 bool ExprChanged = false;
6696 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6697 DEnd = E->designators_end();
6698 D != DEnd; ++D) {
6699 if (D->isFieldDesignator()) {
6700 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6701 D->getDotLoc(),
6702 D->getFieldLoc()));
6703 continue;
6704 }
Mike Stump1eb44332009-09-09 15:08:12 +00006705
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006707 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006710
6711 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6715 ArrayExprs.push_back(Index.release());
6716 continue;
6717 }
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006720 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6722 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006723 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006724
John McCall60d7b3a2010-08-24 06:29:42 +00006725 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006727 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006728
6729 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730 End.get(),
6731 D->getLBracketLoc(),
6732 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006733
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6735 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 ArrayExprs.push_back(Start.release());
6738 ArrayExprs.push_back(End.release());
6739 }
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 if (!getDerived().AlwaysRebuild() &&
6742 Init.get() == E->getInit() &&
6743 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006744 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006746 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006748 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006749}
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregorb98b1992009-08-11 05:31:07 +00006751template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006752ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006754 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006755 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006756
Douglas Gregor5557b252009-10-28 00:29:27 +00006757 // FIXME: Will we ever have proper type location here? Will we actually
6758 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 QualType T = getDerived().TransformType(E->getType());
6760 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006761 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006762
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 if (!getDerived().AlwaysRebuild() &&
6764 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006765 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006766
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 return getDerived().RebuildImplicitValueInitExpr(T);
6768}
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006771ExprResult
John McCall454feb92009-12-08 09:21:05 +00006772TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006773 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6774 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006776
John McCall60d7b3a2010-08-24 06:29:42 +00006777 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006779 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006780
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006782 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006784 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006785
John McCall9ae2f072010-08-23 23:25:46 +00006786 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006787 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788}
6789
6790template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006791ExprResult
John McCall454feb92009-12-08 09:21:05 +00006792TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006794 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006795 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6796 &ArgumentChanged))
6797 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006798
Douglas Gregorb98b1992009-08-11 05:31:07 +00006799 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006800 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 E->getRParenLoc());
6802}
Mike Stump1eb44332009-09-09 15:08:12 +00006803
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804/// \brief Transform an address-of-label expression.
6805///
6806/// By default, the transformation of an address-of-label expression always
6807/// rebuilds the expression, so that the label identifier can be resolved to
6808/// the corresponding label statement by semantic analysis.
6809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006810ExprResult
John McCall454feb92009-12-08 09:21:05 +00006811TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006812 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6813 E->getLabel());
6814 if (!LD)
6815 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006816
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006818 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819}
Mike Stump1eb44332009-09-09 15:08:12 +00006820
6821template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006822ExprResult
John McCall454feb92009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006824 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006825 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006827 if (SubStmt.isInvalid()) {
6828 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006829 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006830 }
Mike Stump1eb44332009-09-09 15:08:12 +00006831
Douglas Gregorb98b1992009-08-11 05:31:07 +00006832 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006833 SubStmt.get() == E->getSubStmt()) {
6834 // Calling this an 'error' is unintuitive, but it does the right thing.
6835 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006836 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006837 }
Mike Stump1eb44332009-09-09 15:08:12 +00006838
6839 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006840 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 E->getRParenLoc());
6842}
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006845ExprResult
John McCall454feb92009-12-08 09:21:05 +00006846TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006847 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006849 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006850
John McCall60d7b3a2010-08-24 06:29:42 +00006851 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006853 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006854
John McCall60d7b3a2010-08-24 06:29:42 +00006855 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006857 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006858
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
6860 Cond.get() == E->getCond() &&
6861 LHS.get() == E->getLHS() &&
6862 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006863 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006864
Douglas Gregorb98b1992009-08-11 05:31:07 +00006865 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006866 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 E->getRParenLoc());
6868}
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006871ExprResult
John McCall454feb92009-12-08 09:21:05 +00006872TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006873 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874}
6875
6876template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006877ExprResult
John McCall454feb92009-12-08 09:21:05 +00006878TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006879 switch (E->getOperator()) {
6880 case OO_New:
6881 case OO_Delete:
6882 case OO_Array_New:
6883 case OO_Array_Delete:
6884 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006885
Douglas Gregor668d6d92009-12-13 20:44:55 +00006886 case OO_Call: {
6887 // This is a call to an object's operator().
6888 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6889
6890 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006891 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006892 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006893 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006894
6895 // FIXME: Poor location information
6896 SourceLocation FakeLParenLoc
6897 = SemaRef.PP.getLocForEndOfToken(
6898 static_cast<Expr *>(Object.get())->getLocEnd());
6899
6900 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006901 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006902 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006903 Args))
6904 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006905
John McCall9ae2f072010-08-23 23:25:46 +00006906 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006907 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006908 E->getLocEnd());
6909 }
6910
6911#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6912 case OO_##Name:
6913#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6914#include "clang/Basic/OperatorKinds.def"
6915 case OO_Subscript:
6916 // Handled below.
6917 break;
6918
6919 case OO_Conditional:
6920 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006921
6922 case OO_None:
6923 case NUM_OVERLOADED_OPERATORS:
6924 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006925 }
6926
John McCall60d7b3a2010-08-24 06:29:42 +00006927 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006929 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006930
Richard Smithefeeccf2012-10-21 03:28:35 +00006931 ExprResult First;
6932 if (E->getOperator() == OO_Amp)
6933 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6934 else
6935 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006936 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006937 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006938
John McCall60d7b3a2010-08-24 06:29:42 +00006939 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 if (E->getNumArgs() == 2) {
6941 Second = getDerived().TransformExpr(E->getArg(1));
6942 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006943 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006944 }
Mike Stump1eb44332009-09-09 15:08:12 +00006945
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946 if (!getDerived().AlwaysRebuild() &&
6947 Callee.get() == E->getCallee() &&
6948 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006949 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006950 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006951
Lang Hamesbe9af122012-10-02 04:45:10 +00006952 Sema::FPContractStateRAII FPContractState(getSema());
6953 getSema().FPFeatures.fp_contract = E->isFPContractable();
6954
Douglas Gregorb98b1992009-08-11 05:31:07 +00006955 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6956 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006957 Callee.get(),
6958 First.get(),
6959 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960}
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006963ExprResult
John McCall454feb92009-12-08 09:21:05 +00006964TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6965 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966}
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006969ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006970TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6971 // Transform the callee.
6972 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6973 if (Callee.isInvalid())
6974 return ExprError();
6975
6976 // Transform exec config.
6977 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6978 if (EC.isInvalid())
6979 return ExprError();
6980
6981 // Transform arguments.
6982 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006983 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006984 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006985 &ArgChanged))
6986 return ExprError();
6987
6988 if (!getDerived().AlwaysRebuild() &&
6989 Callee.get() == E->getCallee() &&
6990 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006991 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006992
6993 // FIXME: Wrong source location information for the '('.
6994 SourceLocation FakeLParenLoc
6995 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6996 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006997 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006998 E->getRParenLoc(), EC.get());
6999}
7000
7001template<typename Derived>
7002ExprResult
John McCall454feb92009-12-08 09:21:05 +00007003TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007004 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7005 if (!Type)
7006 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007007
John McCall60d7b3a2010-08-24 06:29:42 +00007008 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007009 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007011 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007012
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007014 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007016 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007018 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007019 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007020 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007021 E->getAngleBrackets().getEnd(),
7022 // FIXME. this should be '(' location
7023 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007024 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007025 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007026}
Mike Stump1eb44332009-09-09 15:08:12 +00007027
Douglas Gregorb98b1992009-08-11 05:31:07 +00007028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007029ExprResult
John McCall454feb92009-12-08 09:21:05 +00007030TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7031 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032}
Mike Stump1eb44332009-09-09 15:08:12 +00007033
7034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007035ExprResult
John McCall454feb92009-12-08 09:21:05 +00007036TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7037 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007038}
7039
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007041ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007043 CXXReinterpretCastExpr *E) {
7044 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045}
Mike Stump1eb44332009-09-09 15:08:12 +00007046
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007048ExprResult
John McCall454feb92009-12-08 09:21:05 +00007049TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7050 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051}
Mike Stump1eb44332009-09-09 15:08:12 +00007052
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007054ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007056 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007057 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7058 if (!Type)
7059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007060
John McCall60d7b3a2010-08-24 06:29:42 +00007061 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007062 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007063 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007064 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007067 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007069 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007071 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007073 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 E->getRParenLoc());
7075}
Mike Stump1eb44332009-09-09 15:08:12 +00007076
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007078ExprResult
John McCall454feb92009-12-08 09:21:05 +00007079TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007081 TypeSourceInfo *TInfo
7082 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7083 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007084 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007085
Douglas Gregorb98b1992009-08-11 05:31:07 +00007086 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007087 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007088 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007090 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7091 E->getLocStart(),
7092 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093 E->getLocEnd());
7094 }
Mike Stump1eb44332009-09-09 15:08:12 +00007095
Eli Friedmanef331b72012-01-20 01:26:23 +00007096 // We don't know whether the subexpression is potentially evaluated until
7097 // after we perform semantic analysis. We speculatively assume it is
7098 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007099 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007100 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7101 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007102
John McCall60d7b3a2010-08-24 06:29:42 +00007103 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007106
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 if (!getDerived().AlwaysRebuild() &&
7108 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007109 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007110
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007111 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7112 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007113 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 E->getLocEnd());
7115}
7116
7117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007118ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007119TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7120 if (E->isTypeOperand()) {
7121 TypeSourceInfo *TInfo
7122 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7123 if (!TInfo)
7124 return ExprError();
7125
7126 if (!getDerived().AlwaysRebuild() &&
7127 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007128 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007129
Douglas Gregor3c52a212011-03-06 17:40:41 +00007130 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007131 E->getLocStart(),
7132 TInfo,
7133 E->getLocEnd());
7134 }
7135
Francois Pichet01b7c302010-09-08 12:20:18 +00007136 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7137
7138 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7139 if (SubExpr.isInvalid())
7140 return ExprError();
7141
7142 if (!getDerived().AlwaysRebuild() &&
7143 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007144 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007145
7146 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7147 E->getLocStart(),
7148 SubExpr.get(),
7149 E->getLocEnd());
7150}
7151
7152template<typename Derived>
7153ExprResult
John McCall454feb92009-12-08 09:21:05 +00007154TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007155 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156}
Mike Stump1eb44332009-09-09 15:08:12 +00007157
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007159ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007161 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007162 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163}
Mike Stump1eb44332009-09-09 15:08:12 +00007164
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007166ExprResult
John McCall454feb92009-12-08 09:21:05 +00007167TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007168 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007169 QualType T;
7170 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7171 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007172 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007173 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007174 getSema().Context.getRecordType(Record));
7175 } else {
7176 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7177 "this in the wrong scope?");
7178 return ExprError();
7179 }
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregorec79d872012-02-24 17:41:38 +00007181 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7182 // Make sure that we capture 'this'.
7183 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007184 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007185 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007186
Douglas Gregor828a1972010-01-07 23:12:05 +00007187 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
John McCall454feb92009-12-08 09:21:05 +00007192TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007193 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 if (!getDerived().AlwaysRebuild() &&
7198 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007199 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200
Douglas Gregorbca01b42011-07-06 22:04:06 +00007201 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7202 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203}
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007206ExprResult
John McCall454feb92009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007208 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007209 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7210 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007216 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007217
Douglas Gregor036aed12009-12-23 23:03:06 +00007218 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219}
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007223TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7224 CXXScalarValueInitExpr *E) {
7225 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7226 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007227 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007228
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007230 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007231 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007232
Chad Rosier4a9d7952012-08-08 18:46:20 +00007233 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007234 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007235 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236}
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007239ExprResult
John McCall454feb92009-12-08 09:21:05 +00007240TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007241 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007242 TypeSourceInfo *AllocTypeInfo
7243 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7244 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007248 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007250 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007251
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252 // Transform the placement arguments (if any).
7253 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007254 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007255 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007256 E->getNumPlacementArgs(), true,
7257 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007260 // Transform the initializer (if any).
7261 Expr *OldInit = E->getInitializer();
7262 ExprResult NewInit;
7263 if (OldInit)
7264 NewInit = getDerived().TransformExpr(OldInit);
7265 if (NewInit.isInvalid())
7266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007267
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007268 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007269 FunctionDecl *OperatorNew = 0;
7270 if (E->getOperatorNew()) {
7271 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007272 getDerived().TransformDecl(E->getLocStart(),
7273 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007275 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007276 }
7277
7278 FunctionDecl *OperatorDelete = 0;
7279 if (E->getOperatorDelete()) {
7280 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007281 getDerived().TransformDecl(E->getLocStart(),
7282 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007283 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007284 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007285 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007288 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007290 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007291 OperatorNew == E->getOperatorNew() &&
7292 OperatorDelete == E->getOperatorDelete() &&
7293 !ArgumentChanged) {
7294 // Mark any declarations we need as referenced.
7295 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007296 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007297 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007298 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007299 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007300
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007301 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007302 QualType ElementType
7303 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7304 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7305 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7306 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007307 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007308 }
7309 }
7310 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007311
John McCall3fa5cae2010-10-26 07:05:15 +00007312 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007313 }
Mike Stump1eb44332009-09-09 15:08:12 +00007314
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007315 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007316 if (!ArraySize.get()) {
7317 // If no array size was specified, but the new expression was
7318 // instantiated with an array type (e.g., "new T" where T is
7319 // instantiated with "int[4]"), extract the outer bound from the
7320 // array type as our array size. We do this with constant and
7321 // dependently-sized array types.
7322 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7323 if (!ArrayT) {
7324 // Do nothing
7325 } else if (const ConstantArrayType *ConsArrayT
7326 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007327 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007328 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007329 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007330 SemaRef.Context.getSizeType(),
7331 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007332 AllocType = ConsArrayT->getElementType();
7333 } else if (const DependentSizedArrayType *DepArrayT
7334 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7335 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007336 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007337 AllocType = DepArrayT->getElementType();
7338 }
7339 }
7340 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7343 E->isGlobalNew(),
7344 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007345 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007347 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007348 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007349 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007350 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007351 E->getDirectInitRange(),
7352 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353}
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007356ExprResult
John McCall454feb92009-12-08 09:21:05 +00007357TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007358 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregor1af74512010-02-26 00:38:10 +00007362 // Transform the delete operator, if known.
7363 FunctionDecl *OperatorDelete = 0;
7364 if (E->getOperatorDelete()) {
7365 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007366 getDerived().TransformDecl(E->getLocStart(),
7367 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007368 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007369 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007370 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007371
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007373 Operand.get() == E->getArgument() &&
7374 OperatorDelete == E->getOperatorDelete()) {
7375 // Mark any declarations we need as referenced.
7376 // FIXME: instantiation-specific.
7377 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007378 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007379
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007380 if (!E->getArgument()->isTypeDependent()) {
7381 QualType Destroyed = SemaRef.Context.getBaseElementType(
7382 E->getDestroyedType());
7383 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7384 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007385 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007386 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007387 }
7388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007389
John McCall3fa5cae2010-10-26 07:05:15 +00007390 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007391 }
Mike Stump1eb44332009-09-09 15:08:12 +00007392
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7394 E->isGlobalDelete(),
7395 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007396 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397}
Mike Stump1eb44332009-09-09 15:08:12 +00007398
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007400ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007401TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007402 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007403 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007404 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007406
John McCallb3d87482010-08-24 05:47:05 +00007407 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007408 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007409 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007410 E->getOperatorLoc(),
7411 E->isArrow()? tok::arrow : tok::period,
7412 ObjectTypePtr,
7413 MayBePseudoDestructor);
7414 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007415 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007416
John McCallb3d87482010-08-24 05:47:05 +00007417 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007418 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7419 if (QualifierLoc) {
7420 QualifierLoc
7421 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7422 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007423 return ExprError();
7424 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007425 CXXScopeSpec SS;
7426 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007427
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007428 PseudoDestructorTypeStorage Destroyed;
7429 if (E->getDestroyedTypeInfo()) {
7430 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007431 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007432 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007433 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007434 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007435 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007436 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007437 // We aren't likely to be able to resolve the identifier down to a type
7438 // now anyway, so just retain the identifier.
7439 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7440 E->getDestroyedTypeLoc());
7441 } else {
7442 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007443 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007444 *E->getDestroyedTypeIdentifier(),
7445 E->getDestroyedTypeLoc(),
7446 /*Scope=*/0,
7447 SS, ObjectTypePtr,
7448 false);
7449 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007450 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007451
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007452 Destroyed
7453 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7454 E->getDestroyedTypeLoc());
7455 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007456
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007457 TypeSourceInfo *ScopeTypeInfo = 0;
7458 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007459 CXXScopeSpec EmptySS;
7460 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7461 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007462 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007463 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007464 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007465
John McCall9ae2f072010-08-23 23:25:46 +00007466 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007467 E->getOperatorLoc(),
7468 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007469 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007470 ScopeTypeInfo,
7471 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007472 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007473 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007474}
Mike Stump1eb44332009-09-09 15:08:12 +00007475
Douglas Gregora71d8192009-09-04 17:36:40 +00007476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007477ExprResult
John McCallba135432009-11-21 08:51:07 +00007478TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007479 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007480 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7481 Sema::LookupOrdinaryName);
7482
7483 // Transform all the decls.
7484 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7485 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007486 NamedDecl *InstD = static_cast<NamedDecl*>(
7487 getDerived().TransformDecl(Old->getNameLoc(),
7488 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007489 if (!InstD) {
7490 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7491 // This can happen because of dependent hiding.
7492 if (isa<UsingShadowDecl>(*I))
7493 continue;
7494 else
John McCallf312b1e2010-08-26 23:41:50 +00007495 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007496 }
John McCallf7a1a742009-11-24 19:00:30 +00007497
7498 // Expand using declarations.
7499 if (isa<UsingDecl>(InstD)) {
7500 UsingDecl *UD = cast<UsingDecl>(InstD);
7501 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7502 E = UD->shadow_end(); I != E; ++I)
7503 R.addDecl(*I);
7504 continue;
7505 }
7506
7507 R.addDecl(InstD);
7508 }
7509
7510 // Resolve a kind, but don't do any further analysis. If it's
7511 // ambiguous, the callee needs to deal with it.
7512 R.resolveKind();
7513
7514 // Rebuild the nested-name qualifier, if present.
7515 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007516 if (Old->getQualifierLoc()) {
7517 NestedNameSpecifierLoc QualifierLoc
7518 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7519 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007520 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007521
Douglas Gregor4c9be892011-02-28 20:01:57 +00007522 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007523 }
7524
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007525 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007526 CXXRecordDecl *NamingClass
7527 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7528 Old->getNameLoc(),
7529 Old->getNamingClass()));
7530 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007532
Douglas Gregor66c45152010-04-27 16:10:10 +00007533 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007534 }
7535
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007536 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7537
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007538 // If we have neither explicit template arguments, nor the template keyword,
7539 // it's a normal declaration name.
7540 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007541 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7542
7543 // If we have template arguments, rebuild them, then rebuild the
7544 // templateid expression.
7545 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007546 if (Old->hasExplicitTemplateArgs() &&
7547 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007548 Old->getNumTemplateArgs(),
7549 TransArgs))
7550 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007551
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007552 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007553 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554}
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Douglas Gregorb98b1992009-08-11 05:31:07 +00007556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007557ExprResult
John McCall454feb92009-12-08 09:21:05 +00007558TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007559 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7560 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007561 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007562
Douglas Gregorb98b1992009-08-11 05:31:07 +00007563 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007564 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007565 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007566
Mike Stump1eb44332009-09-09 15:08:12 +00007567 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569 T,
7570 E->getLocEnd());
7571}
Mike Stump1eb44332009-09-09 15:08:12 +00007572
Douglas Gregorb98b1992009-08-11 05:31:07 +00007573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007574ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007575TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7576 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7577 if (!LhsT)
7578 return ExprError();
7579
7580 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7581 if (!RhsT)
7582 return ExprError();
7583
7584 if (!getDerived().AlwaysRebuild() &&
7585 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7586 return SemaRef.Owned(E);
7587
7588 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7589 E->getLocStart(),
7590 LhsT, RhsT,
7591 E->getLocEnd());
7592}
7593
7594template<typename Derived>
7595ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007596TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7597 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007598 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007599 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7600 TypeSourceInfo *From = E->getArg(I);
7601 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007602 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007603 TypeLocBuilder TLB;
7604 TLB.reserve(FromTL.getFullDataSize());
7605 QualType To = getDerived().TransformType(TLB, FromTL);
7606 if (To.isNull())
7607 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007608
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007609 if (To == From->getType())
7610 Args.push_back(From);
7611 else {
7612 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7613 ArgChanged = true;
7614 }
7615 continue;
7616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007617
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007618 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007619
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007620 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007621 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007622 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7623 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7624 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007626 // Determine whether the set of unexpanded parameter packs can and should
7627 // be expanded.
7628 bool Expand = true;
7629 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007630 Optional<unsigned> OrigNumExpansions =
7631 ExpansionTL.getTypePtr()->getNumExpansions();
7632 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007633 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7634 PatternTL.getSourceRange(),
7635 Unexpanded,
7636 Expand, RetainExpansion,
7637 NumExpansions))
7638 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007639
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007640 if (!Expand) {
7641 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007642 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007643 // expansion.
7644 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007646 TypeLocBuilder TLB;
7647 TLB.reserve(From->getTypeLoc().getFullDataSize());
7648
7649 QualType To = getDerived().TransformType(TLB, PatternTL);
7650 if (To.isNull())
7651 return ExprError();
7652
Chad Rosier4a9d7952012-08-08 18:46:20 +00007653 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007654 PatternTL.getSourceRange(),
7655 ExpansionTL.getEllipsisLoc(),
7656 NumExpansions);
7657 if (To.isNull())
7658 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007659
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007660 PackExpansionTypeLoc ToExpansionTL
7661 = TLB.push<PackExpansionTypeLoc>(To);
7662 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7663 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7664 continue;
7665 }
7666
7667 // Expand the pack expansion by substituting for each argument in the
7668 // pack(s).
7669 for (unsigned I = 0; I != *NumExpansions; ++I) {
7670 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7671 TypeLocBuilder TLB;
7672 TLB.reserve(PatternTL.getFullDataSize());
7673 QualType To = getDerived().TransformType(TLB, PatternTL);
7674 if (To.isNull())
7675 return ExprError();
7676
7677 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7678 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007679
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007680 if (!RetainExpansion)
7681 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007682
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007683 // If we're supposed to retain a pack expansion, do so by temporarily
7684 // forgetting the partially-substituted parameter pack.
7685 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7686
7687 TypeLocBuilder TLB;
7688 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007690 QualType To = getDerived().TransformType(TLB, PatternTL);
7691 if (To.isNull())
7692 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007693
7694 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007695 PatternTL.getSourceRange(),
7696 ExpansionTL.getEllipsisLoc(),
7697 NumExpansions);
7698 if (To.isNull())
7699 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007700
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007701 PackExpansionTypeLoc ToExpansionTL
7702 = TLB.push<PackExpansionTypeLoc>(To);
7703 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7704 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7705 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007706
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7708 return SemaRef.Owned(E);
7709
7710 return getDerived().RebuildTypeTrait(E->getTrait(),
7711 E->getLocStart(),
7712 Args,
7713 E->getLocEnd());
7714}
7715
7716template<typename Derived>
7717ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007718TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7719 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7720 if (!T)
7721 return ExprError();
7722
7723 if (!getDerived().AlwaysRebuild() &&
7724 T == E->getQueriedTypeSourceInfo())
7725 return SemaRef.Owned(E);
7726
7727 ExprResult SubExpr;
7728 {
7729 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7730 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7731 if (SubExpr.isInvalid())
7732 return ExprError();
7733
7734 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7735 return SemaRef.Owned(E);
7736 }
7737
7738 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7739 E->getLocStart(),
7740 T,
7741 SubExpr.get(),
7742 E->getLocEnd());
7743}
7744
7745template<typename Derived>
7746ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007747TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7748 ExprResult SubExpr;
7749 {
7750 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7751 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7752 if (SubExpr.isInvalid())
7753 return ExprError();
7754
7755 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7756 return SemaRef.Owned(E);
7757 }
7758
7759 return getDerived().RebuildExpressionTrait(
7760 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7761}
7762
7763template<typename Derived>
7764ExprResult
John McCall865d4472009-11-19 22:55:06 +00007765TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007766 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007767 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7768}
7769
7770template<typename Derived>
7771ExprResult
7772TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7773 DependentScopeDeclRefExpr *E,
7774 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007775 NestedNameSpecifierLoc QualifierLoc
7776 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7777 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007778 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007779 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007780
John McCall43fed0d2010-11-12 08:19:04 +00007781 // TODO: If this is a conversion-function-id, verify that the
7782 // destination type name (if present) resolves the same way after
7783 // instantiation as it did in the local scope.
7784
Abramo Bagnara25777432010-08-11 22:01:17 +00007785 DeclarationNameInfo NameInfo
7786 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7787 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007789
John McCallf7a1a742009-11-24 19:00:30 +00007790 if (!E->hasExplicitTemplateArgs()) {
7791 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007792 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007793 // Note: it is sufficient to compare the Name component of NameInfo:
7794 // if name has not changed, DNLoc has not changed either.
7795 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007796 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007797
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007798 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007799 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007800 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007801 /*TemplateArgs*/ 0,
7802 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007803 }
John McCalld5532b62009-11-23 01:53:49 +00007804
7805 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007806 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7807 E->getNumTemplateArgs(),
7808 TransArgs))
7809 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007811 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007812 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007813 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007814 &TransArgs,
7815 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816}
7817
7818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007819ExprResult
John McCall454feb92009-12-08 09:21:05 +00007820TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007821 // CXXConstructExprs other than for list-initialization and
7822 // CXXTemporaryObjectExpr are always implicit, so when we have
7823 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007824 if ((E->getNumArgs() == 1 ||
7825 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007826 (!getDerived().DropCallArgument(E->getArg(0))) &&
7827 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007828 return getDerived().TransformExpr(E->getArg(0));
7829
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7831
7832 QualType T = getDerived().TransformType(E->getType());
7833 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007834 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007835
7836 CXXConstructorDecl *Constructor
7837 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007838 getDerived().TransformDecl(E->getLocStart(),
7839 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007842
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007844 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007845 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007846 &ArgumentChanged))
7847 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007848
Douglas Gregorb98b1992009-08-11 05:31:07 +00007849 if (!getDerived().AlwaysRebuild() &&
7850 T == E->getType() &&
7851 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007852 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007853 // Mark the constructor as referenced.
7854 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007855 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007856 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007857 }
Mike Stump1eb44332009-09-09 15:08:12 +00007858
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007859 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7860 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007861 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007862 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007863 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007864 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007865 E->getConstructionKind(),
7866 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007867}
Mike Stump1eb44332009-09-09 15:08:12 +00007868
Douglas Gregorb98b1992009-08-11 05:31:07 +00007869/// \brief Transform a C++ temporary-binding expression.
7870///
Douglas Gregor51326552009-12-24 18:51:59 +00007871/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7872/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007874ExprResult
John McCall454feb92009-12-08 09:21:05 +00007875TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007876 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877}
Mike Stump1eb44332009-09-09 15:08:12 +00007878
John McCall4765fa02010-12-06 08:20:24 +00007879/// \brief Transform a C++ expression that contains cleanups that should
7880/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007881///
John McCall4765fa02010-12-06 08:20:24 +00007882/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007883/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007885ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007886TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007887 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007888}
Mike Stump1eb44332009-09-09 15:08:12 +00007889
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007891ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007893 CXXTemporaryObjectExpr *E) {
7894 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7895 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007897
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898 CXXConstructorDecl *Constructor
7899 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007900 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007901 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007903 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007904
Douglas Gregorb98b1992009-08-11 05:31:07 +00007905 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007906 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007907 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007908 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007909 &ArgumentChanged))
7910 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007911
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007913 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007915 !ArgumentChanged) {
7916 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007917 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007918 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007920
Richard Smithc83c2302012-12-19 01:39:02 +00007921 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007922 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7923 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007924 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007925 E->getLocEnd());
7926}
Mike Stump1eb44332009-09-09 15:08:12 +00007927
Douglas Gregorb98b1992009-08-11 05:31:07 +00007928template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007929ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007930TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007931 // Transform the type of the lambda parameters and start the definition of
7932 // the lambda itself.
7933 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007934 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007935 if (!MethodTy)
7936 return ExprError();
7937
Eli Friedman8da8a662012-09-19 01:18:11 +00007938 // Create the local class that will describe the lambda.
7939 CXXRecordDecl *Class
7940 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7941 MethodTy,
7942 /*KnownDependent=*/false);
7943 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7944
Douglas Gregorc6889e72012-02-14 22:28:59 +00007945 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007946 SmallVector<QualType, 4> ParamTypes;
7947 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007948 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7949 E->getCallOperator()->param_begin(),
7950 E->getCallOperator()->param_size(),
7951 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007952 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007953
Douglas Gregordfca6f52012-02-13 22:00:16 +00007954 // Build the call operator.
7955 CXXMethodDecl *CallOperator
7956 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007957 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007958 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007959 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007960 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007961
Richard Smith612409e2012-07-25 03:56:55 +00007962 return getDerived().TransformLambdaScope(E, CallOperator);
7963}
7964
7965template<typename Derived>
7966ExprResult
7967TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7968 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007969 // Introduce the context of the call operator.
7970 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7971
Douglas Gregordfca6f52012-02-13 22:00:16 +00007972 // Enter the scope of the lambda.
7973 sema::LambdaScopeInfo *LSI
7974 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7975 E->getCaptureDefault(),
7976 E->hasExplicitParameters(),
7977 E->hasExplicitResultType(),
7978 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007979
Douglas Gregordfca6f52012-02-13 22:00:16 +00007980 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007981 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007982 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007983 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007984 CEnd = E->capture_end();
7985 C != CEnd; ++C) {
7986 // When we hit the first implicit capture, tell Sema that we've finished
7987 // the list of explicit captures.
7988 if (!FinishedExplicitCaptures && C->isImplicit()) {
7989 getSema().finishLambdaExplicitCaptures(LSI);
7990 FinishedExplicitCaptures = true;
7991 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007992
Douglas Gregordfca6f52012-02-13 22:00:16 +00007993 // Capturing 'this' is trivial.
7994 if (C->capturesThis()) {
7995 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7996 continue;
7997 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007998
Douglas Gregora7365242012-02-14 19:27:52 +00007999 // Determine the capture kind for Sema.
8000 Sema::TryCaptureKind Kind
8001 = C->isImplicit()? Sema::TryCapture_Implicit
8002 : C->getCaptureKind() == LCK_ByCopy
8003 ? Sema::TryCapture_ExplicitByVal
8004 : Sema::TryCapture_ExplicitByRef;
8005 SourceLocation EllipsisLoc;
8006 if (C->isPackExpansion()) {
8007 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8008 bool ShouldExpand = false;
8009 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008010 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008011 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8012 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008013 Unexpanded,
8014 ShouldExpand, RetainExpansion,
8015 NumExpansions))
8016 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008017
Douglas Gregora7365242012-02-14 19:27:52 +00008018 if (ShouldExpand) {
8019 // The transform has determined that we should perform an expansion;
8020 // transform and capture each of the arguments.
8021 // expansion of the pattern. Do so.
8022 VarDecl *Pack = C->getCapturedVar();
8023 for (unsigned I = 0; I != *NumExpansions; ++I) {
8024 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8025 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008026 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008027 Pack));
8028 if (!CapturedVar) {
8029 Invalid = true;
8030 continue;
8031 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008032
Douglas Gregora7365242012-02-14 19:27:52 +00008033 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008034 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8035 }
Douglas Gregora7365242012-02-14 19:27:52 +00008036 continue;
8037 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008038
Douglas Gregora7365242012-02-14 19:27:52 +00008039 EllipsisLoc = C->getEllipsisLoc();
8040 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008041
Douglas Gregordfca6f52012-02-13 22:00:16 +00008042 // Transform the captured variable.
8043 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008044 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008045 C->getCapturedVar()));
8046 if (!CapturedVar) {
8047 Invalid = true;
8048 continue;
8049 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008050
Douglas Gregordfca6f52012-02-13 22:00:16 +00008051 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008052 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008053 }
8054 if (!FinishedExplicitCaptures)
8055 getSema().finishLambdaExplicitCaptures(LSI);
8056
Douglas Gregordfca6f52012-02-13 22:00:16 +00008057
8058 // Enter a new evaluation context to insulate the lambda from any
8059 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008060 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008061
8062 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008063 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008064 /*IsInstantiation=*/true);
8065 return ExprError();
8066 }
8067
8068 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008069 StmtResult Body = getDerived().TransformStmt(E->getBody());
8070 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008071 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008072 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008073 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008074 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008075
Chad Rosier4a9d7952012-08-08 18:46:20 +00008076 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008077 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008078}
8079
8080template<typename Derived>
8081ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008082TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008083 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008084 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8085 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008086 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008087
Douglas Gregorb98b1992009-08-11 05:31:07 +00008088 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008089 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008090 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008091 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008092 &ArgumentChanged))
8093 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008094
Douglas Gregorb98b1992009-08-11 05:31:07 +00008095 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008096 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008097 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008098 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008099
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008101 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008102 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008103 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008104 E->getRParenLoc());
8105}
Mike Stump1eb44332009-09-09 15:08:12 +00008106
Douglas Gregorb98b1992009-08-11 05:31:07 +00008107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008108ExprResult
John McCall865d4472009-11-19 22:55:06 +00008109TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008110 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008111 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008112 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008113 Expr *OldBase;
8114 QualType BaseType;
8115 QualType ObjectType;
8116 if (!E->isImplicitAccess()) {
8117 OldBase = E->getBase();
8118 Base = getDerived().TransformExpr(OldBase);
8119 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008121
John McCallaa81e162009-12-01 22:10:20 +00008122 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008123 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008124 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008125 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008126 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008127 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008128 ObjectTy,
8129 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008130 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008131 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008132
John McCallb3d87482010-08-24 05:47:05 +00008133 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008134 BaseType = ((Expr*) Base.get())->getType();
8135 } else {
8136 OldBase = 0;
8137 BaseType = getDerived().TransformType(E->getBaseType());
8138 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8139 }
Mike Stump1eb44332009-09-09 15:08:12 +00008140
Douglas Gregor6cd21982009-10-20 05:58:46 +00008141 // Transform the first part of the nested-name-specifier that qualifies
8142 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008143 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008144 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008145 E->getFirstQualifierFoundInScope(),
8146 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008147
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008148 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008149 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008150 QualifierLoc
8151 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8152 ObjectType,
8153 FirstQualifierInScope);
8154 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008155 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008156 }
Mike Stump1eb44332009-09-09 15:08:12 +00008157
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008158 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8159
John McCall43fed0d2010-11-12 08:19:04 +00008160 // TODO: If this is a conversion-function-id, verify that the
8161 // destination type name (if present) resolves the same way after
8162 // instantiation as it did in the local scope.
8163
Abramo Bagnara25777432010-08-11 22:01:17 +00008164 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008165 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008166 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008168
John McCallaa81e162009-12-01 22:10:20 +00008169 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008170 // This is a reference to a member without an explicitly-specified
8171 // template argument list. Optimize for this common case.
8172 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008173 Base.get() == OldBase &&
8174 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008175 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008176 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008177 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008178 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008179
John McCall9ae2f072010-08-23 23:25:46 +00008180 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008181 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008182 E->isArrow(),
8183 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008184 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008185 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008186 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008187 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008188 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008189 }
8190
John McCalld5532b62009-11-23 01:53:49 +00008191 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008192 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8193 E->getNumTemplateArgs(),
8194 TransArgs))
8195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008196
John McCall9ae2f072010-08-23 23:25:46 +00008197 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008198 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008199 E->isArrow(),
8200 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008201 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008202 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008203 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008204 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008205 &TransArgs);
8206}
8207
8208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008209ExprResult
John McCall454feb92009-12-08 09:21:05 +00008210TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008211 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008212 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008213 QualType BaseType;
8214 if (!Old->isImplicitAccess()) {
8215 Base = getDerived().TransformExpr(Old->getBase());
8216 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008217 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008218 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8219 Old->isArrow());
8220 if (Base.isInvalid())
8221 return ExprError();
8222 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008223 } else {
8224 BaseType = getDerived().TransformType(Old->getBaseType());
8225 }
John McCall129e2df2009-11-30 22:42:35 +00008226
Douglas Gregor4c9be892011-02-28 20:01:57 +00008227 NestedNameSpecifierLoc QualifierLoc;
8228 if (Old->getQualifierLoc()) {
8229 QualifierLoc
8230 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8231 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008232 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008233 }
8234
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008235 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8236
Abramo Bagnara25777432010-08-11 22:01:17 +00008237 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008238 Sema::LookupOrdinaryName);
8239
8240 // Transform all the decls.
8241 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8242 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008243 NamedDecl *InstD = static_cast<NamedDecl*>(
8244 getDerived().TransformDecl(Old->getMemberLoc(),
8245 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008246 if (!InstD) {
8247 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8248 // This can happen because of dependent hiding.
8249 if (isa<UsingShadowDecl>(*I))
8250 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008251 else {
8252 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008253 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008254 }
John McCall9f54ad42009-12-10 09:41:52 +00008255 }
John McCall129e2df2009-11-30 22:42:35 +00008256
8257 // Expand using declarations.
8258 if (isa<UsingDecl>(InstD)) {
8259 UsingDecl *UD = cast<UsingDecl>(InstD);
8260 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8261 E = UD->shadow_end(); I != E; ++I)
8262 R.addDecl(*I);
8263 continue;
8264 }
8265
8266 R.addDecl(InstD);
8267 }
8268
8269 R.resolveKind();
8270
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008271 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008272 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008273 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008274 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008275 Old->getMemberLoc(),
8276 Old->getNamingClass()));
8277 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008278 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008279
Douglas Gregor66c45152010-04-27 16:10:10 +00008280 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008282
John McCall129e2df2009-11-30 22:42:35 +00008283 TemplateArgumentListInfo TransArgs;
8284 if (Old->hasExplicitTemplateArgs()) {
8285 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8286 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008287 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8288 Old->getNumTemplateArgs(),
8289 TransArgs))
8290 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008291 }
John McCallc2233c52010-01-15 08:34:02 +00008292
8293 // FIXME: to do this check properly, we will need to preserve the
8294 // first-qualifier-in-scope here, just in case we had a dependent
8295 // base (and therefore couldn't do the check) and a
8296 // nested-name-qualifier (and therefore could do the lookup).
8297 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008298
John McCall9ae2f072010-08-23 23:25:46 +00008299 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008300 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008301 Old->getOperatorLoc(),
8302 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008303 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008304 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008305 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008306 R,
8307 (Old->hasExplicitTemplateArgs()
8308 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008309}
8310
8311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008312ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008313TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008314 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008315 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8316 if (SubExpr.isInvalid())
8317 return ExprError();
8318
8319 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008320 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008321
8322 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8323}
8324
8325template<typename Derived>
8326ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008327TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008328 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8329 if (Pattern.isInvalid())
8330 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008331
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008332 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8333 return SemaRef.Owned(E);
8334
Douglas Gregor67fd1252011-01-14 21:20:45 +00008335 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8336 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008337}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008338
8339template<typename Derived>
8340ExprResult
8341TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8342 // If E is not value-dependent, then nothing will change when we transform it.
8343 // Note: This is an instantiation-centric view.
8344 if (!E->isValueDependent())
8345 return SemaRef.Owned(E);
8346
8347 // Note: None of the implementations of TryExpandParameterPacks can ever
8348 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008349 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008350 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8351 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008352 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008353 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008355 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008356 ShouldExpand, RetainExpansion,
8357 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008358 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008359
Douglas Gregor089e8932011-10-10 18:59:29 +00008360 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008361 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008362
Douglas Gregor089e8932011-10-10 18:59:29 +00008363 NamedDecl *Pack = E->getPack();
8364 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008365 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008366 Pack));
8367 if (!Pack)
8368 return ExprError();
8369 }
8370
Chad Rosier4a9d7952012-08-08 18:46:20 +00008371
Douglas Gregoree8aff02011-01-04 17:33:58 +00008372 // We now know the length of the parameter pack, so build a new expression
8373 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008374 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8375 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008376 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008377}
8378
Douglas Gregorbe230c32011-01-03 17:17:50 +00008379template<typename Derived>
8380ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008381TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8382 SubstNonTypeTemplateParmPackExpr *E) {
8383 // Default behavior is to do nothing with this transformation.
8384 return SemaRef.Owned(E);
8385}
8386
8387template<typename Derived>
8388ExprResult
John McCall91a57552011-07-15 05:09:51 +00008389TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8390 SubstNonTypeTemplateParmExpr *E) {
8391 // Default behavior is to do nothing with this transformation.
8392 return SemaRef.Owned(E);
8393}
8394
8395template<typename Derived>
8396ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008397TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8398 // Default behavior is to do nothing with this transformation.
8399 return SemaRef.Owned(E);
8400}
8401
8402template<typename Derived>
8403ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008404TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8405 MaterializeTemporaryExpr *E) {
8406 return getDerived().TransformExpr(E->GetTemporaryExpr());
8407}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008408
Douglas Gregor03e80032011-06-21 17:03:29 +00008409template<typename Derived>
8410ExprResult
John McCall454feb92009-12-08 09:21:05 +00008411TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008412 return SemaRef.MaybeBindToTemporary(E);
8413}
8414
8415template<typename Derived>
8416ExprResult
8417TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008418 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008419}
8420
8421template<typename Derived>
8422ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008423TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8424 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8425 if (SubExpr.isInvalid())
8426 return ExprError();
8427
8428 if (!getDerived().AlwaysRebuild() &&
8429 SubExpr.get() == E->getSubExpr())
8430 return SemaRef.Owned(E);
8431
8432 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008433}
8434
8435template<typename Derived>
8436ExprResult
8437TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8438 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008439 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008440 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008441 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008442 /*IsCall=*/false, Elements, &ArgChanged))
8443 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008444
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008445 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8446 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008447
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008448 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8449 Elements.data(),
8450 Elements.size());
8451}
8452
8453template<typename Derived>
8454ExprResult
8455TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008456 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008458 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008459 bool ArgChanged = false;
8460 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8461 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008462
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008463 if (OrigElement.isPackExpansion()) {
8464 // This key/value element is a pack expansion.
8465 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8466 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8467 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8468 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8469
8470 // Determine whether the set of unexpanded parameter packs can
8471 // and should be expanded.
8472 bool Expand = true;
8473 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008474 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8475 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008476 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8477 OrigElement.Value->getLocEnd());
8478 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8479 PatternRange,
8480 Unexpanded,
8481 Expand, RetainExpansion,
8482 NumExpansions))
8483 return ExprError();
8484
8485 if (!Expand) {
8486 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008487 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008488 // expansion.
8489 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8490 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8491 if (Key.isInvalid())
8492 return ExprError();
8493
8494 if (Key.get() != OrigElement.Key)
8495 ArgChanged = true;
8496
8497 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8498 if (Value.isInvalid())
8499 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008500
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008501 if (Value.get() != OrigElement.Value)
8502 ArgChanged = true;
8503
Chad Rosier4a9d7952012-08-08 18:46:20 +00008504 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008505 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8506 };
8507 Elements.push_back(Expansion);
8508 continue;
8509 }
8510
8511 // Record right away that the argument was changed. This needs
8512 // to happen even if the array expands to nothing.
8513 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008514
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008515 // The transform has determined that we should perform an elementwise
8516 // expansion of the pattern. Do so.
8517 for (unsigned I = 0; I != *NumExpansions; ++I) {
8518 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8519 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8520 if (Key.isInvalid())
8521 return ExprError();
8522
8523 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8524 if (Value.isInvalid())
8525 return ExprError();
8526
Chad Rosier4a9d7952012-08-08 18:46:20 +00008527 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008528 Key.get(), Value.get(), SourceLocation(), NumExpansions
8529 };
8530
8531 // If any unexpanded parameter packs remain, we still have a
8532 // pack expansion.
8533 if (Key.get()->containsUnexpandedParameterPack() ||
8534 Value.get()->containsUnexpandedParameterPack())
8535 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008536
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008537 Elements.push_back(Element);
8538 }
8539
8540 // We've finished with this pack expansion.
8541 continue;
8542 }
8543
8544 // Transform and check key.
8545 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8546 if (Key.isInvalid())
8547 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008548
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008549 if (Key.get() != OrigElement.Key)
8550 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008551
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008552 // Transform and check value.
8553 ExprResult Value
8554 = getDerived().TransformExpr(OrigElement.Value);
8555 if (Value.isInvalid())
8556 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008557
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008558 if (Value.get() != OrigElement.Value)
8559 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008560
8561 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008562 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008563 };
8564 Elements.push_back(Element);
8565 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008567 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8568 return SemaRef.MaybeBindToTemporary(E);
8569
8570 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8571 Elements.data(),
8572 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008573}
8574
Mike Stump1eb44332009-09-09 15:08:12 +00008575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008576ExprResult
John McCall454feb92009-12-08 09:21:05 +00008577TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008578 TypeSourceInfo *EncodedTypeInfo
8579 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8580 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008582
Douglas Gregorb98b1992009-08-11 05:31:07 +00008583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008584 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008585 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008586
8587 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008588 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008589 E->getRParenLoc());
8590}
Mike Stump1eb44332009-09-09 15:08:12 +00008591
Douglas Gregorb98b1992009-08-11 05:31:07 +00008592template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008593ExprResult TreeTransform<Derived>::
8594TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8595 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8596 if (result.isInvalid()) return ExprError();
8597 Expr *subExpr = result.take();
8598
8599 if (!getDerived().AlwaysRebuild() &&
8600 subExpr == E->getSubExpr())
8601 return SemaRef.Owned(E);
8602
8603 return SemaRef.Owned(new(SemaRef.Context)
8604 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8605}
8606
8607template<typename Derived>
8608ExprResult TreeTransform<Derived>::
8609TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008610 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008611 = getDerived().TransformType(E->getTypeInfoAsWritten());
8612 if (!TSInfo)
8613 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008614
John McCallf85e1932011-06-15 23:02:42 +00008615 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008616 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008617 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008618
John McCallf85e1932011-06-15 23:02:42 +00008619 if (!getDerived().AlwaysRebuild() &&
8620 TSInfo == E->getTypeInfoAsWritten() &&
8621 Result.get() == E->getSubExpr())
8622 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008623
John McCallf85e1932011-06-15 23:02:42 +00008624 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008625 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008626 Result.get());
8627}
8628
8629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008630ExprResult
John McCall454feb92009-12-08 09:21:05 +00008631TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008632 // Transform arguments.
8633 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008634 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008635 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008636 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008637 &ArgChanged))
8638 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008639
Douglas Gregor92e986e2010-04-22 16:44:27 +00008640 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8641 // Class message: transform the receiver type.
8642 TypeSourceInfo *ReceiverTypeInfo
8643 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8644 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008645 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008646
Douglas Gregor92e986e2010-04-22 16:44:27 +00008647 // If nothing changed, just retain the existing message send.
8648 if (!getDerived().AlwaysRebuild() &&
8649 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008650 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008651
8652 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008653 SmallVector<SourceLocation, 16> SelLocs;
8654 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008655 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8656 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008657 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008658 E->getMethodDecl(),
8659 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008660 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008661 E->getRightLoc());
8662 }
8663
8664 // Instance message: transform the receiver
8665 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8666 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008667 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008668 = getDerived().TransformExpr(E->getInstanceReceiver());
8669 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008670 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008671
8672 // If nothing changed, just retain the existing message send.
8673 if (!getDerived().AlwaysRebuild() &&
8674 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008675 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008676
Douglas Gregor92e986e2010-04-22 16:44:27 +00008677 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008678 SmallVector<SourceLocation, 16> SelLocs;
8679 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008680 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008681 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008682 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008683 E->getMethodDecl(),
8684 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008685 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008686 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008687}
8688
Mike Stump1eb44332009-09-09 15:08:12 +00008689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008690ExprResult
John McCall454feb92009-12-08 09:21:05 +00008691TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008692 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008693}
8694
Mike Stump1eb44332009-09-09 15:08:12 +00008695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008696ExprResult
John McCall454feb92009-12-08 09:21:05 +00008697TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008698 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008699}
8700
Mike Stump1eb44332009-09-09 15:08:12 +00008701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008702ExprResult
John McCall454feb92009-12-08 09:21:05 +00008703TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008704 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008705 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008706 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008707 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008708
8709 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008710
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008711 // If nothing changed, just retain the existing expression.
8712 if (!getDerived().AlwaysRebuild() &&
8713 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008714 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008715
John McCall9ae2f072010-08-23 23:25:46 +00008716 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008717 E->getLocation(),
8718 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008719}
8720
Mike Stump1eb44332009-09-09 15:08:12 +00008721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008722ExprResult
John McCall454feb92009-12-08 09:21:05 +00008723TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008724 // 'super' and types never change. Property never changes. Just
8725 // retain the existing expression.
8726 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008727 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008728
Douglas Gregore3303542010-04-26 20:47:02 +00008729 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008731 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008732 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008733
Douglas Gregore3303542010-04-26 20:47:02 +00008734 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008735
Douglas Gregore3303542010-04-26 20:47:02 +00008736 // If nothing changed, just retain the existing expression.
8737 if (!getDerived().AlwaysRebuild() &&
8738 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008739 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008740
John McCall12f78a62010-12-02 01:19:52 +00008741 if (E->isExplicitProperty())
8742 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8743 E->getExplicitProperty(),
8744 E->getLocation());
8745
8746 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008747 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008748 E->getImplicitPropertyGetter(),
8749 E->getImplicitPropertySetter(),
8750 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008751}
8752
Mike Stump1eb44332009-09-09 15:08:12 +00008753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008754ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008755TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8756 // Transform the base expression.
8757 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8758 if (Base.isInvalid())
8759 return ExprError();
8760
8761 // Transform the key expression.
8762 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8763 if (Key.isInvalid())
8764 return ExprError();
8765
8766 // If nothing changed, just retain the existing expression.
8767 if (!getDerived().AlwaysRebuild() &&
8768 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8769 return SemaRef.Owned(E);
8770
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008772 Base.get(), Key.get(),
8773 E->getAtIndexMethodDecl(),
8774 E->setAtIndexMethodDecl());
8775}
8776
8777template<typename Derived>
8778ExprResult
John McCall454feb92009-12-08 09:21:05 +00008779TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008780 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008781 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008782 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008783 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008784
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008785 // If nothing changed, just retain the existing expression.
8786 if (!getDerived().AlwaysRebuild() &&
8787 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008788 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008789
John McCall9ae2f072010-08-23 23:25:46 +00008790 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008791 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008792 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008793}
8794
Mike Stump1eb44332009-09-09 15:08:12 +00008795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008796ExprResult
John McCall454feb92009-12-08 09:21:05 +00008797TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008798 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008799 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008800 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008801 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008802 SubExprs, &ArgumentChanged))
8803 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008804
Douglas Gregorb98b1992009-08-11 05:31:07 +00008805 if (!getDerived().AlwaysRebuild() &&
8806 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008807 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008808
Douglas Gregorb98b1992009-08-11 05:31:07 +00008809 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008810 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008811 E->getRParenLoc());
8812}
8813
Mike Stump1eb44332009-09-09 15:08:12 +00008814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008815ExprResult
John McCall454feb92009-12-08 09:21:05 +00008816TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008817 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008818
John McCallc6ac9c32011-02-04 18:33:18 +00008819 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8820 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8821
8822 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008823 blockScope->TheDecl->setBlockMissingReturnType(
8824 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008825
Chris Lattner686775d2011-07-20 06:58:45 +00008826 SmallVector<ParmVarDecl*, 4> params;
8827 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008828
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008829 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008830 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8831 oldBlock->param_begin(),
8832 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008833 0, paramTypes, &params)) {
8834 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008835 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008836 }
John McCallc6ac9c32011-02-04 18:33:18 +00008837
Jordan Rose09189892013-03-08 22:25:36 +00008838 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008839 QualType exprResultType =
8840 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008841
8842 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008843 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008844 getSema().Diag(E->getCaretLocation(),
8845 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008846 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008847 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008848 return ExprError();
8849 }
John McCall711c52b2011-01-05 12:14:39 +00008850
Jordan Rosebea522f2013-03-08 21:51:21 +00008851 QualType functionType =
8852 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008853 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008854 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008855
8856 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008857 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008858 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008859
8860 if (!oldBlock->blockMissingReturnType()) {
8861 blockScope->HasImplicitReturnType = false;
8862 blockScope->ReturnType = exprResultType;
8863 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008864
John McCall711c52b2011-01-05 12:14:39 +00008865 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008866 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008867 if (body.isInvalid()) {
8868 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008869 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008870 }
John McCall711c52b2011-01-05 12:14:39 +00008871
John McCallc6ac9c32011-02-04 18:33:18 +00008872#ifndef NDEBUG
8873 // In builds with assertions, make sure that we captured everything we
8874 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008875 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8876 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8877 e = oldBlock->capture_end(); i != e; ++i) {
8878 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008879
Douglas Gregorfc921372011-05-20 15:32:55 +00008880 // Ignore parameter packs.
8881 if (isa<ParmVarDecl>(oldCapture) &&
8882 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8883 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008884
Douglas Gregorfc921372011-05-20 15:32:55 +00008885 VarDecl *newCapture =
8886 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8887 oldCapture));
8888 assert(blockScope->CaptureMap.count(newCapture));
8889 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008890 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008891 }
8892#endif
8893
8894 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8895 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008896}
8897
Mike Stump1eb44332009-09-09 15:08:12 +00008898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008899ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008900TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008901 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008902}
Eli Friedman276b0612011-10-11 02:20:01 +00008903
8904template<typename Derived>
8905ExprResult
8906TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008907 QualType RetTy = getDerived().TransformType(E->getType());
8908 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008909 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008910 SubExprs.reserve(E->getNumSubExprs());
8911 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8912 SubExprs, &ArgumentChanged))
8913 return ExprError();
8914
8915 if (!getDerived().AlwaysRebuild() &&
8916 !ArgumentChanged)
8917 return SemaRef.Owned(E);
8918
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008919 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008920 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008921}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008922
Douglas Gregorb98b1992009-08-11 05:31:07 +00008923//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008924// Type reconstruction
8925//===----------------------------------------------------------------------===//
8926
Mike Stump1eb44332009-09-09 15:08:12 +00008927template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008928QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8929 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008930 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008931 getDerived().getBaseEntity());
8932}
8933
Mike Stump1eb44332009-09-09 15:08:12 +00008934template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008935QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8936 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008937 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008938 getDerived().getBaseEntity());
8939}
8940
Mike Stump1eb44332009-09-09 15:08:12 +00008941template<typename Derived>
8942QualType
John McCall85737a72009-10-30 00:06:24 +00008943TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8944 bool WrittenAsLValue,
8945 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008946 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008947 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008948}
8949
8950template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008951QualType
John McCall85737a72009-10-30 00:06:24 +00008952TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8953 QualType ClassType,
8954 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008955 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008956 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008957}
8958
8959template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008960QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8962 ArrayType::ArraySizeModifier SizeMod,
8963 const llvm::APInt *Size,
8964 Expr *SizeExpr,
8965 unsigned IndexTypeQuals,
8966 SourceRange BracketsRange) {
8967 if (SizeExpr || !Size)
8968 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8969 IndexTypeQuals, BracketsRange,
8970 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008971
8972 QualType Types[] = {
8973 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8974 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8975 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008976 };
8977 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8978 QualType SizeType;
8979 for (unsigned I = 0; I != NumTypes; ++I)
8980 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8981 SizeType = Types[I];
8982 break;
8983 }
Mike Stump1eb44332009-09-09 15:08:12 +00008984
Eli Friedman01f276d2012-01-25 23:20:27 +00008985 // Note that we can return a VariableArrayType here in the case where
8986 // the element type was a dependent VariableArrayType.
8987 IntegerLiteral *ArraySize
8988 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8989 /*FIXME*/BracketsRange.getBegin());
8990 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008992 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008993}
Mike Stump1eb44332009-09-09 15:08:12 +00008994
Douglas Gregor577f75a2009-08-04 16:50:30 +00008995template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008996QualType
8997TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008998 ArrayType::ArraySizeModifier SizeMod,
8999 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009000 unsigned IndexTypeQuals,
9001 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009002 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009003 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009004}
9005
9006template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009007QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009008TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009010 unsigned IndexTypeQuals,
9011 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009012 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009013 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009014}
Mike Stump1eb44332009-09-09 15:08:12 +00009015
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009017QualType
9018TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009019 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009020 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009021 unsigned IndexTypeQuals,
9022 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009023 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009024 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009025 IndexTypeQuals, BracketsRange);
9026}
9027
9028template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009029QualType
9030TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009031 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009032 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009033 unsigned IndexTypeQuals,
9034 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009035 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009036 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009037 IndexTypeQuals, BracketsRange);
9038}
9039
9040template<typename Derived>
9041QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009042 unsigned NumElements,
9043 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009044 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009045 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009046}
Mike Stump1eb44332009-09-09 15:08:12 +00009047
Douglas Gregor577f75a2009-08-04 16:50:30 +00009048template<typename Derived>
9049QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9050 unsigned NumElements,
9051 SourceLocation AttributeLoc) {
9052 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9053 NumElements, true);
9054 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009055 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9056 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009057 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009058}
Mike Stump1eb44332009-09-09 15:08:12 +00009059
Douglas Gregor577f75a2009-08-04 16:50:30 +00009060template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009061QualType
9062TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009063 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009064 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009065 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009066}
Mike Stump1eb44332009-09-09 15:08:12 +00009067
Douglas Gregor577f75a2009-08-04 16:50:30 +00009068template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009069QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9070 QualType T,
9071 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009072 const FunctionProtoType::ExtProtoInfo &EPI) {
9073 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009075 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009076 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009077}
Mike Stump1eb44332009-09-09 15:08:12 +00009078
Douglas Gregor577f75a2009-08-04 16:50:30 +00009079template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009080QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9081 return SemaRef.Context.getFunctionNoProtoType(T);
9082}
9083
9084template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009085QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9086 assert(D && "no decl found");
9087 if (D->isInvalidDecl()) return QualType();
9088
Douglas Gregor92e986e2010-04-22 16:44:27 +00009089 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009090 TypeDecl *Ty;
9091 if (isa<UsingDecl>(D)) {
9092 UsingDecl *Using = cast<UsingDecl>(D);
9093 assert(Using->isTypeName() &&
9094 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9095
9096 // A valid resolved using typename decl points to exactly one type decl.
9097 assert(++Using->shadow_begin() == Using->shadow_end());
9098 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009099
John McCalled976492009-12-04 22:46:56 +00009100 } else {
9101 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9102 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9103 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9104 }
9105
9106 return SemaRef.Context.getTypeDeclType(Ty);
9107}
9108
9109template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009110QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9111 SourceLocation Loc) {
9112 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009113}
9114
9115template<typename Derived>
9116QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9117 return SemaRef.Context.getTypeOfType(Underlying);
9118}
9119
9120template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009121QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9122 SourceLocation Loc) {
9123 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009124}
9125
9126template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009127QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9128 UnaryTransformType::UTTKind UKind,
9129 SourceLocation Loc) {
9130 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9131}
9132
9133template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009134QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009135 TemplateName Template,
9136 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009137 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009138 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009139}
Mike Stump1eb44332009-09-09 15:08:12 +00009140
Douglas Gregordcee1a12009-08-06 05:28:30 +00009141template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009142QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9143 SourceLocation KWLoc) {
9144 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9145}
9146
9147template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009148TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009149TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009150 bool TemplateKW,
9151 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009152 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009153 Template);
9154}
9155
9156template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009157TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009158TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9159 const IdentifierInfo &Name,
9160 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009161 QualType ObjectType,
9162 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009163 UnqualifiedId TemplateName;
9164 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009165 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009166 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009167 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009168 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009169 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009170 /*EnteringContext=*/false,
9171 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009172 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009173}
Mike Stump1eb44332009-09-09 15:08:12 +00009174
Douglas Gregorb98b1992009-08-11 05:31:07 +00009175template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009176TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009177TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009178 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009179 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009180 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009181 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009182 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009183 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009184 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009185 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009186 Sema::TemplateTy Template;
9187 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009188 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009189 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009190 /*EnteringContext=*/false,
9191 Template);
9192 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009193}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009194
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009196ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009197TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9198 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009199 Expr *OrigCallee,
9200 Expr *First,
9201 Expr *Second) {
9202 Expr *Callee = OrigCallee->IgnoreParenCasts();
9203 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009204
Douglas Gregorb98b1992009-08-11 05:31:07 +00009205 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009206 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009207 if (!First->getType()->isOverloadableType() &&
9208 !Second->getType()->isOverloadableType())
9209 return getSema().CreateBuiltinArraySubscriptExpr(First,
9210 Callee->getLocStart(),
9211 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009212 } else if (Op == OO_Arrow) {
9213 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009214 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9215 } else if (Second == 0 || isPostIncDec) {
9216 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009217 // The argument is not of overloadable type, so try to create a
9218 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009219 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009220 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009221
John McCall9ae2f072010-08-23 23:25:46 +00009222 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009223 }
9224 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009225 if (!First->getType()->isOverloadableType() &&
9226 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009227 // Neither of the arguments is an overloadable type, so try to
9228 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009229 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009230 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009231 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009232 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009234
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009235 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009236 }
9237 }
Mike Stump1eb44332009-09-09 15:08:12 +00009238
9239 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009240 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009241 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009242
John McCall9ae2f072010-08-23 23:25:46 +00009243 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009244 assert(ULE->requiresADL());
9245
9246 // FIXME: Do we have to check
9247 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009248 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009249 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009250 // If we've resolved this to a particular non-member function, just call
9251 // that function. If we resolved it to a member function,
9252 // CreateOverloaded* will find that function for us.
9253 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9254 if (!isa<CXXMethodDecl>(ND))
9255 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009256 }
Mike Stump1eb44332009-09-09 15:08:12 +00009257
Douglas Gregorb98b1992009-08-11 05:31:07 +00009258 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009259 Expr *Args[2] = { First, Second };
9260 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009261
Douglas Gregorb98b1992009-08-11 05:31:07 +00009262 // Create the overloaded operator invocation for unary operators.
9263 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009264 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009265 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009266 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009267 }
Mike Stump1eb44332009-09-09 15:08:12 +00009268
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009269 if (Op == OO_Subscript) {
9270 SourceLocation LBrace;
9271 SourceLocation RBrace;
9272
9273 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9274 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9275 LBrace = SourceLocation::getFromRawEncoding(
9276 NameLoc.CXXOperatorName.BeginOpNameLoc);
9277 RBrace = SourceLocation::getFromRawEncoding(
9278 NameLoc.CXXOperatorName.EndOpNameLoc);
9279 } else {
9280 LBrace = Callee->getLocStart();
9281 RBrace = OpLoc;
9282 }
9283
9284 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9285 First, Second);
9286 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009287
Douglas Gregorb98b1992009-08-11 05:31:07 +00009288 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009289 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009290 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009291 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9292 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009294
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009295 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009296}
Mike Stump1eb44332009-09-09 15:08:12 +00009297
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009298template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009299ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009300TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009301 SourceLocation OperatorLoc,
9302 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009303 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009304 TypeSourceInfo *ScopeType,
9305 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009306 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009307 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009308 QualType BaseType = Base->getType();
9309 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009310 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009311 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009312 !BaseType->getAs<PointerType>()->getPointeeType()
9313 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009314 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009315 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009316 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009317 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009318 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009319 /*FIXME?*/true);
9320 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009321
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009322 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009323 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9324 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9325 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9326 NameInfo.setNamedTypeInfo(DestroyedType);
9327
Richard Smith6314db92012-05-15 06:15:11 +00009328 // The scope type is now known to be a valid nested name specifier
9329 // component. Tack it on to the end of the nested name specifier.
9330 if (ScopeType)
9331 SS.Extend(SemaRef.Context, SourceLocation(),
9332 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009333
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009334 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009335 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009336 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009337 SS, TemplateKWLoc,
9338 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009339 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009340 /*TemplateArgs*/ 0);
9341}
9342
Douglas Gregor577f75a2009-08-04 16:50:30 +00009343} // end namespace clang
9344
9345#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H