blob: e228d7a0f2bddd5dc46e74c087f7eccaa067e607 [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(),
3997 OldParm->getStorageClassAsWritten(),
3998 /* DefArg */ NULL);
3999 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4000 OldParm->getFunctionScopeIndex() + indexAdjustment);
4001 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00004002}
4003
4004template<typename Derived>
4005bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00004006 TransformFunctionTypeParams(SourceLocation Loc,
4007 ParmVarDecl **Params, unsigned NumParams,
4008 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00004009 SmallVectorImpl<QualType> &OutParamTypes,
4010 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00004011 int indexAdjustment = 0;
4012
Douglas Gregora009b592011-01-07 00:20:55 +00004013 for (unsigned i = 0; i != NumParams; ++i) {
4014 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00004015 assert(OldParm->getFunctionScopeIndex() == i);
4016
David Blaikiedc84cd52013-02-20 22:23:23 +00004017 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004018 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004019 if (OldParm->isParameterPack()) {
4020 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00004021 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00004022
Douglas Gregor603cfb42011-01-05 23:12:31 +00004023 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004024 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00004025 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004026 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4027 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004028 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4029
Douglas Gregor603cfb42011-01-05 23:12:31 +00004030 // Determine whether we should expand the parameter packs.
4031 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004032 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004033 Optional<unsigned> OrigNumExpansions =
4034 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004035 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004036 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4037 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004038 Unexpanded,
4039 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004040 RetainExpansion,
4041 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042 return true;
4043 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004044
Douglas Gregor603cfb42011-01-05 23:12:31 +00004045 if (ShouldExpand) {
4046 // Expand the function parameter pack into multiple, separate
4047 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004048 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004049 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004050 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004051 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004052 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004053 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004054 OrigNumExpansions,
4055 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004056 if (!NewParm)
4057 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004058
Douglas Gregora009b592011-01-07 00:20:55 +00004059 OutParamTypes.push_back(NewParm->getType());
4060 if (PVars)
4061 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 }
Douglas Gregord3731192011-01-10 07:32:04 +00004063
4064 // If we're supposed to retain a pack expansion, do so by temporarily
4065 // forgetting the partially-substituted parameter pack.
4066 if (RetainExpansion) {
4067 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004068 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004069 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004070 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004071 OrigNumExpansions,
4072 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004073 if (!NewParm)
4074 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004075
Douglas Gregord3731192011-01-10 07:32:04 +00004076 OutParamTypes.push_back(NewParm->getType());
4077 if (PVars)
4078 PVars->push_back(NewParm);
4079 }
4080
John McCallfb44de92011-05-01 22:35:37 +00004081 // The next parameter should have the same adjustment as the
4082 // last thing we pushed, but we post-incremented indexAdjustment
4083 // on every push. Also, if we push nothing, the adjustment should
4084 // go down by one.
4085 indexAdjustment--;
4086
Douglas Gregor603cfb42011-01-05 23:12:31 +00004087 // We're done with the pack expansion.
4088 continue;
4089 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004090
4091 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004092 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004093 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4094 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004095 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004096 NumExpansions,
4097 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004098 } else {
David Blaikiedc84cd52013-02-20 22:23:23 +00004099 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie66874fb2013-02-21 01:47:18 +00004100 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004101 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004102
John McCall21ef0fa2010-03-11 09:03:00 +00004103 if (!NewParm)
4104 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004105
Douglas Gregora009b592011-01-07 00:20:55 +00004106 OutParamTypes.push_back(NewParm->getType());
4107 if (PVars)
4108 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004109 continue;
4110 }
John McCall21ef0fa2010-03-11 09:03:00 +00004111
4112 // Deal with the possibility that we don't have a parameter
4113 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004114 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004115 bool IsPackExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00004116 Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004117 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004118 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004119 = dyn_cast<PackExpansionType>(OldType)) {
4120 // We have a function parameter pack that may need to be expanded.
4121 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004122 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004123 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004124
Douglas Gregor603cfb42011-01-05 23:12:31 +00004125 // Determine whether we should expand the parameter packs.
4126 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004127 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004128 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004129 Unexpanded,
4130 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004131 RetainExpansion,
4132 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004133 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004134 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004135
Douglas Gregor603cfb42011-01-05 23:12:31 +00004136 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004137 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004138 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004139 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4141 QualType NewType = getDerived().TransformType(Pattern);
4142 if (NewType.isNull())
4143 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004144
Douglas Gregora009b592011-01-07 00:20:55 +00004145 OutParamTypes.push_back(NewType);
4146 if (PVars)
4147 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004148 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004149
Douglas Gregor603cfb42011-01-05 23:12:31 +00004150 // We're done with the pack expansion.
4151 continue;
4152 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004153
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004154 // If we're supposed to retain a pack expansion, do so by temporarily
4155 // forgetting the partially-substituted parameter pack.
4156 if (RetainExpansion) {
4157 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4158 QualType NewType = getDerived().TransformType(Pattern);
4159 if (NewType.isNull())
4160 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004161
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004162 OutParamTypes.push_back(NewType);
4163 if (PVars)
4164 PVars->push_back(0);
4165 }
Douglas Gregord3731192011-01-10 07:32:04 +00004166
Chad Rosier4a9d7952012-08-08 18:46:20 +00004167 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004168 // expansion.
4169 OldType = Expansion->getPattern();
4170 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004171 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4172 NewType = getDerived().TransformType(OldType);
4173 } else {
4174 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004175 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004176
Douglas Gregor603cfb42011-01-05 23:12:31 +00004177 if (NewType.isNull())
4178 return true;
4179
4180 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004181 NewType = getSema().Context.getPackExpansionType(NewType,
4182 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004183
Douglas Gregora009b592011-01-07 00:20:55 +00004184 OutParamTypes.push_back(NewType);
4185 if (PVars)
4186 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004187 }
4188
John McCallfb44de92011-05-01 22:35:37 +00004189#ifndef NDEBUG
4190 if (PVars) {
4191 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4192 if (ParmVarDecl *parm = (*PVars)[i])
4193 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004194 }
John McCallfb44de92011-05-01 22:35:37 +00004195#endif
4196
4197 return false;
4198}
John McCall21ef0fa2010-03-11 09:03:00 +00004199
4200template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004201QualType
John McCalla2becad2009-10-21 00:40:46 +00004202TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004203 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004204 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4205}
4206
4207template<typename Derived>
4208QualType
4209TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4210 FunctionProtoTypeLoc TL,
4211 CXXRecordDecl *ThisContext,
4212 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004213 // Transform the parameters and return type.
4214 //
Richard Smithe6975e92012-04-17 00:58:00 +00004215 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004216 // When the function has a trailing return type, we instantiate the
4217 // parameters before the return type, since the return type can then refer
4218 // to the parameters themselves (via decltype, sizeof, etc.).
4219 //
Chris Lattner686775d2011-07-20 06:58:45 +00004220 SmallVector<QualType, 4> ParamTypes;
4221 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004222 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004223
Douglas Gregordab60ad2010-10-01 18:44:50 +00004224 QualType ResultType;
4225
Richard Smith9fbf3272012-08-14 22:51:13 +00004226 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004227 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004228 TL.getParmArray(),
4229 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004230 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004231 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004232 return QualType();
4233
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004234 {
4235 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004236 // If a declaration declares a member function or member function
4237 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004238 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004239 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004240 // declarator.
4241 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004242
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004243 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4244 if (ResultType.isNull())
4245 return QualType();
4246 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004247 }
4248 else {
4249 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4250 if (ResultType.isNull())
4251 return QualType();
4252
Chad Rosier4a9d7952012-08-08 18:46:20 +00004253 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004254 TL.getParmArray(),
4255 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004256 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004257 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004258 return QualType();
4259 }
4260
Richard Smithe6975e92012-04-17 00:58:00 +00004261 // FIXME: Need to transform the exception-specification too.
4262
John McCalla2becad2009-10-21 00:40:46 +00004263 QualType Result = TL.getType();
4264 if (getDerived().AlwaysRebuild() ||
4265 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004266 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004267 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
Jordan Rosebea522f2013-03-08 21:51:21 +00004268 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00004269 T->getExtProtoInfo());
John McCalla2becad2009-10-21 00:40:46 +00004270 if (Result.isNull())
4271 return QualType();
4272 }
Mike Stump1eb44332009-09-09 15:08:12 +00004273
John McCalla2becad2009-10-21 00:40:46 +00004274 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004275 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004276 NewTL.setLParenLoc(TL.getLParenLoc());
4277 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004278 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004279 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4280 NewTL.setArg(i, ParamDecls[i]);
4281
4282 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
Douglas Gregor577f75a2009-08-04 16:50:30 +00004285template<typename Derived>
4286QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004287 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004288 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004289 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004290 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4291 if (ResultType.isNull())
4292 return QualType();
4293
4294 QualType Result = TL.getType();
4295 if (getDerived().AlwaysRebuild() ||
4296 ResultType != T->getResultType())
4297 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4298
4299 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004300 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004301 NewTL.setLParenLoc(TL.getLParenLoc());
4302 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004303 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004304
4305 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004306}
Mike Stump1eb44332009-09-09 15:08:12 +00004307
John McCalled976492009-12-04 22:46:56 +00004308template<typename Derived> QualType
4309TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004310 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004311 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004312 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004313 if (!D)
4314 return QualType();
4315
4316 QualType Result = TL.getType();
4317 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4318 Result = getDerived().RebuildUnresolvedUsingType(D);
4319 if (Result.isNull())
4320 return QualType();
4321 }
4322
4323 // We might get an arbitrary type spec type back. We should at
4324 // least always get a type spec type, though.
4325 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4326 NewTL.setNameLoc(TL.getNameLoc());
4327
4328 return Result;
4329}
4330
Douglas Gregor577f75a2009-08-04 16:50:30 +00004331template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004332QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004333 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004334 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004335 TypedefNameDecl *Typedef
4336 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4337 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004338 if (!Typedef)
4339 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004340
John McCalla2becad2009-10-21 00:40:46 +00004341 QualType Result = TL.getType();
4342 if (getDerived().AlwaysRebuild() ||
4343 Typedef != T->getDecl()) {
4344 Result = getDerived().RebuildTypedefType(Typedef);
4345 if (Result.isNull())
4346 return QualType();
4347 }
Mike Stump1eb44332009-09-09 15:08:12 +00004348
John McCalla2becad2009-10-21 00:40:46 +00004349 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4350 NewTL.setNameLoc(TL.getNameLoc());
4351
4352 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004353}
Mike Stump1eb44332009-09-09 15:08:12 +00004354
Douglas Gregor577f75a2009-08-04 16:50:30 +00004355template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004356QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004357 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004358 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004359 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4360 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004361
John McCall60d7b3a2010-08-24 06:29:42 +00004362 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004363 if (E.isInvalid())
4364 return QualType();
4365
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004366 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4367 if (E.isInvalid())
4368 return QualType();
4369
John McCalla2becad2009-10-21 00:40:46 +00004370 QualType Result = TL.getType();
4371 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004372 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004373 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004374 if (Result.isNull())
4375 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004376 }
John McCalla2becad2009-10-21 00:40:46 +00004377 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004378
John McCalla2becad2009-10-21 00:40:46 +00004379 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004380 NewTL.setTypeofLoc(TL.getTypeofLoc());
4381 NewTL.setLParenLoc(TL.getLParenLoc());
4382 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004383
4384 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004385}
Mike Stump1eb44332009-09-09 15:08:12 +00004386
4387template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004388QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004389 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004390 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4391 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4392 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004393 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004394
John McCalla2becad2009-10-21 00:40:46 +00004395 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004396 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4397 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004398 if (Result.isNull())
4399 return QualType();
4400 }
Mike Stump1eb44332009-09-09 15:08:12 +00004401
John McCalla2becad2009-10-21 00:40:46 +00004402 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004403 NewTL.setTypeofLoc(TL.getTypeofLoc());
4404 NewTL.setLParenLoc(TL.getLParenLoc());
4405 NewTL.setRParenLoc(TL.getRParenLoc());
4406 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004407
4408 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004409}
Mike Stump1eb44332009-09-09 15:08:12 +00004410
4411template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004412QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004413 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004414 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004415
Douglas Gregor670444e2009-08-04 22:27:00 +00004416 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004417 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4418 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004419
John McCall60d7b3a2010-08-24 06:29:42 +00004420 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421 if (E.isInvalid())
4422 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004423
Richard Smith76f3f692012-02-22 02:04:18 +00004424 E = getSema().ActOnDecltypeExpression(E.take());
4425 if (E.isInvalid())
4426 return QualType();
4427
John McCalla2becad2009-10-21 00:40:46 +00004428 QualType Result = TL.getType();
4429 if (getDerived().AlwaysRebuild() ||
4430 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004431 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004432 if (Result.isNull())
4433 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434 }
John McCalla2becad2009-10-21 00:40:46 +00004435 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004436
John McCalla2becad2009-10-21 00:40:46 +00004437 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4438 NewTL.setNameLoc(TL.getNameLoc());
4439
4440 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004441}
4442
4443template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004444QualType TreeTransform<Derived>::TransformUnaryTransformType(
4445 TypeLocBuilder &TLB,
4446 UnaryTransformTypeLoc TL) {
4447 QualType Result = TL.getType();
4448 if (Result->isDependentType()) {
4449 const UnaryTransformType *T = TL.getTypePtr();
4450 QualType NewBase =
4451 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4452 Result = getDerived().RebuildUnaryTransformType(NewBase,
4453 T->getUTTKind(),
4454 TL.getKWLoc());
4455 if (Result.isNull())
4456 return QualType();
4457 }
4458
4459 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4460 NewTL.setKWLoc(TL.getKWLoc());
4461 NewTL.setParensRange(TL.getParensRange());
4462 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4463 return Result;
4464}
4465
4466template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004467QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4468 AutoTypeLoc TL) {
4469 const AutoType *T = TL.getTypePtr();
4470 QualType OldDeduced = T->getDeducedType();
4471 QualType NewDeduced;
4472 if (!OldDeduced.isNull()) {
4473 NewDeduced = getDerived().TransformType(OldDeduced);
4474 if (NewDeduced.isNull())
4475 return QualType();
4476 }
4477
4478 QualType Result = TL.getType();
4479 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4480 Result = getDerived().RebuildAutoType(NewDeduced);
4481 if (Result.isNull())
4482 return QualType();
4483 }
4484
4485 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4486 NewTL.setNameLoc(TL.getNameLoc());
4487
4488 return Result;
4489}
4490
4491template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004492QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004493 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004494 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004495 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004496 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4497 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004498 if (!Record)
4499 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004500
John McCalla2becad2009-10-21 00:40:46 +00004501 QualType Result = TL.getType();
4502 if (getDerived().AlwaysRebuild() ||
4503 Record != T->getDecl()) {
4504 Result = getDerived().RebuildRecordType(Record);
4505 if (Result.isNull())
4506 return QualType();
4507 }
Mike Stump1eb44332009-09-09 15:08:12 +00004508
John McCalla2becad2009-10-21 00:40:46 +00004509 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4510 NewTL.setNameLoc(TL.getNameLoc());
4511
4512 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004513}
Mike Stump1eb44332009-09-09 15:08:12 +00004514
4515template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004516QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004517 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004518 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004519 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004520 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4521 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004522 if (!Enum)
4523 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004524
John McCalla2becad2009-10-21 00:40:46 +00004525 QualType Result = TL.getType();
4526 if (getDerived().AlwaysRebuild() ||
4527 Enum != T->getDecl()) {
4528 Result = getDerived().RebuildEnumType(Enum);
4529 if (Result.isNull())
4530 return QualType();
4531 }
Mike Stump1eb44332009-09-09 15:08:12 +00004532
John McCalla2becad2009-10-21 00:40:46 +00004533 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4534 NewTL.setNameLoc(TL.getNameLoc());
4535
4536 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537}
John McCall7da24312009-09-05 00:15:47 +00004538
John McCall3cb0ebd2010-03-10 03:28:59 +00004539template<typename Derived>
4540QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4541 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004542 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004543 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4544 TL.getTypePtr()->getDecl());
4545 if (!D) return QualType();
4546
4547 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4548 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4549 return T;
4550}
4551
Douglas Gregor577f75a2009-08-04 16:50:30 +00004552template<typename Derived>
4553QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004554 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004555 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004556 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004557}
4558
Mike Stump1eb44332009-09-09 15:08:12 +00004559template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004560QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004561 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004562 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004563 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004564
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004565 // Substitute into the replacement type, which itself might involve something
4566 // that needs to be transformed. This only tends to occur with default
4567 // template arguments of template template parameters.
4568 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4569 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4570 if (Replacement.isNull())
4571 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004572
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004573 // Always canonicalize the replacement type.
4574 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4575 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004576 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004577 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004578
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004579 // Propagate type-source information.
4580 SubstTemplateTypeParmTypeLoc NewTL
4581 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4582 NewTL.setNameLoc(TL.getNameLoc());
4583 return Result;
4584
John McCall49a832b2009-10-18 09:09:24 +00004585}
4586
4587template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004588QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4589 TypeLocBuilder &TLB,
4590 SubstTemplateTypeParmPackTypeLoc TL) {
4591 return TransformTypeSpecType(TLB, TL);
4592}
4593
4594template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004595QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004596 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004597 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004598 const TemplateSpecializationType *T = TL.getTypePtr();
4599
Douglas Gregor1d752d72011-03-02 18:46:51 +00004600 // The nested-name-specifier never matters in a TemplateSpecializationType,
4601 // because we can't have a dependent nested-name-specifier anyway.
4602 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004603 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004604 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4605 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004606 if (Template.isNull())
4607 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004608
John McCall43fed0d2010-11-12 08:19:04 +00004609 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4610}
4611
Eli Friedmanb001de72011-10-06 23:00:33 +00004612template<typename Derived>
4613QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4614 AtomicTypeLoc TL) {
4615 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4616 if (ValueType.isNull())
4617 return QualType();
4618
4619 QualType Result = TL.getType();
4620 if (getDerived().AlwaysRebuild() ||
4621 ValueType != TL.getValueLoc().getType()) {
4622 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4623 if (Result.isNull())
4624 return QualType();
4625 }
4626
4627 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4628 NewTL.setKWLoc(TL.getKWLoc());
4629 NewTL.setLParenLoc(TL.getLParenLoc());
4630 NewTL.setRParenLoc(TL.getRParenLoc());
4631
4632 return Result;
4633}
4634
Chad Rosier4a9d7952012-08-08 18:46:20 +00004635 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004636 /// container that provides a \c getArgLoc() member function.
4637 ///
4638 /// This iterator is intended to be used with the iterator form of
4639 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4640 template<typename ArgLocContainer>
4641 class TemplateArgumentLocContainerIterator {
4642 ArgLocContainer *Container;
4643 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004644
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004645 public:
4646 typedef TemplateArgumentLoc value_type;
4647 typedef TemplateArgumentLoc reference;
4648 typedef int difference_type;
4649 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004650
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004651 class pointer {
4652 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004653
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004654 public:
4655 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004656
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004657 const TemplateArgumentLoc *operator->() const {
4658 return &Arg;
4659 }
4660 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004661
4662
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004663 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004664
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004665 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4666 unsigned Index)
4667 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004668
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004669 TemplateArgumentLocContainerIterator &operator++() {
4670 ++Index;
4671 return *this;
4672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004673
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004674 TemplateArgumentLocContainerIterator operator++(int) {
4675 TemplateArgumentLocContainerIterator Old(*this);
4676 ++(*this);
4677 return Old;
4678 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004679
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004680 TemplateArgumentLoc operator*() const {
4681 return Container->getArgLoc(Index);
4682 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004683
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004684 pointer operator->() const {
4685 return pointer(Container->getArgLoc(Index));
4686 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004687
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004688 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004689 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 return X.Container == Y.Container && X.Index == Y.Index;
4691 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004693 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004694 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004695 return !(X == Y);
4696 }
4697 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004698
4699
John McCall43fed0d2010-11-12 08:19:04 +00004700template <typename Derived>
4701QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4702 TypeLocBuilder &TLB,
4703 TemplateSpecializationTypeLoc TL,
4704 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004705 TemplateArgumentListInfo NewTemplateArgs;
4706 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4707 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004708 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4709 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004710 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004711 ArgIterator(TL, TL.getNumArgs()),
4712 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004713 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004714
John McCall833ca992009-10-29 08:12:44 +00004715 // FIXME: maybe don't rebuild if all the template arguments are the same.
4716
4717 QualType Result =
4718 getDerived().RebuildTemplateSpecializationType(Template,
4719 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004720 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004721
4722 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004723 // Specializations of template template parameters are represented as
4724 // TemplateSpecializationTypes, and substitution of type alias templates
4725 // within a dependent context can transform them into
4726 // DependentTemplateSpecializationTypes.
4727 if (isa<DependentTemplateSpecializationType>(Result)) {
4728 DependentTemplateSpecializationTypeLoc NewTL
4729 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004730 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004731 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004732 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004733 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004734 NewTL.setLAngleLoc(TL.getLAngleLoc());
4735 NewTL.setRAngleLoc(TL.getRAngleLoc());
4736 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4737 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4738 return Result;
4739 }
4740
John McCall833ca992009-10-29 08:12:44 +00004741 TemplateSpecializationTypeLoc NewTL
4742 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004743 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004744 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4745 NewTL.setLAngleLoc(TL.getLAngleLoc());
4746 NewTL.setRAngleLoc(TL.getRAngleLoc());
4747 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4748 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004749 }
Mike Stump1eb44332009-09-09 15:08:12 +00004750
John McCall833ca992009-10-29 08:12:44 +00004751 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004752}
Mike Stump1eb44332009-09-09 15:08:12 +00004753
Douglas Gregora88f09f2011-02-28 17:23:35 +00004754template <typename Derived>
4755QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4756 TypeLocBuilder &TLB,
4757 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004758 TemplateName Template,
4759 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004760 TemplateArgumentListInfo NewTemplateArgs;
4761 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4762 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4763 typedef TemplateArgumentLocContainerIterator<
4764 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004765 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004766 ArgIterator(TL, TL.getNumArgs()),
4767 NewTemplateArgs))
4768 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004769
Douglas Gregora88f09f2011-02-28 17:23:35 +00004770 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004771
Douglas Gregora88f09f2011-02-28 17:23:35 +00004772 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4773 QualType Result
4774 = getSema().Context.getDependentTemplateSpecializationType(
4775 TL.getTypePtr()->getKeyword(),
4776 DTN->getQualifier(),
4777 DTN->getIdentifier(),
4778 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004779
Douglas Gregora88f09f2011-02-28 17:23:35 +00004780 DependentTemplateSpecializationTypeLoc NewTL
4781 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004782 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004783 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004784 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004785 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004786 NewTL.setLAngleLoc(TL.getLAngleLoc());
4787 NewTL.setRAngleLoc(TL.getRAngleLoc());
4788 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4789 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4790 return Result;
4791 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004792
4793 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004794 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004795 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004796 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004797
Douglas Gregora88f09f2011-02-28 17:23:35 +00004798 if (!Result.isNull()) {
4799 /// FIXME: Wrap this in an elaborated-type-specifier?
4800 TemplateSpecializationTypeLoc NewTL
4801 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004802 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004803 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004804 NewTL.setLAngleLoc(TL.getLAngleLoc());
4805 NewTL.setRAngleLoc(TL.getRAngleLoc());
4806 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4807 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4808 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004809
Douglas Gregora88f09f2011-02-28 17:23:35 +00004810 return Result;
4811}
4812
Mike Stump1eb44332009-09-09 15:08:12 +00004813template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004814QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004815TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004816 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004817 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004818
Douglas Gregor9e876872011-03-01 18:12:44 +00004819 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004820 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004821 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004822 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004823 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4824 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004825 return QualType();
4826 }
Mike Stump1eb44332009-09-09 15:08:12 +00004827
John McCall43fed0d2010-11-12 08:19:04 +00004828 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4829 if (NamedT.isNull())
4830 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004831
Richard Smith3e4c6c42011-05-05 21:57:07 +00004832 // C++0x [dcl.type.elab]p2:
4833 // If the identifier resolves to a typedef-name or the simple-template-id
4834 // resolves to an alias template specialization, the
4835 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004836 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4837 if (const TemplateSpecializationType *TST =
4838 NamedT->getAs<TemplateSpecializationType>()) {
4839 TemplateName Template = TST->getTemplateName();
4840 if (TypeAliasTemplateDecl *TAT =
4841 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4842 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4843 diag::err_tag_reference_non_tag) << 4;
4844 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4845 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004846 }
4847 }
4848
John McCalla2becad2009-10-21 00:40:46 +00004849 QualType Result = TL.getType();
4850 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004851 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004852 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004853 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004854 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004855 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004856 if (Result.isNull())
4857 return QualType();
4858 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004859
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004860 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004861 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004862 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004863 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004864}
Mike Stump1eb44332009-09-09 15:08:12 +00004865
4866template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004867QualType TreeTransform<Derived>::TransformAttributedType(
4868 TypeLocBuilder &TLB,
4869 AttributedTypeLoc TL) {
4870 const AttributedType *oldType = TL.getTypePtr();
4871 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4872 if (modifiedType.isNull())
4873 return QualType();
4874
4875 QualType result = TL.getType();
4876
4877 // FIXME: dependent operand expressions?
4878 if (getDerived().AlwaysRebuild() ||
4879 modifiedType != oldType->getModifiedType()) {
4880 // TODO: this is really lame; we should really be rebuilding the
4881 // equivalent type from first principles.
4882 QualType equivalentType
4883 = getDerived().TransformType(oldType->getEquivalentType());
4884 if (equivalentType.isNull())
4885 return QualType();
4886 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4887 modifiedType,
4888 equivalentType);
4889 }
4890
4891 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4892 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4893 if (TL.hasAttrOperand())
4894 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4895 if (TL.hasAttrExprOperand())
4896 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4897 else if (TL.hasAttrEnumOperand())
4898 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4899
4900 return result;
4901}
4902
4903template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004904QualType
4905TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4906 ParenTypeLoc TL) {
4907 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4908 if (Inner.isNull())
4909 return QualType();
4910
4911 QualType Result = TL.getType();
4912 if (getDerived().AlwaysRebuild() ||
4913 Inner != TL.getInnerLoc().getType()) {
4914 Result = getDerived().RebuildParenType(Inner);
4915 if (Result.isNull())
4916 return QualType();
4917 }
4918
4919 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4920 NewTL.setLParenLoc(TL.getLParenLoc());
4921 NewTL.setRParenLoc(TL.getRParenLoc());
4922 return Result;
4923}
4924
4925template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004926QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004927 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004928 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004929
Douglas Gregor2494dd02011-03-01 01:34:45 +00004930 NestedNameSpecifierLoc QualifierLoc
4931 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4932 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004933 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004934
John McCall33500952010-06-11 00:33:02 +00004935 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004936 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004937 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004938 QualifierLoc,
4939 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004940 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004941 if (Result.isNull())
4942 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004943
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004944 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4945 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004946 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4947
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004948 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004949 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004950 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004951 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004952 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004953 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004954 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004955 NewTL.setNameLoc(TL.getNameLoc());
4956 }
John McCalla2becad2009-10-21 00:40:46 +00004957 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004958}
Mike Stump1eb44332009-09-09 15:08:12 +00004959
Douglas Gregor577f75a2009-08-04 16:50:30 +00004960template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004961QualType TreeTransform<Derived>::
4962 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004963 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004964 NestedNameSpecifierLoc QualifierLoc;
4965 if (TL.getQualifierLoc()) {
4966 QualifierLoc
4967 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4968 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004969 return QualType();
4970 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004971
John McCall43fed0d2010-11-12 08:19:04 +00004972 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004973 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004974}
4975
4976template<typename Derived>
4977QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004978TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4979 DependentTemplateSpecializationTypeLoc TL,
4980 NestedNameSpecifierLoc QualifierLoc) {
4981 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004982
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004983 TemplateArgumentListInfo NewTemplateArgs;
4984 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4985 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004987 typedef TemplateArgumentLocContainerIterator<
4988 DependentTemplateSpecializationTypeLoc> ArgIterator;
4989 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4990 ArgIterator(TL, TL.getNumArgs()),
4991 NewTemplateArgs))
4992 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004993
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004994 QualType Result
4995 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4996 QualifierLoc,
4997 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004998 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004999 NewTemplateArgs);
5000 if (Result.isNull())
5001 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005002
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5004 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005005
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005006 // Copy information relevant to the template specialization.
5007 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005008 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005009 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005010 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005011 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5012 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005013 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005015
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005016 // Copy information relevant to the elaborated type.
5017 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005018 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005019 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005020 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5021 DependentTemplateSpecializationTypeLoc SpecTL
5022 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005023 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005024 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005025 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005026 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005027 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5028 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005029 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005030 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005031 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005032 TemplateSpecializationTypeLoc SpecTL
5033 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005034 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005035 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005036 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5037 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005038 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005039 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005040 }
5041 return Result;
5042}
5043
5044template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005045QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5046 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005047 QualType Pattern
5048 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005049 if (Pattern.isNull())
5050 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005051
5052 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005053 if (getDerived().AlwaysRebuild() ||
5054 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005055 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005056 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005057 TL.getEllipsisLoc(),
5058 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005059 if (Result.isNull())
5060 return QualType();
5061 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005062
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005063 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5064 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5065 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005066}
5067
5068template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005069QualType
5070TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005071 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005072 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005073 TLB.pushFullCopy(TL);
5074 return TL.getType();
5075}
5076
5077template<typename Derived>
5078QualType
5079TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005080 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005081 // ObjCObjectType is never dependent.
5082 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005083 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005084}
Mike Stump1eb44332009-09-09 15:08:12 +00005085
5086template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005087QualType
5088TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005089 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005090 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005091 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005092 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005093}
5094
Douglas Gregor577f75a2009-08-04 16:50:30 +00005095//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005096// Statement transformation
5097//===----------------------------------------------------------------------===//
5098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005099StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005100TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005101 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005102}
5103
5104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005105StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005106TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5107 return getDerived().TransformCompoundStmt(S, false);
5108}
5109
5110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005111StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005112TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005113 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005114 Sema::CompoundScopeRAII CompoundScope(getSema());
5115
John McCall7114cba2010-08-27 19:56:05 +00005116 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005118 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5120 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005121 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005122 if (Result.isInvalid()) {
5123 // Immediately fail if this was a DeclStmt, since it's very
5124 // likely that this will cause problems for future statements.
5125 if (isa<DeclStmt>(*B))
5126 return StmtError();
5127
5128 // Otherwise, just keep processing substatements and fail later.
5129 SubStmtInvalid = true;
5130 continue;
5131 }
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5134 Statements.push_back(Result.takeAs<Stmt>());
5135 }
Mike Stump1eb44332009-09-09 15:08:12 +00005136
John McCall7114cba2010-08-27 19:56:05 +00005137 if (SubStmtInvalid)
5138 return StmtError();
5139
Douglas Gregor43959a92009-08-20 07:17:43 +00005140 if (!getDerived().AlwaysRebuild() &&
5141 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005142 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005143
5144 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005145 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005146 S->getRBracLoc(),
5147 IsStmtExpr);
5148}
Mike Stump1eb44332009-09-09 15:08:12 +00005149
Douglas Gregor43959a92009-08-20 07:17:43 +00005150template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005151StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005152TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005153 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005154 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005155 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5156 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005157
Eli Friedman264c1f82009-11-19 03:14:00 +00005158 // Transform the left-hand case value.
5159 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005160 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005161 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Eli Friedman264c1f82009-11-19 03:14:00 +00005164 // Transform the right-hand case value (for the GNU case-range extension).
5165 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005166 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005167 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005168 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005169 }
Mike Stump1eb44332009-09-09 15:08:12 +00005170
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 // Build the case statement.
5172 // Case statements are always rebuilt so that they will attached to their
5173 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005174 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005175 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005177 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 S->getColonLoc());
5179 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005180 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005181
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005183 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005185 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor43959a92009-08-20 07:17:43 +00005187 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005188 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005189}
5190
5191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005192StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005193TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005194 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005195 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005196 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005197 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // Default statements are always rebuilt
5200 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005201 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005202}
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregor43959a92009-08-20 07:17:43 +00005204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005205StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005206TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005207 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005209 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Chris Lattner57ad3782011-02-17 20:34:02 +00005211 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5212 S->getDecl());
5213 if (!LD)
5214 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005215
5216
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005218 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005219 cast<LabelDecl>(LD), SourceLocation(),
5220 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005221}
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregor43959a92009-08-20 07:17:43 +00005223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005224StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005225TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5226 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5227 if (SubStmt.isInvalid())
5228 return StmtError();
5229
5230 // TODO: transform attributes
5231 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5232 return S;
5233
5234 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5235 S->getAttrs(),
5236 SubStmt.get());
5237}
5238
5239template<typename Derived>
5240StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005241TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005243 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005244 VarDecl *ConditionVar = 0;
5245 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005246 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005247 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005248 getDerived().TransformDefinition(
5249 S->getConditionVariable()->getLocation(),
5250 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005251 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005253 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005254 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005255
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005256 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005258
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005259 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005260 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005261 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005262 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005263 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005265
John McCall9ae2f072010-08-23 23:25:46 +00005266 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005267 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005268 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005269
John McCall9ae2f072010-08-23 23:25:46 +00005270 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5271 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005272 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005273
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005275 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005277 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005278
Douglas Gregor43959a92009-08-20 07:17:43 +00005279 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005280 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005282 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005283
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005285 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005286 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005287 Then.get() == S->getThen() &&
5288 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005289 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005290
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005291 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005292 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005293 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005294}
5295
5296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005297StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005298TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005300 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005301 VarDecl *ConditionVar = 0;
5302 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005303 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005304 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005305 getDerived().TransformDefinition(
5306 S->getConditionVariable()->getLocation(),
5307 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005308 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005310 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005311 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005312
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005313 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005314 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005315 }
Mike Stump1eb44332009-09-09 15:08:12 +00005316
Douglas Gregor43959a92009-08-20 07:17:43 +00005317 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005318 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005319 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005320 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005322 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005323
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005325 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005327 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005328
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005330 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5331 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005332}
Mike Stump1eb44332009-09-09 15:08:12 +00005333
Douglas Gregor43959a92009-08-20 07:17:43 +00005334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005335StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005336TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005338 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005339 VarDecl *ConditionVar = 0;
5340 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005341 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005342 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005343 getDerived().TransformDefinition(
5344 S->getConditionVariable()->getLocation(),
5345 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005346 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005347 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005348 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005349 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005350
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005351 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005352 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005353
5354 if (S->getCond()) {
5355 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005356 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005357 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005358 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005360 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005361 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005362 }
Mike Stump1eb44332009-09-09 15:08:12 +00005363
John McCall9ae2f072010-08-23 23:25:46 +00005364 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5365 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005366 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005367
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005369 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005374 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005375 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005376 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005377 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005378
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005379 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005380 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005381}
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregor43959a92009-08-20 07:17:43 +00005383template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005384StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005385TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005386 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005387 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005391 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005392 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005393 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005394 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 if (!getDerived().AlwaysRebuild() &&
5397 Cond.get() == S->getCond() &&
5398 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005399 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005400
John McCall9ae2f072010-08-23 23:25:46 +00005401 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5402 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005403 S->getRParenLoc());
5404}
Mike Stump1eb44332009-09-09 15:08:12 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005407StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005408TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005409 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005410 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005411 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005415 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005416 VarDecl *ConditionVar = 0;
5417 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005418 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005419 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005420 getDerived().TransformDefinition(
5421 S->getConditionVariable()->getLocation(),
5422 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005423 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005424 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005425 } else {
5426 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005427
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005428 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005429 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005430
5431 if (S->getCond()) {
5432 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005433 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005434 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005435 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005437
John McCall9ae2f072010-08-23 23:25:46 +00005438 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005439 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005440 }
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Chad Rosier4a9d7952012-08-08 18:46:20 +00005442 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005443 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005445
Douglas Gregor43959a92009-08-20 07:17:43 +00005446 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005447 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005448 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005449 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005450
Richard Smith41956372013-01-14 22:39:08 +00005451 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005452 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005453 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005454
Douglas Gregor43959a92009-08-20 07:17:43 +00005455 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005456 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005457 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005458 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005459
Douglas Gregor43959a92009-08-20 07:17:43 +00005460 if (!getDerived().AlwaysRebuild() &&
5461 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005462 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005463 Inc.get() == S->getInc() &&
5464 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005465 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005468 Init.get(), FullCond, ConditionVar,
5469 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005470}
5471
5472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005473StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005474TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005475 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5476 S->getLabel());
5477 if (!LD)
5478 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005479
Douglas Gregor43959a92009-08-20 07:17:43 +00005480 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005481 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005482 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005483}
5484
5485template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005486StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005487TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005488 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005489 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005490 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005491 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005492
Douglas Gregor43959a92009-08-20 07:17:43 +00005493 if (!getDerived().AlwaysRebuild() &&
5494 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005495 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005496
5497 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005498 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005499}
5500
5501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005502StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005503TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005504 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005505}
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005509TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005510 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005511}
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregor43959a92009-08-20 07:17:43 +00005513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005514StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005515TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005516 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005517 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005519
Mike Stump1eb44332009-09-09 15:08:12 +00005520 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005522 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005523}
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005526StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005527TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005528 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005529 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005530 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5531 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005532 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5533 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005535 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregor43959a92009-08-20 07:17:43 +00005537 if (Transformed != *D)
5538 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005539
Douglas Gregor43959a92009-08-20 07:17:43 +00005540 Decls.push_back(Transformed);
5541 }
Mike Stump1eb44332009-09-09 15:08:12 +00005542
Douglas Gregor43959a92009-08-20 07:17:43 +00005543 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005544 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005545
5546 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005547 S->getStartLoc(), S->getEndLoc());
5548}
Mike Stump1eb44332009-09-09 15:08:12 +00005549
Douglas Gregor43959a92009-08-20 07:17:43 +00005550template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005551StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005552TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005553
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005554 SmallVector<Expr*, 8> Constraints;
5555 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005556 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005557
John McCall60d7b3a2010-08-24 06:29:42 +00005558 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005559 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005560
5561 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 // Go through the outputs.
5564 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005565 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005568 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005569
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 // Transform the output expr.
5571 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
John McCall9ae2f072010-08-23 23:25:46 +00005578 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005579 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005580
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 // Go through the inputs.
5582 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005583 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Anders Carlsson703e3942010-01-24 05:50:09 +00005585 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005586 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005587
Anders Carlsson703e3942010-01-24 05:50:09 +00005588 // Transform the input expr.
5589 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005590 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005591 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005592 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005593
Anders Carlsson703e3942010-01-24 05:50:09 +00005594 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005595
John McCall9ae2f072010-08-23 23:25:46 +00005596 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005597 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005598
Anders Carlsson703e3942010-01-24 05:50:09 +00005599 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005600 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005601
5602 // Go through the clobbers.
5603 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005604 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005605
5606 // No need to transform the asm string literal.
5607 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005608 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5609 S->isVolatile(), S->getNumOutputs(),
5610 S->getNumInputs(), Names.data(),
5611 Constraints, Exprs, AsmString.get(),
5612 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005613}
5614
Chad Rosier8cd64b42012-06-11 20:47:18 +00005615template<typename Derived>
5616StmtResult
5617TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005618 ArrayRef<Token> AsmToks =
5619 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005620
Chad Rosier7bd092b2012-08-15 16:53:30 +00005621 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5622 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005623}
Douglas Gregor43959a92009-08-20 07:17:43 +00005624
5625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005626StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005627TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005628 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005629 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005630 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005631 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005632
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005633 // Transform the @catch statements (if present).
5634 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005635 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005636 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005637 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005638 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005640 if (Catch.get() != S->getCatchStmt(I))
5641 AnyCatchChanged = true;
5642 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005643 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005644
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005645 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005646 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005647 if (S->getFinallyStmt()) {
5648 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5649 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005651 }
5652
5653 // If nothing changed, just retain this statement.
5654 if (!getDerived().AlwaysRebuild() &&
5655 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005656 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005657 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005658 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005659
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005660 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005661 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005662 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005663}
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregor43959a92009-08-20 07:17:43 +00005665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005666StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005667TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005668 // Transform the @catch parameter, if there is one.
5669 VarDecl *Var = 0;
5670 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5671 TypeSourceInfo *TSInfo = 0;
5672 if (FromVar->getTypeSourceInfo()) {
5673 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5674 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005675 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005677
Douglas Gregorbe270a02010-04-26 17:57:08 +00005678 QualType T;
5679 if (TSInfo)
5680 T = TSInfo->getType();
5681 else {
5682 T = getDerived().TransformType(FromVar->getType());
5683 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005684 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005685 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005686
Douglas Gregorbe270a02010-04-26 17:57:08 +00005687 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5688 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005689 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005690 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005691
John McCall60d7b3a2010-08-24 06:29:42 +00005692 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005693 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005694 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005695
5696 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005697 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005698 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005699}
Mike Stump1eb44332009-09-09 15:08:12 +00005700
Douglas Gregor43959a92009-08-20 07:17:43 +00005701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005702StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005703TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005704 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005705 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005706 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005707 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005708
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005709 // If nothing changed, just retain this statement.
5710 if (!getDerived().AlwaysRebuild() &&
5711 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005712 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005713
5714 // Build a new statement.
5715 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005716 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005717}
Mike Stump1eb44332009-09-09 15:08:12 +00005718
Douglas Gregor43959a92009-08-20 07:17:43 +00005719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005720StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005721TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005722 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005723 if (S->getThrowExpr()) {
5724 Operand = getDerived().TransformExpr(S->getThrowExpr());
5725 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005726 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005727 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005728
Douglas Gregord1377b22010-04-22 21:44:01 +00005729 if (!getDerived().AlwaysRebuild() &&
5730 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005731 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005732
John McCall9ae2f072010-08-23 23:25:46 +00005733 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005734}
Mike Stump1eb44332009-09-09 15:08:12 +00005735
Douglas Gregor43959a92009-08-20 07:17:43 +00005736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005737StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005738TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005739 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005740 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005741 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005742 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005743 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005744 Object =
5745 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5746 Object.get());
5747 if (Object.isInvalid())
5748 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005749
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005750 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005751 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005752 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005753 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005754
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005755 // If nothing change, just retain the current statement.
5756 if (!getDerived().AlwaysRebuild() &&
5757 Object.get() == S->getSynchExpr() &&
5758 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005759 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005760
5761 // Build a new statement.
5762 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005763 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005764}
5765
5766template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005767StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005768TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5769 ObjCAutoreleasePoolStmt *S) {
5770 // Transform the body.
5771 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5772 if (Body.isInvalid())
5773 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005774
John McCallf85e1932011-06-15 23:02:42 +00005775 // If nothing changed, just retain this statement.
5776 if (!getDerived().AlwaysRebuild() &&
5777 Body.get() == S->getSubStmt())
5778 return SemaRef.Owned(S);
5779
5780 // Build a new statement.
5781 return getDerived().RebuildObjCAutoreleasePoolStmt(
5782 S->getAtLoc(), Body.get());
5783}
5784
5785template<typename Derived>
5786StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005787TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005788 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005789 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005790 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005791 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005792 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005793
Douglas Gregorc3203e72010-04-22 23:10:45 +00005794 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005795 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005796 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005797 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005798
Douglas Gregorc3203e72010-04-22 23:10:45 +00005799 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005800 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005801 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005802 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005803
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 // If nothing changed, just retain this statement.
5805 if (!getDerived().AlwaysRebuild() &&
5806 Element.get() == S->getElement() &&
5807 Collection.get() == S->getCollection() &&
5808 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005809 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005810
Douglas Gregorc3203e72010-04-22 23:10:45 +00005811 // Build a new statement.
5812 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005813 Element.get(),
5814 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005815 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005816 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005817}
5818
5819
5820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005821StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005822TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5823 // Transform the exception declaration, if any.
5824 VarDecl *Var = 0;
5825 if (S->getExceptionDecl()) {
5826 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005827 TypeSourceInfo *T = getDerived().TransformType(
5828 ExceptionDecl->getTypeSourceInfo());
5829 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005830 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005831
Douglas Gregor83cb9422010-09-09 17:09:21 +00005832 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005833 ExceptionDecl->getInnerLocStart(),
5834 ExceptionDecl->getLocation(),
5835 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005836 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005837 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005838 }
Mike Stump1eb44332009-09-09 15:08:12 +00005839
Douglas Gregor43959a92009-08-20 07:17:43 +00005840 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005841 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005842 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005843 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005844
Douglas Gregor43959a92009-08-20 07:17:43 +00005845 if (!getDerived().AlwaysRebuild() &&
5846 !Var &&
5847 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005848 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005849
5850 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5851 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005852 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005853}
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregor43959a92009-08-20 07:17:43 +00005855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005856StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005857TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5858 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005859 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005860 = getDerived().TransformCompoundStmt(S->getTryBlock());
5861 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005862 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 // Transform the handlers.
5865 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005866 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005867 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005868 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005869 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5870 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005871 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005872
Douglas Gregor43959a92009-08-20 07:17:43 +00005873 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5874 Handlers.push_back(Handler.takeAs<Stmt>());
5875 }
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregor43959a92009-08-20 07:17:43 +00005877 if (!getDerived().AlwaysRebuild() &&
5878 TryBlock.get() == S->getTryBlock() &&
5879 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005880 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005881
John McCall9ae2f072010-08-23 23:25:46 +00005882 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005883 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005884}
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Richard Smithad762fc2011-04-14 22:09:26 +00005886template<typename Derived>
5887StmtResult
5888TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5889 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5890 if (Range.isInvalid())
5891 return StmtError();
5892
5893 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5894 if (BeginEnd.isInvalid())
5895 return StmtError();
5896
5897 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5898 if (Cond.isInvalid())
5899 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005900 if (Cond.get())
5901 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5902 if (Cond.isInvalid())
5903 return StmtError();
5904 if (Cond.get())
5905 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005906
5907 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5908 if (Inc.isInvalid())
5909 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005910 if (Inc.get())
5911 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005912
5913 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5914 if (LoopVar.isInvalid())
5915 return StmtError();
5916
5917 StmtResult NewStmt = S;
5918 if (getDerived().AlwaysRebuild() ||
5919 Range.get() != S->getRangeStmt() ||
5920 BeginEnd.get() != S->getBeginEndStmt() ||
5921 Cond.get() != S->getCond() ||
5922 Inc.get() != S->getInc() ||
5923 LoopVar.get() != S->getLoopVarStmt())
5924 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5925 S->getColonLoc(), Range.get(),
5926 BeginEnd.get(), Cond.get(),
5927 Inc.get(), LoopVar.get(),
5928 S->getRParenLoc());
5929
5930 StmtResult Body = getDerived().TransformStmt(S->getBody());
5931 if (Body.isInvalid())
5932 return StmtError();
5933
5934 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5935 // it now so we have a new statement to attach the body to.
5936 if (Body.get() != S->getBody() && NewStmt.get() == S)
5937 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5938 S->getColonLoc(), Range.get(),
5939 BeginEnd.get(), Cond.get(),
5940 Inc.get(), LoopVar.get(),
5941 S->getRParenLoc());
5942
5943 if (NewStmt.get() == S)
5944 return SemaRef.Owned(S);
5945
5946 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5947}
5948
John Wiegley28bbe4b2011-04-28 01:08:34 +00005949template<typename Derived>
5950StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005951TreeTransform<Derived>::TransformMSDependentExistsStmt(
5952 MSDependentExistsStmt *S) {
5953 // Transform the nested-name-specifier, if any.
5954 NestedNameSpecifierLoc QualifierLoc;
5955 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005956 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005957 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5958 if (!QualifierLoc)
5959 return StmtError();
5960 }
5961
5962 // Transform the declaration name.
5963 DeclarationNameInfo NameInfo = S->getNameInfo();
5964 if (NameInfo.getName()) {
5965 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5966 if (!NameInfo.getName())
5967 return StmtError();
5968 }
5969
5970 // Check whether anything changed.
5971 if (!getDerived().AlwaysRebuild() &&
5972 QualifierLoc == S->getQualifierLoc() &&
5973 NameInfo.getName() == S->getNameInfo().getName())
5974 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005975
Douglas Gregorba0513d2011-10-25 01:33:02 +00005976 // Determine whether this name exists, if we can.
5977 CXXScopeSpec SS;
5978 SS.Adopt(QualifierLoc);
5979 bool Dependent = false;
5980 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5981 case Sema::IER_Exists:
5982 if (S->isIfExists())
5983 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005984
Douglas Gregorba0513d2011-10-25 01:33:02 +00005985 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5986
5987 case Sema::IER_DoesNotExist:
5988 if (S->isIfNotExists())
5989 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005990
Douglas Gregorba0513d2011-10-25 01:33:02 +00005991 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005992
Douglas Gregorba0513d2011-10-25 01:33:02 +00005993 case Sema::IER_Dependent:
5994 Dependent = true;
5995 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005996
Douglas Gregor65019ac2011-10-25 03:44:56 +00005997 case Sema::IER_Error:
5998 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005999 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006000
Douglas Gregorba0513d2011-10-25 01:33:02 +00006001 // We need to continue with the instantiation, so do so now.
6002 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6003 if (SubStmt.isInvalid())
6004 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006005
Douglas Gregorba0513d2011-10-25 01:33:02 +00006006 // If we have resolved the name, just transform to the substatement.
6007 if (!Dependent)
6008 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006009
Douglas Gregorba0513d2011-10-25 01:33:02 +00006010 // The name is still dependent, so build a dependent expression again.
6011 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6012 S->isIfExists(),
6013 QualifierLoc,
6014 NameInfo,
6015 SubStmt.get());
6016}
6017
6018template<typename Derived>
6019StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006020TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6021 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6022 if(TryBlock.isInvalid()) return StmtError();
6023
6024 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6025 if(!getDerived().AlwaysRebuild() &&
6026 TryBlock.get() == S->getTryBlock() &&
6027 Handler.get() == S->getHandler())
6028 return SemaRef.Owned(S);
6029
6030 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6031 S->getTryLoc(),
6032 TryBlock.take(),
6033 Handler.take());
6034}
6035
6036template<typename Derived>
6037StmtResult
6038TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6039 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6040 if(Block.isInvalid()) return StmtError();
6041
6042 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6043 Block.take());
6044}
6045
6046template<typename Derived>
6047StmtResult
6048TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6049 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6050 if(FilterExpr.isInvalid()) return StmtError();
6051
6052 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6053 if(Block.isInvalid()) return StmtError();
6054
6055 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6056 FilterExpr.take(),
6057 Block.take());
6058}
6059
6060template<typename Derived>
6061StmtResult
6062TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6063 if(isa<SEHFinallyStmt>(Handler))
6064 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6065 else
6066 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6067}
6068
Douglas Gregor43959a92009-08-20 07:17:43 +00006069//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070// Expression transformation
6071//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006073ExprResult
John McCall454feb92009-12-08 09:21:05 +00006074TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006075 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076}
Mike Stump1eb44332009-09-09 15:08:12 +00006077
6078template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006079ExprResult
John McCall454feb92009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006081 NestedNameSpecifierLoc QualifierLoc;
6082 if (E->getQualifierLoc()) {
6083 QualifierLoc
6084 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6085 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006086 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006087 }
John McCalldbd872f2009-12-08 09:08:17 +00006088
6089 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006090 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6091 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006092 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006093 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006094
John McCallec8045d2010-08-17 21:27:17 +00006095 DeclarationNameInfo NameInfo = E->getNameInfo();
6096 if (NameInfo.getName()) {
6097 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6098 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006099 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006100 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006101
6102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006103 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006104 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006105 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006106 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006107
6108 // Mark it referenced in the new context regardless.
6109 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006110 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006111
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006113 }
John McCalldbd872f2009-12-08 09:08:17 +00006114
6115 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006116 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006117 TemplateArgs = &TransArgs;
6118 TransArgs.setLAngleLoc(E->getLAngleLoc());
6119 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006120 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6121 E->getNumTemplateArgs(),
6122 TransArgs))
6123 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006124 }
6125
Chad Rosier4a9d7952012-08-08 18:46:20 +00006126 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006127 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128}
Mike Stump1eb44332009-09-09 15:08:12 +00006129
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006131ExprResult
John McCall454feb92009-12-08 09:21:05 +00006132TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134}
Mike Stump1eb44332009-09-09 15:08:12 +00006135
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006137ExprResult
John McCall454feb92009-12-08 09:21:05 +00006138TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140}
Mike Stump1eb44332009-09-09 15:08:12 +00006141
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006143ExprResult
John McCall454feb92009-12-08 09:21:05 +00006144TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006145 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146}
Mike Stump1eb44332009-09-09 15:08:12 +00006147
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006149ExprResult
John McCall454feb92009-12-08 09:21:05 +00006150TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006151 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152}
Mike Stump1eb44332009-09-09 15:08:12 +00006153
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006155ExprResult
John McCall454feb92009-12-08 09:21:05 +00006156TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006157 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006158}
6159
6160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006161ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006162TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6163 return SemaRef.MaybeBindToTemporary(E);
6164}
6165
6166template<typename Derived>
6167ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006168TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6169 ExprResult ControllingExpr =
6170 getDerived().TransformExpr(E->getControllingExpr());
6171 if (ControllingExpr.isInvalid())
6172 return ExprError();
6173
Chris Lattner686775d2011-07-20 06:58:45 +00006174 SmallVector<Expr *, 4> AssocExprs;
6175 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006176 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6177 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6178 if (TS) {
6179 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6180 if (!AssocType)
6181 return ExprError();
6182 AssocTypes.push_back(AssocType);
6183 } else {
6184 AssocTypes.push_back(0);
6185 }
6186
6187 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6188 if (AssocExpr.isInvalid())
6189 return ExprError();
6190 AssocExprs.push_back(AssocExpr.release());
6191 }
6192
6193 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6194 E->getDefaultLoc(),
6195 E->getRParenLoc(),
6196 ControllingExpr.release(),
6197 AssocTypes.data(),
6198 AssocExprs.data(),
6199 E->getNumAssocs());
6200}
6201
6202template<typename Derived>
6203ExprResult
John McCall454feb92009-12-08 09:21:05 +00006204TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006205 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006207 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006208
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006211
John McCall9ae2f072010-08-23 23:25:46 +00006212 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 E->getRParen());
6214}
6215
Richard Smithefeeccf2012-10-21 03:28:35 +00006216/// \brief The operand of a unary address-of operator has special rules: it's
6217/// allowed to refer to a non-static member of a class even if there's no 'this'
6218/// object available.
6219template<typename Derived>
6220ExprResult
6221TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6222 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6223 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6224 else
6225 return getDerived().TransformExpr(E);
6226}
6227
Mike Stump1eb44332009-09-09 15:08:12 +00006228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006229ExprResult
John McCall454feb92009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006231 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006236 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006237
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6239 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006240 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006241}
Mike Stump1eb44332009-09-09 15:08:12 +00006242
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006244ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006245TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6246 // Transform the type.
6247 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6248 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006249 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006250
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006251 // Transform all of the components into components similar to what the
6252 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006253 // FIXME: It would be slightly more efficient in the non-dependent case to
6254 // just map FieldDecls, rather than requiring the rebuilder to look for
6255 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006256 // template code that we don't care.
6257 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006258 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006259 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006260 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006261 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6262 const Node &ON = E->getComponent(I);
6263 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006264 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006265 Comp.LocStart = ON.getSourceRange().getBegin();
6266 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006267 switch (ON.getKind()) {
6268 case Node::Array: {
6269 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006270 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006272 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006273
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 ExprChanged = ExprChanged || Index.get() != FromIndex;
6275 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006276 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006277 break;
6278 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006279
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006280 case Node::Field:
6281 case Node::Identifier:
6282 Comp.isBrackets = false;
6283 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006284 if (!Comp.U.IdentInfo)
6285 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006286
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006287 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006288
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006289 case Node::Base:
6290 // Will be recomputed during the rebuild.
6291 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006292 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006293
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006294 Components.push_back(Comp);
6295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006296
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006297 // If nothing changed, retain the existing expression.
6298 if (!getDerived().AlwaysRebuild() &&
6299 Type == E->getTypeSourceInfo() &&
6300 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006302
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006303 // Build a new offsetof expression.
6304 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6305 Components.data(), Components.size(),
6306 E->getRParenLoc());
6307}
6308
6309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006310ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006311TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6312 assert(getDerived().AlreadyTransformed(E->getType()) &&
6313 "opaque value expression requires transformation");
6314 return SemaRef.Owned(E);
6315}
6316
6317template<typename Derived>
6318ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006319TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006320 // Rebuild the syntactic form. The original syntactic form has
6321 // opaque-value expressions in it, so strip those away and rebuild
6322 // the result. This is a really awful way of doing this, but the
6323 // better solution (rebuilding the semantic expressions and
6324 // rebinding OVEs as necessary) doesn't work; we'd need
6325 // TreeTransform to not strip away implicit conversions.
6326 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6327 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006328 if (result.isInvalid()) return ExprError();
6329
6330 // If that gives us a pseudo-object result back, the pseudo-object
6331 // expression must have been an lvalue-to-rvalue conversion which we
6332 // should reapply.
6333 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6334 result = SemaRef.checkPseudoObjectRValue(result.take());
6335
6336 return result;
6337}
6338
6339template<typename Derived>
6340ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006341TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6342 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006344 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006345
John McCalla93c9342009-12-07 02:54:59 +00006346 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006347 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006348 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006349
John McCall5ab75172009-11-04 07:28:41 +00006350 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006351 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006352
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006353 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6354 E->getKind(),
6355 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 }
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006358 // C++0x [expr.sizeof]p1:
6359 // The operand is either an expression, which is an unevaluated operand
6360 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006361 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6362 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006363
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006364 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6365 if (SubExpr.isInvalid())
6366 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006368 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006370
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006371 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6372 E->getOperatorLoc(),
6373 E->getKind(),
6374 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375}
Mike Stump1eb44332009-09-09 15:08:12 +00006376
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006378ExprResult
John McCall454feb92009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006380 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006382 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006383
John McCall60d7b3a2010-08-24 06:29:42 +00006384 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006387
6388
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 if (!getDerived().AlwaysRebuild() &&
6390 LHS.get() == E->getLHS() &&
6391 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006392 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006393
John McCall9ae2f072010-08-23 23:25:46 +00006394 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006396 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 E->getRBracketLoc());
6398}
Mike Stump1eb44332009-09-09 15:08:12 +00006399
6400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006401ExprResult
John McCall454feb92009-12-08 09:21:05 +00006402TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006403 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006404 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407
6408 // Transform arguments.
6409 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006410 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006411 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006412 &ArgChanged))
6413 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006414
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415 if (!getDerived().AlwaysRebuild() &&
6416 Callee.get() == E->getCallee() &&
6417 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006418 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006421 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006423 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006424 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 E->getRParenLoc());
6426}
Mike Stump1eb44332009-09-09 15:08:12 +00006427
6428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006429ExprResult
John McCall454feb92009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006431 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006434
Douglas Gregor40d96a62011-02-28 21:54:11 +00006435 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006436 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006437 QualifierLoc
6438 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006439
Douglas Gregor40d96a62011-02-28 21:54:11 +00006440 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006441 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006442 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006443 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Eli Friedmanf595cc42009-12-04 06:40:45 +00006445 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006446 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6447 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006450
John McCall6bb80172010-03-30 21:47:33 +00006451 NamedDecl *FoundDecl = E->getFoundDecl();
6452 if (FoundDecl == E->getMemberDecl()) {
6453 FoundDecl = Member;
6454 } else {
6455 FoundDecl = cast_or_null<NamedDecl>(
6456 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6457 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006458 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006459 }
6460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (!getDerived().AlwaysRebuild() &&
6462 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006463 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006464 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006465 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006466 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006467
Anders Carlsson1f240322009-12-22 05:24:09 +00006468 // Mark it referenced in the new context regardless.
6469 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006470 SemaRef.MarkMemberReferenced(E);
6471
John McCall3fa5cae2010-10-26 07:05:15 +00006472 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006473 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474
John McCalld5532b62009-11-23 01:53:49 +00006475 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006476 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006477 TransArgs.setLAngleLoc(E->getLAngleLoc());
6478 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006479 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6480 E->getNumTemplateArgs(),
6481 TransArgs))
6482 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006483 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 // FIXME: Bogus source location for the operator
6486 SourceLocation FakeOperatorLoc
6487 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6488
John McCallc2233c52010-01-15 08:34:02 +00006489 // FIXME: to do this check properly, we will need to preserve the
6490 // first-qualifier-in-scope here, just in case we had a dependent
6491 // base (and therefore couldn't do the check) and a
6492 // nested-name-qualifier (and therefore could do the lookup).
6493 NamedDecl *FirstQualifierInScope = 0;
6494
John McCall9ae2f072010-08-23 23:25:46 +00006495 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006497 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006498 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006499 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006500 Member,
John McCall6bb80172010-03-30 21:47:33 +00006501 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006502 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006503 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006504 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505}
Mike Stump1eb44332009-09-09 15:08:12 +00006506
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006508ExprResult
John McCall454feb92009-12-08 09:21:05 +00006509TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006510 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006512 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006513
John McCall60d7b3a2010-08-24 06:29:42 +00006514 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006517
Douglas Gregorb98b1992009-08-11 05:31:07 +00006518 if (!getDerived().AlwaysRebuild() &&
6519 LHS.get() == E->getLHS() &&
6520 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006521 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006522
Lang Hamesbe9af122012-10-02 04:45:10 +00006523 Sema::FPContractStateRAII FPContractState(getSema());
6524 getSema().FPFeatures.fp_contract = E->isFPContractable();
6525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006527 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528}
6529
Mike Stump1eb44332009-09-09 15:08:12 +00006530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006531ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006533 CompoundAssignOperator *E) {
6534 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535}
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006538ExprResult TreeTransform<Derived>::
6539TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6540 // Just rebuild the common and RHS expressions and see whether we
6541 // get any changes.
6542
6543 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6544 if (commonExpr.isInvalid())
6545 return ExprError();
6546
6547 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6548 if (rhs.isInvalid())
6549 return ExprError();
6550
6551 if (!getDerived().AlwaysRebuild() &&
6552 commonExpr.get() == e->getCommon() &&
6553 rhs.get() == e->getFalseExpr())
6554 return SemaRef.Owned(e);
6555
6556 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6557 e->getQuestionLoc(),
6558 0,
6559 e->getColonLoc(),
6560 rhs.get());
6561}
6562
6563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006564ExprResult
John McCall454feb92009-12-08 09:21:05 +00006565TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006566 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006568 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006569
John McCall60d7b3a2010-08-24 06:29:42 +00006570 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006572 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006573
John McCall60d7b3a2010-08-24 06:29:42 +00006574 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006576 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006577
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578 if (!getDerived().AlwaysRebuild() &&
6579 Cond.get() == E->getCond() &&
6580 LHS.get() == E->getLHS() &&
6581 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006582 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006583
John McCall9ae2f072010-08-23 23:25:46 +00006584 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006585 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006586 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006587 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006588 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
6591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006592ExprResult
John McCall454feb92009-12-08 09:21:05 +00006593TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006594 // Implicit casts are eliminated during transformation, since they
6595 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006596 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597}
Mike Stump1eb44332009-09-09 15:08:12 +00006598
Douglas Gregorb98b1992009-08-11 05:31:07 +00006599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006600ExprResult
John McCall454feb92009-12-08 09:21:05 +00006601TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006602 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6603 if (!Type)
6604 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006605
John McCall60d7b3a2010-08-24 06:29:42 +00006606 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006607 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006609 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006612 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006614 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006615
John McCall9d125032010-01-15 18:39:57 +00006616 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006617 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006619 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620}
Mike Stump1eb44332009-09-09 15:08:12 +00006621
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006623ExprResult
John McCall454feb92009-12-08 09:21:05 +00006624TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006625 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6626 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6627 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006628 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006629
John McCall60d7b3a2010-08-24 06:29:42 +00006630 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006635 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006637 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638
John McCall1d7d8d62010-01-19 22:33:45 +00006639 // Note: the expression type doesn't necessarily match the
6640 // type-as-written, but that's okay, because it should always be
6641 // derivable from the initializer.
6642
John McCall42f56b52010-01-18 19:35:47 +00006643 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006645 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646}
Mike Stump1eb44332009-09-09 15:08:12 +00006647
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006649ExprResult
John McCall454feb92009-12-08 09:21:05 +00006650TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006651 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006653 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006654
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 if (!getDerived().AlwaysRebuild() &&
6656 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006657 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006660 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006662 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 E->getAccessorLoc(),
6664 E->getAccessor());
6665}
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006668ExprResult
John McCall454feb92009-12-08 09:21:05 +00006669TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006672 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006673 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006674 Inits, &InitChanged))
6675 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006678 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006680 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006681 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682}
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006685ExprResult
John McCall454feb92009-12-08 09:21:05 +00006686TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregor43959a92009-08-20 07:17:43 +00006689 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006690 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006692 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006693
Douglas Gregor43959a92009-08-20 07:17:43 +00006694 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006695 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 bool ExprChanged = false;
6697 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6698 DEnd = E->designators_end();
6699 D != DEnd; ++D) {
6700 if (D->isFieldDesignator()) {
6701 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6702 D->getDotLoc(),
6703 D->getFieldLoc()));
6704 continue;
6705 }
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006708 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006710 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006711
6712 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6716 ArrayExprs.push_back(Index.release());
6717 continue;
6718 }
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006721 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006722 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6723 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006725
John McCall60d7b3a2010-08-24 06:29:42 +00006726 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006729
6730 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 End.get(),
6732 D->getLBracketLoc(),
6733 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006734
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6736 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006737
Douglas Gregorb98b1992009-08-11 05:31:07 +00006738 ArrayExprs.push_back(Start.release());
6739 ArrayExprs.push_back(End.release());
6740 }
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 if (!getDerived().AlwaysRebuild() &&
6743 Init.get() == E->getInit() &&
6744 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006745 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006747 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006749 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750}
Mike Stump1eb44332009-09-09 15:08:12 +00006751
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006753ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006755 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006756 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006757
Douglas Gregor5557b252009-10-28 00:29:27 +00006758 // FIXME: Will we ever have proper type location here? Will we actually
6759 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 QualType T = getDerived().TransformType(E->getType());
6761 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006762 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006763
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (!getDerived().AlwaysRebuild() &&
6765 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006766 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006767
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 return getDerived().RebuildImplicitValueInitExpr(T);
6769}
Mike Stump1eb44332009-09-09 15:08:12 +00006770
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006772ExprResult
John McCall454feb92009-12-08 09:21:05 +00006773TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006774 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6775 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006776 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006777
John McCall60d7b3a2010-08-24 06:29:42 +00006778 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006783 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006784 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006785 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006786
John McCall9ae2f072010-08-23 23:25:46 +00006787 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006788 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789}
6790
6791template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006792ExprResult
John McCall454feb92009-12-08 09:21:05 +00006793TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006794 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006795 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006796 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6797 &ArgumentChanged))
6798 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006799
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006801 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006802 E->getRParenLoc());
6803}
Mike Stump1eb44332009-09-09 15:08:12 +00006804
Douglas Gregorb98b1992009-08-11 05:31:07 +00006805/// \brief Transform an address-of-label expression.
6806///
6807/// By default, the transformation of an address-of-label expression always
6808/// rebuilds the expression, so that the label identifier can be resolved to
6809/// the corresponding label statement by semantic analysis.
6810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006811ExprResult
John McCall454feb92009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006813 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6814 E->getLabel());
6815 if (!LD)
6816 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006817
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006819 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820}
Mike Stump1eb44332009-09-09 15:08:12 +00006821
6822template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006823ExprResult
John McCall454feb92009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006825 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006826 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006827 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006828 if (SubStmt.isInvalid()) {
6829 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006830 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006831 }
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006834 SubStmt.get() == E->getSubStmt()) {
6835 // Calling this an 'error' is unintuitive, but it does the right thing.
6836 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006837 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006838 }
Mike Stump1eb44332009-09-09 15:08:12 +00006839
6840 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006841 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842 E->getRParenLoc());
6843}
Mike Stump1eb44332009-09-09 15:08:12 +00006844
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006846ExprResult
John McCall454feb92009-12-08 09:21:05 +00006847TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006848 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006851
John McCall60d7b3a2010-08-24 06:29:42 +00006852 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006854 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006855
John McCall60d7b3a2010-08-24 06:29:42 +00006856 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006859
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860 if (!getDerived().AlwaysRebuild() &&
6861 Cond.get() == E->getCond() &&
6862 LHS.get() == E->getLHS() &&
6863 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006864 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006865
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006867 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 E->getRParenLoc());
6869}
Mike Stump1eb44332009-09-09 15:08:12 +00006870
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006872ExprResult
John McCall454feb92009-12-08 09:21:05 +00006873TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006874 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875}
6876
6877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006878ExprResult
John McCall454feb92009-12-08 09:21:05 +00006879TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006880 switch (E->getOperator()) {
6881 case OO_New:
6882 case OO_Delete:
6883 case OO_Array_New:
6884 case OO_Array_Delete:
6885 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006886
Douglas Gregor668d6d92009-12-13 20:44:55 +00006887 case OO_Call: {
6888 // This is a call to an object's operator().
6889 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6890
6891 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006892 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006893 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006894 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006895
6896 // FIXME: Poor location information
6897 SourceLocation FakeLParenLoc
6898 = SemaRef.PP.getLocForEndOfToken(
6899 static_cast<Expr *>(Object.get())->getLocEnd());
6900
6901 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006902 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006903 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006904 Args))
6905 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006906
John McCall9ae2f072010-08-23 23:25:46 +00006907 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006908 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006909 E->getLocEnd());
6910 }
6911
6912#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6913 case OO_##Name:
6914#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6915#include "clang/Basic/OperatorKinds.def"
6916 case OO_Subscript:
6917 // Handled below.
6918 break;
6919
6920 case OO_Conditional:
6921 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006922
6923 case OO_None:
6924 case NUM_OVERLOADED_OPERATORS:
6925 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006926 }
6927
John McCall60d7b3a2010-08-24 06:29:42 +00006928 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006930 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006931
Richard Smithefeeccf2012-10-21 03:28:35 +00006932 ExprResult First;
6933 if (E->getOperator() == OO_Amp)
6934 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6935 else
6936 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006938 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939
John McCall60d7b3a2010-08-24 06:29:42 +00006940 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 if (E->getNumArgs() == 2) {
6942 Second = getDerived().TransformExpr(E->getArg(1));
6943 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006944 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 }
Mike Stump1eb44332009-09-09 15:08:12 +00006946
Douglas Gregorb98b1992009-08-11 05:31:07 +00006947 if (!getDerived().AlwaysRebuild() &&
6948 Callee.get() == E->getCallee() &&
6949 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006950 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006951 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006952
Lang Hamesbe9af122012-10-02 04:45:10 +00006953 Sema::FPContractStateRAII FPContractState(getSema());
6954 getSema().FPFeatures.fp_contract = E->isFPContractable();
6955
Douglas Gregorb98b1992009-08-11 05:31:07 +00006956 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6957 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006958 Callee.get(),
6959 First.get(),
6960 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961}
Mike Stump1eb44332009-09-09 15:08:12 +00006962
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006964ExprResult
John McCall454feb92009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6966 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967}
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006970ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006971TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6972 // Transform the callee.
6973 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6974 if (Callee.isInvalid())
6975 return ExprError();
6976
6977 // Transform exec config.
6978 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6979 if (EC.isInvalid())
6980 return ExprError();
6981
6982 // Transform arguments.
6983 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006984 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006985 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006986 &ArgChanged))
6987 return ExprError();
6988
6989 if (!getDerived().AlwaysRebuild() &&
6990 Callee.get() == E->getCallee() &&
6991 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006992 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006993
6994 // FIXME: Wrong source location information for the '('.
6995 SourceLocation FakeLParenLoc
6996 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6997 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006998 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006999 E->getRParenLoc(), EC.get());
7000}
7001
7002template<typename Derived>
7003ExprResult
John McCall454feb92009-12-08 09:21:05 +00007004TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007005 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7006 if (!Type)
7007 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007008
John McCall60d7b3a2010-08-24 06:29:42 +00007009 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007010 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007012 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007015 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007017 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007019 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007020 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007021 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007022 E->getAngleBrackets().getEnd(),
7023 // FIXME. this should be '(' location
7024 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007025 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007026 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027}
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007030ExprResult
John McCall454feb92009-12-08 09:21:05 +00007031TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7032 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033}
Mike Stump1eb44332009-09-09 15:08:12 +00007034
7035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007036ExprResult
John McCall454feb92009-12-08 09:21:05 +00007037TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7038 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007039}
7040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007042ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007043TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007044 CXXReinterpretCastExpr *E) {
7045 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046}
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007049ExprResult
John McCall454feb92009-12-08 09:21:05 +00007050TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7051 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052}
Mike Stump1eb44332009-09-09 15:08:12 +00007053
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007055ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007057 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007058 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7059 if (!Type)
7060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007061
John McCall60d7b3a2010-08-24 06:29:42 +00007062 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007063 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007064 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007065 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007066
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007068 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007070 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007071
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007072 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007074 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007075 E->getRParenLoc());
7076}
Mike Stump1eb44332009-09-09 15:08:12 +00007077
Douglas Gregorb98b1992009-08-11 05:31:07 +00007078template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007079ExprResult
John McCall454feb92009-12-08 09:21:05 +00007080TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007082 TypeSourceInfo *TInfo
7083 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7084 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007085 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007086
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007088 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007089 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007090
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007091 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7092 E->getLocStart(),
7093 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094 E->getLocEnd());
7095 }
Mike Stump1eb44332009-09-09 15:08:12 +00007096
Eli Friedmanef331b72012-01-20 01:26:23 +00007097 // We don't know whether the subexpression is potentially evaluated until
7098 // after we perform semantic analysis. We speculatively assume it is
7099 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007100 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007101 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7102 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007103
John McCall60d7b3a2010-08-24 06:29:42 +00007104 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007106 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007107
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108 if (!getDerived().AlwaysRebuild() &&
7109 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007110 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007112 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7113 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007114 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115 E->getLocEnd());
7116}
7117
7118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007119ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007120TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7121 if (E->isTypeOperand()) {
7122 TypeSourceInfo *TInfo
7123 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7124 if (!TInfo)
7125 return ExprError();
7126
7127 if (!getDerived().AlwaysRebuild() &&
7128 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007130
Douglas Gregor3c52a212011-03-06 17:40:41 +00007131 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007132 E->getLocStart(),
7133 TInfo,
7134 E->getLocEnd());
7135 }
7136
Francois Pichet01b7c302010-09-08 12:20:18 +00007137 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7138
7139 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7140 if (SubExpr.isInvalid())
7141 return ExprError();
7142
7143 if (!getDerived().AlwaysRebuild() &&
7144 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007146
7147 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7148 E->getLocStart(),
7149 SubExpr.get(),
7150 E->getLocEnd());
7151}
7152
7153template<typename Derived>
7154ExprResult
John McCall454feb92009-12-08 09:21:05 +00007155TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007156 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157}
Mike Stump1eb44332009-09-09 15:08:12 +00007158
Douglas Gregorb98b1992009-08-11 05:31:07 +00007159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007160ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007162 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007163 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164}
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregorb98b1992009-08-11 05:31:07 +00007166template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007167ExprResult
John McCall454feb92009-12-08 09:21:05 +00007168TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007169 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007170 QualType T;
7171 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7172 T = MD->getThisType(getSema().Context);
Douglas Gregore4743be2013-03-08 22:43:48 +00007173 else if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith7a614d82011-06-11 17:19:42 +00007174 T = getSema().Context.getPointerType(
Douglas Gregore4743be2013-03-08 22:43:48 +00007175 getSema().Context.getRecordType(Record));
7176 } else {
7177 assert(SemaRef.Context.getDiagnostics().hasErrorOccurred() &&
7178 "this in the wrong scope?");
7179 return ExprError();
7180 }
Mike Stump1eb44332009-09-09 15:08:12 +00007181
Douglas Gregorec79d872012-02-24 17:41:38 +00007182 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7183 // Make sure that we capture 'this'.
7184 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007185 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007186 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007187
Douglas Gregor828a1972010-01-07 23:12:05 +00007188 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189}
Mike Stump1eb44332009-09-09 15:08:12 +00007190
Douglas Gregorb98b1992009-08-11 05:31:07 +00007191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007192ExprResult
John McCall454feb92009-12-08 09:21:05 +00007193TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007194 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregorb98b1992009-08-11 05:31:07 +00007198 if (!getDerived().AlwaysRebuild() &&
7199 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007200 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201
Douglas Gregorbca01b42011-07-06 22:04:06 +00007202 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7203 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204}
Mike Stump1eb44332009-09-09 15:08:12 +00007205
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007207ExprResult
John McCall454feb92009-12-08 09:21:05 +00007208TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007209 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007210 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7211 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007212 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007213 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007215 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007217 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregor036aed12009-12-23 23:03:06 +00007219 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220}
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Douglas Gregorb98b1992009-08-11 05:31:07 +00007222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007223ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007224TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7225 CXXScalarValueInitExpr *E) {
7226 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7227 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007228 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007229
Douglas Gregorb98b1992009-08-11 05:31:07 +00007230 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007231 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007232 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007233
Chad Rosier4a9d7952012-08-08 18:46:20 +00007234 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007235 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007236 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007237}
Mike Stump1eb44332009-09-09 15:08:12 +00007238
Douglas Gregorb98b1992009-08-11 05:31:07 +00007239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007240ExprResult
John McCall454feb92009-12-08 09:21:05 +00007241TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007242 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007243 TypeSourceInfo *AllocTypeInfo
7244 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7245 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007247
Douglas Gregorb98b1992009-08-11 05:31:07 +00007248 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007249 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007251 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007252
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253 // Transform the placement arguments (if any).
7254 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007255 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007256 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007257 E->getNumPlacementArgs(), true,
7258 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007259 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007261 // Transform the initializer (if any).
7262 Expr *OldInit = E->getInitializer();
7263 ExprResult NewInit;
7264 if (OldInit)
7265 NewInit = getDerived().TransformExpr(OldInit);
7266 if (NewInit.isInvalid())
7267 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007268
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007269 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007270 FunctionDecl *OperatorNew = 0;
7271 if (E->getOperatorNew()) {
7272 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007273 getDerived().TransformDecl(E->getLocStart(),
7274 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007275 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007276 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007277 }
7278
7279 FunctionDecl *OperatorDelete = 0;
7280 if (E->getOperatorDelete()) {
7281 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007282 getDerived().TransformDecl(E->getLocStart(),
7283 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007284 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007285 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007286 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007287
Douglas Gregorb98b1992009-08-11 05:31:07 +00007288 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007289 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007290 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007291 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007292 OperatorNew == E->getOperatorNew() &&
7293 OperatorDelete == E->getOperatorDelete() &&
7294 !ArgumentChanged) {
7295 // Mark any declarations we need as referenced.
7296 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007297 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007298 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007300 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007301
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007302 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007303 QualType ElementType
7304 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7305 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7306 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7307 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007308 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007309 }
7310 }
7311 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007312
John McCall3fa5cae2010-10-26 07:05:15 +00007313 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007314 }
Mike Stump1eb44332009-09-09 15:08:12 +00007315
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007316 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007317 if (!ArraySize.get()) {
7318 // If no array size was specified, but the new expression was
7319 // instantiated with an array type (e.g., "new T" where T is
7320 // instantiated with "int[4]"), extract the outer bound from the
7321 // array type as our array size. We do this with constant and
7322 // dependently-sized array types.
7323 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7324 if (!ArrayT) {
7325 // Do nothing
7326 } else if (const ConstantArrayType *ConsArrayT
7327 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007328 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007329 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007330 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007331 SemaRef.Context.getSizeType(),
7332 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007333 AllocType = ConsArrayT->getElementType();
7334 } else if (const DependentSizedArrayType *DepArrayT
7335 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7336 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007337 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007338 AllocType = DepArrayT->getElementType();
7339 }
7340 }
7341 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007342
Douglas Gregorb98b1992009-08-11 05:31:07 +00007343 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7344 E->isGlobalNew(),
7345 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007346 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007348 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007350 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007351 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007352 E->getDirectInitRange(),
7353 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354}
Mike Stump1eb44332009-09-09 15:08:12 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007357ExprResult
John McCall454feb92009-12-08 09:21:05 +00007358TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007359 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007360 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregor1af74512010-02-26 00:38:10 +00007363 // Transform the delete operator, if known.
7364 FunctionDecl *OperatorDelete = 0;
7365 if (E->getOperatorDelete()) {
7366 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007367 getDerived().TransformDecl(E->getLocStart(),
7368 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007369 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007370 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007371 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007372
Douglas Gregorb98b1992009-08-11 05:31:07 +00007373 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007374 Operand.get() == E->getArgument() &&
7375 OperatorDelete == E->getOperatorDelete()) {
7376 // Mark any declarations we need as referenced.
7377 // FIXME: instantiation-specific.
7378 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007379 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007380
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007381 if (!E->getArgument()->isTypeDependent()) {
7382 QualType Destroyed = SemaRef.Context.getBaseElementType(
7383 E->getDestroyedType());
7384 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7385 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007386 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007387 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007388 }
7389 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007390
John McCall3fa5cae2010-10-26 07:05:15 +00007391 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007392 }
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7395 E->isGlobalDelete(),
7396 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007397 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007398}
Mike Stump1eb44332009-09-09 15:08:12 +00007399
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007401ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007402TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007403 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007404 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007405 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007407
John McCallb3d87482010-08-24 05:47:05 +00007408 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007409 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007410 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007411 E->getOperatorLoc(),
7412 E->isArrow()? tok::arrow : tok::period,
7413 ObjectTypePtr,
7414 MayBePseudoDestructor);
7415 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007416 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007417
John McCallb3d87482010-08-24 05:47:05 +00007418 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007419 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7420 if (QualifierLoc) {
7421 QualifierLoc
7422 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7423 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007424 return ExprError();
7425 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007426 CXXScopeSpec SS;
7427 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007428
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007429 PseudoDestructorTypeStorage Destroyed;
7430 if (E->getDestroyedTypeInfo()) {
7431 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007432 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007433 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007434 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007435 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007436 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007437 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007438 // We aren't likely to be able to resolve the identifier down to a type
7439 // now anyway, so just retain the identifier.
7440 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7441 E->getDestroyedTypeLoc());
7442 } else {
7443 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007444 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007445 *E->getDestroyedTypeIdentifier(),
7446 E->getDestroyedTypeLoc(),
7447 /*Scope=*/0,
7448 SS, ObjectTypePtr,
7449 false);
7450 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007451 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007452
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007453 Destroyed
7454 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7455 E->getDestroyedTypeLoc());
7456 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007457
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007458 TypeSourceInfo *ScopeTypeInfo = 0;
7459 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007460 CXXScopeSpec EmptySS;
7461 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7462 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007463 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007464 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007465 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007466
John McCall9ae2f072010-08-23 23:25:46 +00007467 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007468 E->getOperatorLoc(),
7469 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007470 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007471 ScopeTypeInfo,
7472 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007473 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007474 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007475}
Mike Stump1eb44332009-09-09 15:08:12 +00007476
Douglas Gregora71d8192009-09-04 17:36:40 +00007477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007478ExprResult
John McCallba135432009-11-21 08:51:07 +00007479TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007480 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007481 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7482 Sema::LookupOrdinaryName);
7483
7484 // Transform all the decls.
7485 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7486 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007487 NamedDecl *InstD = static_cast<NamedDecl*>(
7488 getDerived().TransformDecl(Old->getNameLoc(),
7489 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007490 if (!InstD) {
7491 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7492 // This can happen because of dependent hiding.
7493 if (isa<UsingShadowDecl>(*I))
7494 continue;
7495 else
John McCallf312b1e2010-08-26 23:41:50 +00007496 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007497 }
John McCallf7a1a742009-11-24 19:00:30 +00007498
7499 // Expand using declarations.
7500 if (isa<UsingDecl>(InstD)) {
7501 UsingDecl *UD = cast<UsingDecl>(InstD);
7502 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7503 E = UD->shadow_end(); I != E; ++I)
7504 R.addDecl(*I);
7505 continue;
7506 }
7507
7508 R.addDecl(InstD);
7509 }
7510
7511 // Resolve a kind, but don't do any further analysis. If it's
7512 // ambiguous, the callee needs to deal with it.
7513 R.resolveKind();
7514
7515 // Rebuild the nested-name qualifier, if present.
7516 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007517 if (Old->getQualifierLoc()) {
7518 NestedNameSpecifierLoc QualifierLoc
7519 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7520 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007521 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007522
Douglas Gregor4c9be892011-02-28 20:01:57 +00007523 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007524 }
7525
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007526 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007527 CXXRecordDecl *NamingClass
7528 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7529 Old->getNameLoc(),
7530 Old->getNamingClass()));
7531 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007532 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007533
Douglas Gregor66c45152010-04-27 16:10:10 +00007534 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007535 }
7536
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007537 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7538
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007539 // If we have neither explicit template arguments, nor the template keyword,
7540 // it's a normal declaration name.
7541 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007542 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7543
7544 // If we have template arguments, rebuild them, then rebuild the
7545 // templateid expression.
7546 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007547 if (Old->hasExplicitTemplateArgs() &&
7548 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007549 Old->getNumTemplateArgs(),
7550 TransArgs))
7551 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007552
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007553 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007554 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007555}
Mike Stump1eb44332009-09-09 15:08:12 +00007556
Douglas Gregorb98b1992009-08-11 05:31:07 +00007557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007558ExprResult
John McCall454feb92009-12-08 09:21:05 +00007559TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007560 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7561 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007562 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007563
Douglas Gregorb98b1992009-08-11 05:31:07 +00007564 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007565 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007566 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007567
Mike Stump1eb44332009-09-09 15:08:12 +00007568 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 T,
7571 E->getLocEnd());
7572}
Mike Stump1eb44332009-09-09 15:08:12 +00007573
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007575ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007576TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7577 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7578 if (!LhsT)
7579 return ExprError();
7580
7581 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7582 if (!RhsT)
7583 return ExprError();
7584
7585 if (!getDerived().AlwaysRebuild() &&
7586 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7587 return SemaRef.Owned(E);
7588
7589 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7590 E->getLocStart(),
7591 LhsT, RhsT,
7592 E->getLocEnd());
7593}
7594
7595template<typename Derived>
7596ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007597TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7598 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007599 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007600 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7601 TypeSourceInfo *From = E->getArg(I);
7602 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007603 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007604 TypeLocBuilder TLB;
7605 TLB.reserve(FromTL.getFullDataSize());
7606 QualType To = getDerived().TransformType(TLB, FromTL);
7607 if (To.isNull())
7608 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007609
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007610 if (To == From->getType())
7611 Args.push_back(From);
7612 else {
7613 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7614 ArgChanged = true;
7615 }
7616 continue;
7617 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007618
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007619 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007620
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007621 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007622 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007623 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7624 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7625 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007626
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007627 // Determine whether the set of unexpanded parameter packs can and should
7628 // be expanded.
7629 bool Expand = true;
7630 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007631 Optional<unsigned> OrigNumExpansions =
7632 ExpansionTL.getTypePtr()->getNumExpansions();
7633 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007634 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7635 PatternTL.getSourceRange(),
7636 Unexpanded,
7637 Expand, RetainExpansion,
7638 NumExpansions))
7639 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007640
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007641 if (!Expand) {
7642 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007643 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007644 // expansion.
7645 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007646
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007647 TypeLocBuilder TLB;
7648 TLB.reserve(From->getTypeLoc().getFullDataSize());
7649
7650 QualType To = getDerived().TransformType(TLB, PatternTL);
7651 if (To.isNull())
7652 return ExprError();
7653
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007655 PatternTL.getSourceRange(),
7656 ExpansionTL.getEllipsisLoc(),
7657 NumExpansions);
7658 if (To.isNull())
7659 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007660
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007661 PackExpansionTypeLoc ToExpansionTL
7662 = TLB.push<PackExpansionTypeLoc>(To);
7663 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7664 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7665 continue;
7666 }
7667
7668 // Expand the pack expansion by substituting for each argument in the
7669 // pack(s).
7670 for (unsigned I = 0; I != *NumExpansions; ++I) {
7671 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7672 TypeLocBuilder TLB;
7673 TLB.reserve(PatternTL.getFullDataSize());
7674 QualType To = getDerived().TransformType(TLB, PatternTL);
7675 if (To.isNull())
7676 return ExprError();
7677
7678 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7679 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007680
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007681 if (!RetainExpansion)
7682 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007683
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007684 // If we're supposed to retain a pack expansion, do so by temporarily
7685 // forgetting the partially-substituted parameter pack.
7686 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7687
7688 TypeLocBuilder TLB;
7689 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007690
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007691 QualType To = getDerived().TransformType(TLB, PatternTL);
7692 if (To.isNull())
7693 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007694
7695 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007696 PatternTL.getSourceRange(),
7697 ExpansionTL.getEllipsisLoc(),
7698 NumExpansions);
7699 if (To.isNull())
7700 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007701
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007702 PackExpansionTypeLoc ToExpansionTL
7703 = TLB.push<PackExpansionTypeLoc>(To);
7704 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7705 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7706 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007707
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007708 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7709 return SemaRef.Owned(E);
7710
7711 return getDerived().RebuildTypeTrait(E->getTrait(),
7712 E->getLocStart(),
7713 Args,
7714 E->getLocEnd());
7715}
7716
7717template<typename Derived>
7718ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007719TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7720 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7721 if (!T)
7722 return ExprError();
7723
7724 if (!getDerived().AlwaysRebuild() &&
7725 T == E->getQueriedTypeSourceInfo())
7726 return SemaRef.Owned(E);
7727
7728 ExprResult SubExpr;
7729 {
7730 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7731 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7732 if (SubExpr.isInvalid())
7733 return ExprError();
7734
7735 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7736 return SemaRef.Owned(E);
7737 }
7738
7739 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7740 E->getLocStart(),
7741 T,
7742 SubExpr.get(),
7743 E->getLocEnd());
7744}
7745
7746template<typename Derived>
7747ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007748TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7749 ExprResult SubExpr;
7750 {
7751 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7752 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7753 if (SubExpr.isInvalid())
7754 return ExprError();
7755
7756 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7757 return SemaRef.Owned(E);
7758 }
7759
7760 return getDerived().RebuildExpressionTrait(
7761 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7762}
7763
7764template<typename Derived>
7765ExprResult
John McCall865d4472009-11-19 22:55:06 +00007766TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007767 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007768 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7769}
7770
7771template<typename Derived>
7772ExprResult
7773TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7774 DependentScopeDeclRefExpr *E,
7775 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007776 NestedNameSpecifierLoc QualifierLoc
7777 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7778 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007779 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007780 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007781
John McCall43fed0d2010-11-12 08:19:04 +00007782 // TODO: If this is a conversion-function-id, verify that the
7783 // destination type name (if present) resolves the same way after
7784 // instantiation as it did in the local scope.
7785
Abramo Bagnara25777432010-08-11 22:01:17 +00007786 DeclarationNameInfo NameInfo
7787 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7788 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007789 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007790
John McCallf7a1a742009-11-24 19:00:30 +00007791 if (!E->hasExplicitTemplateArgs()) {
7792 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007793 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007794 // Note: it is sufficient to compare the Name component of NameInfo:
7795 // if name has not changed, DNLoc has not changed either.
7796 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007797 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007798
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007799 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007800 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007801 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007802 /*TemplateArgs*/ 0,
7803 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007804 }
John McCalld5532b62009-11-23 01:53:49 +00007805
7806 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007807 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7808 E->getNumTemplateArgs(),
7809 TransArgs))
7810 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007811
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007812 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007813 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007814 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007815 &TransArgs,
7816 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007817}
7818
7819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007820ExprResult
John McCall454feb92009-12-08 09:21:05 +00007821TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007822 // CXXConstructExprs other than for list-initialization and
7823 // CXXTemporaryObjectExpr are always implicit, so when we have
7824 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007825 if ((E->getNumArgs() == 1 ||
7826 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007827 (!getDerived().DropCallArgument(E->getArg(0))) &&
7828 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007829 return getDerived().TransformExpr(E->getArg(0));
7830
Douglas Gregorb98b1992009-08-11 05:31:07 +00007831 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7832
7833 QualType T = getDerived().TransformType(E->getType());
7834 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007835 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007836
7837 CXXConstructorDecl *Constructor
7838 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007839 getDerived().TransformDecl(E->getLocStart(),
7840 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007842 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007843
Douglas Gregorb98b1992009-08-11 05:31:07 +00007844 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007845 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007846 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007847 &ArgumentChanged))
7848 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007849
Douglas Gregorb98b1992009-08-11 05:31:07 +00007850 if (!getDerived().AlwaysRebuild() &&
7851 T == E->getType() &&
7852 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007853 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007854 // Mark the constructor as referenced.
7855 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007856 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007857 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007858 }
Mike Stump1eb44332009-09-09 15:08:12 +00007859
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007860 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7861 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007862 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007863 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007864 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007865 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007866 E->getConstructionKind(),
7867 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007868}
Mike Stump1eb44332009-09-09 15:08:12 +00007869
Douglas Gregorb98b1992009-08-11 05:31:07 +00007870/// \brief Transform a C++ temporary-binding expression.
7871///
Douglas Gregor51326552009-12-24 18:51:59 +00007872/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7873/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007875ExprResult
John McCall454feb92009-12-08 09:21:05 +00007876TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007877 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878}
Mike Stump1eb44332009-09-09 15:08:12 +00007879
John McCall4765fa02010-12-06 08:20:24 +00007880/// \brief Transform a C++ expression that contains cleanups that should
7881/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007882///
John McCall4765fa02010-12-06 08:20:24 +00007883/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007884/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007886ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007887TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007888 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007889}
Mike Stump1eb44332009-09-09 15:08:12 +00007890
Douglas Gregorb98b1992009-08-11 05:31:07 +00007891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007892ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007893TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007894 CXXTemporaryObjectExpr *E) {
7895 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7896 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007897 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007898
Douglas Gregorb98b1992009-08-11 05:31:07 +00007899 CXXConstructorDecl *Constructor
7900 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007901 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007902 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007904 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007905
Douglas Gregorb98b1992009-08-11 05:31:07 +00007906 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007907 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007909 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007910 &ArgumentChanged))
7911 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007912
Douglas Gregorb98b1992009-08-11 05:31:07 +00007913 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007914 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007915 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007916 !ArgumentChanged) {
7917 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007918 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007919 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007920 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007921
Richard Smithc83c2302012-12-19 01:39:02 +00007922 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007923 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7924 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007925 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007926 E->getLocEnd());
7927}
Mike Stump1eb44332009-09-09 15:08:12 +00007928
Douglas Gregorb98b1992009-08-11 05:31:07 +00007929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007930ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007931TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007932 // Transform the type of the lambda parameters and start the definition of
7933 // the lambda itself.
7934 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007935 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007936 if (!MethodTy)
7937 return ExprError();
7938
Eli Friedman8da8a662012-09-19 01:18:11 +00007939 // Create the local class that will describe the lambda.
7940 CXXRecordDecl *Class
7941 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7942 MethodTy,
7943 /*KnownDependent=*/false);
7944 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7945
Douglas Gregorc6889e72012-02-14 22:28:59 +00007946 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007947 SmallVector<QualType, 4> ParamTypes;
7948 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007949 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7950 E->getCallOperator()->param_begin(),
7951 E->getCallOperator()->param_size(),
7952 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007953 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007954
Douglas Gregordfca6f52012-02-13 22:00:16 +00007955 // Build the call operator.
7956 CXXMethodDecl *CallOperator
7957 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007958 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007959 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007960 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007961 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007962
Richard Smith612409e2012-07-25 03:56:55 +00007963 return getDerived().TransformLambdaScope(E, CallOperator);
7964}
7965
7966template<typename Derived>
7967ExprResult
7968TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7969 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007970 // Introduce the context of the call operator.
7971 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7972
Douglas Gregordfca6f52012-02-13 22:00:16 +00007973 // Enter the scope of the lambda.
7974 sema::LambdaScopeInfo *LSI
7975 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7976 E->getCaptureDefault(),
7977 E->hasExplicitParameters(),
7978 E->hasExplicitResultType(),
7979 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007980
Douglas Gregordfca6f52012-02-13 22:00:16 +00007981 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007982 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007983 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007984 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007985 CEnd = E->capture_end();
7986 C != CEnd; ++C) {
7987 // When we hit the first implicit capture, tell Sema that we've finished
7988 // the list of explicit captures.
7989 if (!FinishedExplicitCaptures && C->isImplicit()) {
7990 getSema().finishLambdaExplicitCaptures(LSI);
7991 FinishedExplicitCaptures = true;
7992 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007993
Douglas Gregordfca6f52012-02-13 22:00:16 +00007994 // Capturing 'this' is trivial.
7995 if (C->capturesThis()) {
7996 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7997 continue;
7998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007999
Douglas Gregora7365242012-02-14 19:27:52 +00008000 // Determine the capture kind for Sema.
8001 Sema::TryCaptureKind Kind
8002 = C->isImplicit()? Sema::TryCapture_Implicit
8003 : C->getCaptureKind() == LCK_ByCopy
8004 ? Sema::TryCapture_ExplicitByVal
8005 : Sema::TryCapture_ExplicitByRef;
8006 SourceLocation EllipsisLoc;
8007 if (C->isPackExpansion()) {
8008 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8009 bool ShouldExpand = false;
8010 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008011 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8013 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008014 Unexpanded,
8015 ShouldExpand, RetainExpansion,
8016 NumExpansions))
8017 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008018
Douglas Gregora7365242012-02-14 19:27:52 +00008019 if (ShouldExpand) {
8020 // The transform has determined that we should perform an expansion;
8021 // transform and capture each of the arguments.
8022 // expansion of the pattern. Do so.
8023 VarDecl *Pack = C->getCapturedVar();
8024 for (unsigned I = 0; I != *NumExpansions; ++I) {
8025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8026 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008027 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008028 Pack));
8029 if (!CapturedVar) {
8030 Invalid = true;
8031 continue;
8032 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008033
Douglas Gregora7365242012-02-14 19:27:52 +00008034 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008035 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8036 }
Douglas Gregora7365242012-02-14 19:27:52 +00008037 continue;
8038 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008039
Douglas Gregora7365242012-02-14 19:27:52 +00008040 EllipsisLoc = C->getEllipsisLoc();
8041 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008042
Douglas Gregordfca6f52012-02-13 22:00:16 +00008043 // Transform the captured variable.
8044 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008045 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008046 C->getCapturedVar()));
8047 if (!CapturedVar) {
8048 Invalid = true;
8049 continue;
8050 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008051
Douglas Gregordfca6f52012-02-13 22:00:16 +00008052 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008053 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008054 }
8055 if (!FinishedExplicitCaptures)
8056 getSema().finishLambdaExplicitCaptures(LSI);
8057
Douglas Gregordfca6f52012-02-13 22:00:16 +00008058
8059 // Enter a new evaluation context to insulate the lambda from any
8060 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008061 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008062
8063 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008064 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008065 /*IsInstantiation=*/true);
8066 return ExprError();
8067 }
8068
8069 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008070 StmtResult Body = getDerived().TransformStmt(E->getBody());
8071 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008072 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008073 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008074 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008075 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008076
Chad Rosier4a9d7952012-08-08 18:46:20 +00008077 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008078 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008079}
8080
8081template<typename Derived>
8082ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008083TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008084 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008085 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8086 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008087 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008088
Douglas Gregorb98b1992009-08-11 05:31:07 +00008089 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008090 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008091 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008092 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008093 &ArgumentChanged))
8094 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008095
Douglas Gregorb98b1992009-08-11 05:31:07 +00008096 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008097 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008098 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008099 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008100
Douglas Gregorb98b1992009-08-11 05:31:07 +00008101 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008102 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008103 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008104 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105 E->getRParenLoc());
8106}
Mike Stump1eb44332009-09-09 15:08:12 +00008107
Douglas Gregorb98b1992009-08-11 05:31:07 +00008108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008109ExprResult
John McCall865d4472009-11-19 22:55:06 +00008110TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008111 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008112 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008113 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008114 Expr *OldBase;
8115 QualType BaseType;
8116 QualType ObjectType;
8117 if (!E->isImplicitAccess()) {
8118 OldBase = E->getBase();
8119 Base = getDerived().TransformExpr(OldBase);
8120 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008121 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008122
John McCallaa81e162009-12-01 22:10:20 +00008123 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008124 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008125 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008126 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008127 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008128 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008129 ObjectTy,
8130 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008131 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008132 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008133
John McCallb3d87482010-08-24 05:47:05 +00008134 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008135 BaseType = ((Expr*) Base.get())->getType();
8136 } else {
8137 OldBase = 0;
8138 BaseType = getDerived().TransformType(E->getBaseType());
8139 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8140 }
Mike Stump1eb44332009-09-09 15:08:12 +00008141
Douglas Gregor6cd21982009-10-20 05:58:46 +00008142 // Transform the first part of the nested-name-specifier that qualifies
8143 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008144 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008145 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008146 E->getFirstQualifierFoundInScope(),
8147 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008148
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008149 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008150 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008151 QualifierLoc
8152 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8153 ObjectType,
8154 FirstQualifierInScope);
8155 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008156 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008157 }
Mike Stump1eb44332009-09-09 15:08:12 +00008158
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008159 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8160
John McCall43fed0d2010-11-12 08:19:04 +00008161 // TODO: If this is a conversion-function-id, verify that the
8162 // destination type name (if present) resolves the same way after
8163 // instantiation as it did in the local scope.
8164
Abramo Bagnara25777432010-08-11 22:01:17 +00008165 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008166 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008167 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008169
John McCallaa81e162009-12-01 22:10:20 +00008170 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008171 // This is a reference to a member without an explicitly-specified
8172 // template argument list. Optimize for this common case.
8173 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008174 Base.get() == OldBase &&
8175 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008176 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008177 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008178 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008179 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008180
John McCall9ae2f072010-08-23 23:25:46 +00008181 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008182 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008183 E->isArrow(),
8184 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008185 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008186 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008187 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008188 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008189 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008190 }
8191
John McCalld5532b62009-11-23 01:53:49 +00008192 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008193 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8194 E->getNumTemplateArgs(),
8195 TransArgs))
8196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008197
John McCall9ae2f072010-08-23 23:25:46 +00008198 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008199 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008200 E->isArrow(),
8201 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008202 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008203 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008204 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008205 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008206 &TransArgs);
8207}
8208
8209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008210ExprResult
John McCall454feb92009-12-08 09:21:05 +00008211TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008212 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008213 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008214 QualType BaseType;
8215 if (!Old->isImplicitAccess()) {
8216 Base = getDerived().TransformExpr(Old->getBase());
8217 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008218 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008219 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8220 Old->isArrow());
8221 if (Base.isInvalid())
8222 return ExprError();
8223 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008224 } else {
8225 BaseType = getDerived().TransformType(Old->getBaseType());
8226 }
John McCall129e2df2009-11-30 22:42:35 +00008227
Douglas Gregor4c9be892011-02-28 20:01:57 +00008228 NestedNameSpecifierLoc QualifierLoc;
8229 if (Old->getQualifierLoc()) {
8230 QualifierLoc
8231 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8232 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008233 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008234 }
8235
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008236 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8237
Abramo Bagnara25777432010-08-11 22:01:17 +00008238 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008239 Sema::LookupOrdinaryName);
8240
8241 // Transform all the decls.
8242 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8243 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008244 NamedDecl *InstD = static_cast<NamedDecl*>(
8245 getDerived().TransformDecl(Old->getMemberLoc(),
8246 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008247 if (!InstD) {
8248 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8249 // This can happen because of dependent hiding.
8250 if (isa<UsingShadowDecl>(*I))
8251 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008252 else {
8253 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008254 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008255 }
John McCall9f54ad42009-12-10 09:41:52 +00008256 }
John McCall129e2df2009-11-30 22:42:35 +00008257
8258 // Expand using declarations.
8259 if (isa<UsingDecl>(InstD)) {
8260 UsingDecl *UD = cast<UsingDecl>(InstD);
8261 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8262 E = UD->shadow_end(); I != E; ++I)
8263 R.addDecl(*I);
8264 continue;
8265 }
8266
8267 R.addDecl(InstD);
8268 }
8269
8270 R.resolveKind();
8271
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008272 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008273 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008274 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008275 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008276 Old->getMemberLoc(),
8277 Old->getNamingClass()));
8278 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008279 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008280
Douglas Gregor66c45152010-04-27 16:10:10 +00008281 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008283
John McCall129e2df2009-11-30 22:42:35 +00008284 TemplateArgumentListInfo TransArgs;
8285 if (Old->hasExplicitTemplateArgs()) {
8286 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8287 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008288 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8289 Old->getNumTemplateArgs(),
8290 TransArgs))
8291 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008292 }
John McCallc2233c52010-01-15 08:34:02 +00008293
8294 // FIXME: to do this check properly, we will need to preserve the
8295 // first-qualifier-in-scope here, just in case we had a dependent
8296 // base (and therefore couldn't do the check) and a
8297 // nested-name-qualifier (and therefore could do the lookup).
8298 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008299
John McCall9ae2f072010-08-23 23:25:46 +00008300 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008301 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008302 Old->getOperatorLoc(),
8303 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008304 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008305 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008306 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008307 R,
8308 (Old->hasExplicitTemplateArgs()
8309 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008310}
8311
8312template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008313ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008314TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008315 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008316 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8317 if (SubExpr.isInvalid())
8318 return ExprError();
8319
8320 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008321 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008322
8323 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8324}
8325
8326template<typename Derived>
8327ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008328TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008329 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8330 if (Pattern.isInvalid())
8331 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008332
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008333 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8334 return SemaRef.Owned(E);
8335
Douglas Gregor67fd1252011-01-14 21:20:45 +00008336 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8337 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008338}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008339
8340template<typename Derived>
8341ExprResult
8342TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8343 // If E is not value-dependent, then nothing will change when we transform it.
8344 // Note: This is an instantiation-centric view.
8345 if (!E->isValueDependent())
8346 return SemaRef.Owned(E);
8347
8348 // Note: None of the implementations of TryExpandParameterPacks can ever
8349 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008351 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8352 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008353 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008354 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008355 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008356 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008357 ShouldExpand, RetainExpansion,
8358 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008359 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008360
Douglas Gregor089e8932011-10-10 18:59:29 +00008361 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008362 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008363
Douglas Gregor089e8932011-10-10 18:59:29 +00008364 NamedDecl *Pack = E->getPack();
8365 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008366 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008367 Pack));
8368 if (!Pack)
8369 return ExprError();
8370 }
8371
Chad Rosier4a9d7952012-08-08 18:46:20 +00008372
Douglas Gregoree8aff02011-01-04 17:33:58 +00008373 // We now know the length of the parameter pack, so build a new expression
8374 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008375 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8376 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008377 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008378}
8379
Douglas Gregorbe230c32011-01-03 17:17:50 +00008380template<typename Derived>
8381ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008382TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8383 SubstNonTypeTemplateParmPackExpr *E) {
8384 // Default behavior is to do nothing with this transformation.
8385 return SemaRef.Owned(E);
8386}
8387
8388template<typename Derived>
8389ExprResult
John McCall91a57552011-07-15 05:09:51 +00008390TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8391 SubstNonTypeTemplateParmExpr *E) {
8392 // Default behavior is to do nothing with this transformation.
8393 return SemaRef.Owned(E);
8394}
8395
8396template<typename Derived>
8397ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008398TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8399 // Default behavior is to do nothing with this transformation.
8400 return SemaRef.Owned(E);
8401}
8402
8403template<typename Derived>
8404ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008405TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8406 MaterializeTemporaryExpr *E) {
8407 return getDerived().TransformExpr(E->GetTemporaryExpr());
8408}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008409
Douglas Gregor03e80032011-06-21 17:03:29 +00008410template<typename Derived>
8411ExprResult
John McCall454feb92009-12-08 09:21:05 +00008412TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008413 return SemaRef.MaybeBindToTemporary(E);
8414}
8415
8416template<typename Derived>
8417ExprResult
8418TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008419 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008420}
8421
8422template<typename Derived>
8423ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008424TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8425 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8426 if (SubExpr.isInvalid())
8427 return ExprError();
8428
8429 if (!getDerived().AlwaysRebuild() &&
8430 SubExpr.get() == E->getSubExpr())
8431 return SemaRef.Owned(E);
8432
8433 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008434}
8435
8436template<typename Derived>
8437ExprResult
8438TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8439 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008440 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008441 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008443 /*IsCall=*/false, Elements, &ArgChanged))
8444 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008445
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008446 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8447 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008448
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008449 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8450 Elements.data(),
8451 Elements.size());
8452}
8453
8454template<typename Derived>
8455ExprResult
8456TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008457 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008458 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008459 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008460 bool ArgChanged = false;
8461 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8462 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008463
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008464 if (OrigElement.isPackExpansion()) {
8465 // This key/value element is a pack expansion.
8466 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8467 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8468 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8469 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8470
8471 // Determine whether the set of unexpanded parameter packs can
8472 // and should be expanded.
8473 bool Expand = true;
8474 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008475 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8476 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008477 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8478 OrigElement.Value->getLocEnd());
8479 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8480 PatternRange,
8481 Unexpanded,
8482 Expand, RetainExpansion,
8483 NumExpansions))
8484 return ExprError();
8485
8486 if (!Expand) {
8487 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008488 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008489 // expansion.
8490 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8491 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8492 if (Key.isInvalid())
8493 return ExprError();
8494
8495 if (Key.get() != OrigElement.Key)
8496 ArgChanged = true;
8497
8498 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8499 if (Value.isInvalid())
8500 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008501
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008502 if (Value.get() != OrigElement.Value)
8503 ArgChanged = true;
8504
Chad Rosier4a9d7952012-08-08 18:46:20 +00008505 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008506 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8507 };
8508 Elements.push_back(Expansion);
8509 continue;
8510 }
8511
8512 // Record right away that the argument was changed. This needs
8513 // to happen even if the array expands to nothing.
8514 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008515
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008516 // The transform has determined that we should perform an elementwise
8517 // expansion of the pattern. Do so.
8518 for (unsigned I = 0; I != *NumExpansions; ++I) {
8519 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8520 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8521 if (Key.isInvalid())
8522 return ExprError();
8523
8524 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8525 if (Value.isInvalid())
8526 return ExprError();
8527
Chad Rosier4a9d7952012-08-08 18:46:20 +00008528 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008529 Key.get(), Value.get(), SourceLocation(), NumExpansions
8530 };
8531
8532 // If any unexpanded parameter packs remain, we still have a
8533 // pack expansion.
8534 if (Key.get()->containsUnexpandedParameterPack() ||
8535 Value.get()->containsUnexpandedParameterPack())
8536 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008537
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008538 Elements.push_back(Element);
8539 }
8540
8541 // We've finished with this pack expansion.
8542 continue;
8543 }
8544
8545 // Transform and check key.
8546 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8547 if (Key.isInvalid())
8548 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008549
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008550 if (Key.get() != OrigElement.Key)
8551 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008553 // Transform and check value.
8554 ExprResult Value
8555 = getDerived().TransformExpr(OrigElement.Value);
8556 if (Value.isInvalid())
8557 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008558
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008559 if (Value.get() != OrigElement.Value)
8560 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008561
8562 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008563 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008564 };
8565 Elements.push_back(Element);
8566 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008568 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8569 return SemaRef.MaybeBindToTemporary(E);
8570
8571 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8572 Elements.data(),
8573 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008574}
8575
Mike Stump1eb44332009-09-09 15:08:12 +00008576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008577ExprResult
John McCall454feb92009-12-08 09:21:05 +00008578TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008579 TypeSourceInfo *EncodedTypeInfo
8580 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8581 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008582 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008583
Douglas Gregorb98b1992009-08-11 05:31:07 +00008584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008585 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008586 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008587
8588 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008589 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008590 E->getRParenLoc());
8591}
Mike Stump1eb44332009-09-09 15:08:12 +00008592
Douglas Gregorb98b1992009-08-11 05:31:07 +00008593template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008594ExprResult TreeTransform<Derived>::
8595TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8596 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8597 if (result.isInvalid()) return ExprError();
8598 Expr *subExpr = result.take();
8599
8600 if (!getDerived().AlwaysRebuild() &&
8601 subExpr == E->getSubExpr())
8602 return SemaRef.Owned(E);
8603
8604 return SemaRef.Owned(new(SemaRef.Context)
8605 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8606}
8607
8608template<typename Derived>
8609ExprResult TreeTransform<Derived>::
8610TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008611 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008612 = getDerived().TransformType(E->getTypeInfoAsWritten());
8613 if (!TSInfo)
8614 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008615
John McCallf85e1932011-06-15 23:02:42 +00008616 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008617 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008618 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008619
John McCallf85e1932011-06-15 23:02:42 +00008620 if (!getDerived().AlwaysRebuild() &&
8621 TSInfo == E->getTypeInfoAsWritten() &&
8622 Result.get() == E->getSubExpr())
8623 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008624
John McCallf85e1932011-06-15 23:02:42 +00008625 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008626 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008627 Result.get());
8628}
8629
8630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008631ExprResult
John McCall454feb92009-12-08 09:21:05 +00008632TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008633 // Transform arguments.
8634 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008635 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008636 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008637 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008638 &ArgChanged))
8639 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008640
Douglas Gregor92e986e2010-04-22 16:44:27 +00008641 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8642 // Class message: transform the receiver type.
8643 TypeSourceInfo *ReceiverTypeInfo
8644 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8645 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008646 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008647
Douglas Gregor92e986e2010-04-22 16:44:27 +00008648 // If nothing changed, just retain the existing message send.
8649 if (!getDerived().AlwaysRebuild() &&
8650 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008651 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008652
8653 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008654 SmallVector<SourceLocation, 16> SelLocs;
8655 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008656 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8657 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008658 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008659 E->getMethodDecl(),
8660 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008661 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008662 E->getRightLoc());
8663 }
8664
8665 // Instance message: transform the receiver
8666 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8667 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008668 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008669 = getDerived().TransformExpr(E->getInstanceReceiver());
8670 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008671 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008672
8673 // If nothing changed, just retain the existing message send.
8674 if (!getDerived().AlwaysRebuild() &&
8675 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008676 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
Douglas Gregor92e986e2010-04-22 16:44:27 +00008678 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008679 SmallVector<SourceLocation, 16> SelLocs;
8680 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008681 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008682 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008683 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008684 E->getMethodDecl(),
8685 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008686 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008687 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008688}
8689
Mike Stump1eb44332009-09-09 15:08:12 +00008690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008691ExprResult
John McCall454feb92009-12-08 09:21:05 +00008692TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008693 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008694}
8695
Mike Stump1eb44332009-09-09 15:08:12 +00008696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008697ExprResult
John McCall454feb92009-12-08 09:21:05 +00008698TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008699 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008700}
8701
Mike Stump1eb44332009-09-09 15:08:12 +00008702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008703ExprResult
John McCall454feb92009-12-08 09:21:05 +00008704TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008705 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008706 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008707 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008708 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008709
8710 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008711
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008712 // If nothing changed, just retain the existing expression.
8713 if (!getDerived().AlwaysRebuild() &&
8714 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008715 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008716
John McCall9ae2f072010-08-23 23:25:46 +00008717 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008718 E->getLocation(),
8719 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008720}
8721
Mike Stump1eb44332009-09-09 15:08:12 +00008722template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008723ExprResult
John McCall454feb92009-12-08 09:21:05 +00008724TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008725 // 'super' and types never change. Property never changes. Just
8726 // retain the existing expression.
8727 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008728 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008729
Douglas Gregore3303542010-04-26 20:47:02 +00008730 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008731 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008732 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008733 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008734
Douglas Gregore3303542010-04-26 20:47:02 +00008735 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008736
Douglas Gregore3303542010-04-26 20:47:02 +00008737 // If nothing changed, just retain the existing expression.
8738 if (!getDerived().AlwaysRebuild() &&
8739 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008740 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008741
John McCall12f78a62010-12-02 01:19:52 +00008742 if (E->isExplicitProperty())
8743 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8744 E->getExplicitProperty(),
8745 E->getLocation());
8746
8747 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008748 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008749 E->getImplicitPropertyGetter(),
8750 E->getImplicitPropertySetter(),
8751 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008752}
8753
Mike Stump1eb44332009-09-09 15:08:12 +00008754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008755ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008756TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8757 // Transform the base expression.
8758 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8759 if (Base.isInvalid())
8760 return ExprError();
8761
8762 // Transform the key expression.
8763 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8764 if (Key.isInvalid())
8765 return ExprError();
8766
8767 // If nothing changed, just retain the existing expression.
8768 if (!getDerived().AlwaysRebuild() &&
8769 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8770 return SemaRef.Owned(E);
8771
Chad Rosier4a9d7952012-08-08 18:46:20 +00008772 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008773 Base.get(), Key.get(),
8774 E->getAtIndexMethodDecl(),
8775 E->setAtIndexMethodDecl());
8776}
8777
8778template<typename Derived>
8779ExprResult
John McCall454feb92009-12-08 09:21:05 +00008780TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008781 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008782 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008783 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008784 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008785
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008786 // If nothing changed, just retain the existing expression.
8787 if (!getDerived().AlwaysRebuild() &&
8788 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008789 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008790
John McCall9ae2f072010-08-23 23:25:46 +00008791 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanianec8deba2013-03-28 19:50:55 +00008792 E->getOpLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008793 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008794}
8795
Mike Stump1eb44332009-09-09 15:08:12 +00008796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008797ExprResult
John McCall454feb92009-12-08 09:21:05 +00008798TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008799 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008800 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008801 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008802 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008803 SubExprs, &ArgumentChanged))
8804 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008805
Douglas Gregorb98b1992009-08-11 05:31:07 +00008806 if (!getDerived().AlwaysRebuild() &&
8807 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008808 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008809
Douglas Gregorb98b1992009-08-11 05:31:07 +00008810 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008811 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008812 E->getRParenLoc());
8813}
8814
Mike Stump1eb44332009-09-09 15:08:12 +00008815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008816ExprResult
John McCall454feb92009-12-08 09:21:05 +00008817TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008818 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008819
John McCallc6ac9c32011-02-04 18:33:18 +00008820 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8821 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8822
8823 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008824 blockScope->TheDecl->setBlockMissingReturnType(
8825 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008826
Chris Lattner686775d2011-07-20 06:58:45 +00008827 SmallVector<ParmVarDecl*, 4> params;
8828 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008829
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008830 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008831 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8832 oldBlock->param_begin(),
8833 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008834 0, paramTypes, &params)) {
8835 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008836 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008837 }
John McCallc6ac9c32011-02-04 18:33:18 +00008838
Jordan Rose09189892013-03-08 22:25:36 +00008839 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008840 QualType exprResultType =
8841 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008842
8843 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008844 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008845 getSema().Diag(E->getCaretLocation(),
8846 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008847 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008848 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008849 return ExprError();
8850 }
John McCall711c52b2011-01-05 12:14:39 +00008851
Jordan Rosebea522f2013-03-08 21:51:21 +00008852 QualType functionType =
8853 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rose09189892013-03-08 22:25:36 +00008854 exprFunctionType->getExtProtoInfo());
John McCallc6ac9c32011-02-04 18:33:18 +00008855 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008856
8857 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008858 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008859 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008860
8861 if (!oldBlock->blockMissingReturnType()) {
8862 blockScope->HasImplicitReturnType = false;
8863 blockScope->ReturnType = exprResultType;
8864 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008865
John McCall711c52b2011-01-05 12:14:39 +00008866 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008867 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008868 if (body.isInvalid()) {
8869 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008870 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008871 }
John McCall711c52b2011-01-05 12:14:39 +00008872
John McCallc6ac9c32011-02-04 18:33:18 +00008873#ifndef NDEBUG
8874 // In builds with assertions, make sure that we captured everything we
8875 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008876 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8877 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8878 e = oldBlock->capture_end(); i != e; ++i) {
8879 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008880
Douglas Gregorfc921372011-05-20 15:32:55 +00008881 // Ignore parameter packs.
8882 if (isa<ParmVarDecl>(oldCapture) &&
8883 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8884 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008885
Douglas Gregorfc921372011-05-20 15:32:55 +00008886 VarDecl *newCapture =
8887 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8888 oldCapture));
8889 assert(blockScope->CaptureMap.count(newCapture));
8890 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008891 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008892 }
8893#endif
8894
8895 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8896 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008897}
8898
Mike Stump1eb44332009-09-09 15:08:12 +00008899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008900ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008901TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008902 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008903}
Eli Friedman276b0612011-10-11 02:20:01 +00008904
8905template<typename Derived>
8906ExprResult
8907TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008908 QualType RetTy = getDerived().TransformType(E->getType());
8909 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008910 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008911 SubExprs.reserve(E->getNumSubExprs());
8912 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8913 SubExprs, &ArgumentChanged))
8914 return ExprError();
8915
8916 if (!getDerived().AlwaysRebuild() &&
8917 !ArgumentChanged)
8918 return SemaRef.Owned(E);
8919
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008920 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008921 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008922}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008923
Douglas Gregorb98b1992009-08-11 05:31:07 +00008924//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008925// Type reconstruction
8926//===----------------------------------------------------------------------===//
8927
Mike Stump1eb44332009-09-09 15:08:12 +00008928template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008929QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8930 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008931 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008932 getDerived().getBaseEntity());
8933}
8934
Mike Stump1eb44332009-09-09 15:08:12 +00008935template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008936QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8937 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008938 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008939 getDerived().getBaseEntity());
8940}
8941
Mike Stump1eb44332009-09-09 15:08:12 +00008942template<typename Derived>
8943QualType
John McCall85737a72009-10-30 00:06:24 +00008944TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8945 bool WrittenAsLValue,
8946 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008947 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008948 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949}
8950
8951template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008952QualType
John McCall85737a72009-10-30 00:06:24 +00008953TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8954 QualType ClassType,
8955 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008956 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008957 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008958}
8959
8960template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008961QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008962TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8963 ArrayType::ArraySizeModifier SizeMod,
8964 const llvm::APInt *Size,
8965 Expr *SizeExpr,
8966 unsigned IndexTypeQuals,
8967 SourceRange BracketsRange) {
8968 if (SizeExpr || !Size)
8969 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8970 IndexTypeQuals, BracketsRange,
8971 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008972
8973 QualType Types[] = {
8974 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8975 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8976 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008977 };
8978 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8979 QualType SizeType;
8980 for (unsigned I = 0; I != NumTypes; ++I)
8981 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8982 SizeType = Types[I];
8983 break;
8984 }
Mike Stump1eb44332009-09-09 15:08:12 +00008985
Eli Friedman01f276d2012-01-25 23:20:27 +00008986 // Note that we can return a VariableArrayType here in the case where
8987 // the element type was a dependent VariableArrayType.
8988 IntegerLiteral *ArraySize
8989 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8990 /*FIXME*/BracketsRange.getBegin());
8991 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008992 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008993 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008994}
Mike Stump1eb44332009-09-09 15:08:12 +00008995
Douglas Gregor577f75a2009-08-04 16:50:30 +00008996template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008997QualType
8998TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008999 ArrayType::ArraySizeModifier SizeMod,
9000 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00009001 unsigned IndexTypeQuals,
9002 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009003 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00009004 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005}
9006
9007template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009008QualType
Mike Stump1eb44332009-09-09 15:08:12 +00009009TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009010 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00009011 unsigned IndexTypeQuals,
9012 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009013 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00009014 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009015}
Mike Stump1eb44332009-09-09 15:08:12 +00009016
Douglas Gregor577f75a2009-08-04 16:50:30 +00009017template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009018QualType
9019TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009020 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009021 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009022 unsigned IndexTypeQuals,
9023 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009024 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009025 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009026 IndexTypeQuals, BracketsRange);
9027}
9028
9029template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009030QualType
9031TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009032 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00009033 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009034 unsigned IndexTypeQuals,
9035 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00009036 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00009037 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009038 IndexTypeQuals, BracketsRange);
9039}
9040
9041template<typename Derived>
9042QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00009043 unsigned NumElements,
9044 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00009045 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00009046 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009047}
Mike Stump1eb44332009-09-09 15:08:12 +00009048
Douglas Gregor577f75a2009-08-04 16:50:30 +00009049template<typename Derived>
9050QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
9051 unsigned NumElements,
9052 SourceLocation AttributeLoc) {
9053 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
9054 NumElements, true);
9055 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009056 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9057 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009058 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009059}
Mike Stump1eb44332009-09-09 15:08:12 +00009060
Douglas Gregor577f75a2009-08-04 16:50:30 +00009061template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009062QualType
9063TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009064 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009065 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009066 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009067}
Mike Stump1eb44332009-09-09 15:08:12 +00009068
Douglas Gregor577f75a2009-08-04 16:50:30 +00009069template<typename Derived>
Jordan Rosebea522f2013-03-08 21:51:21 +00009070QualType TreeTransform<Derived>::RebuildFunctionProtoType(
9071 QualType T,
9072 llvm::MutableArrayRef<QualType> ParamTypes,
Jordan Rose09189892013-03-08 22:25:36 +00009073 const FunctionProtoType::ExtProtoInfo &EPI) {
9074 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009075 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009076 getDerived().getBaseEntity(),
Jordan Rose09189892013-03-08 22:25:36 +00009077 EPI);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009078}
Mike Stump1eb44332009-09-09 15:08:12 +00009079
Douglas Gregor577f75a2009-08-04 16:50:30 +00009080template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009081QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9082 return SemaRef.Context.getFunctionNoProtoType(T);
9083}
9084
9085template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009086QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9087 assert(D && "no decl found");
9088 if (D->isInvalidDecl()) return QualType();
9089
Douglas Gregor92e986e2010-04-22 16:44:27 +00009090 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009091 TypeDecl *Ty;
9092 if (isa<UsingDecl>(D)) {
9093 UsingDecl *Using = cast<UsingDecl>(D);
9094 assert(Using->isTypeName() &&
9095 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9096
9097 // A valid resolved using typename decl points to exactly one type decl.
9098 assert(++Using->shadow_begin() == Using->shadow_end());
9099 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009100
John McCalled976492009-12-04 22:46:56 +00009101 } else {
9102 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9103 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9104 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9105 }
9106
9107 return SemaRef.Context.getTypeDeclType(Ty);
9108}
9109
9110template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009111QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9112 SourceLocation Loc) {
9113 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009114}
9115
9116template<typename Derived>
9117QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9118 return SemaRef.Context.getTypeOfType(Underlying);
9119}
9120
9121template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009122QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9123 SourceLocation Loc) {
9124 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009125}
9126
9127template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009128QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9129 UnaryTransformType::UTTKind UKind,
9130 SourceLocation Loc) {
9131 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9132}
9133
9134template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009135QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009136 TemplateName Template,
9137 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009138 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009139 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009140}
Mike Stump1eb44332009-09-09 15:08:12 +00009141
Douglas Gregordcee1a12009-08-06 05:28:30 +00009142template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009143QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9144 SourceLocation KWLoc) {
9145 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9146}
9147
9148template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009149TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009150TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009151 bool TemplateKW,
9152 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009153 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009154 Template);
9155}
9156
9157template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009158TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009159TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9160 const IdentifierInfo &Name,
9161 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009162 QualType ObjectType,
9163 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009164 UnqualifiedId TemplateName;
9165 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009166 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009167 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009168 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009169 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009170 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009171 /*EnteringContext=*/false,
9172 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009173 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009174}
Mike Stump1eb44332009-09-09 15:08:12 +00009175
Douglas Gregorb98b1992009-08-11 05:31:07 +00009176template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009177TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009178TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009179 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009180 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009181 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009182 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009183 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009184 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009185 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009186 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009187 Sema::TemplateTy Template;
9188 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009189 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009190 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009191 /*EnteringContext=*/false,
9192 Template);
9193 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009194}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009195
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009197ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009198TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9199 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009200 Expr *OrigCallee,
9201 Expr *First,
9202 Expr *Second) {
9203 Expr *Callee = OrigCallee->IgnoreParenCasts();
9204 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009205
Douglas Gregorb98b1992009-08-11 05:31:07 +00009206 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009207 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009208 if (!First->getType()->isOverloadableType() &&
9209 !Second->getType()->isOverloadableType())
9210 return getSema().CreateBuiltinArraySubscriptExpr(First,
9211 Callee->getLocStart(),
9212 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009213 } else if (Op == OO_Arrow) {
9214 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009215 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9216 } else if (Second == 0 || isPostIncDec) {
9217 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009218 // The argument is not of overloadable type, so try to create a
9219 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009220 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009221 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009222
John McCall9ae2f072010-08-23 23:25:46 +00009223 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009224 }
9225 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009226 if (!First->getType()->isOverloadableType() &&
9227 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009228 // Neither of the arguments is an overloadable type, so try to
9229 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009230 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009231 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009232 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009234 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009235
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009236 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009237 }
9238 }
Mike Stump1eb44332009-09-09 15:08:12 +00009239
9240 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009241 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009242 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009243
John McCall9ae2f072010-08-23 23:25:46 +00009244 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009245 assert(ULE->requiresADL());
9246
9247 // FIXME: Do we have to check
9248 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009249 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009250 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009251 // If we've resolved this to a particular non-member function, just call
9252 // that function. If we resolved it to a member function,
9253 // CreateOverloaded* will find that function for us.
9254 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9255 if (!isa<CXXMethodDecl>(ND))
9256 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009257 }
Mike Stump1eb44332009-09-09 15:08:12 +00009258
Douglas Gregorb98b1992009-08-11 05:31:07 +00009259 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009260 Expr *Args[2] = { First, Second };
9261 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009262
Douglas Gregorb98b1992009-08-11 05:31:07 +00009263 // Create the overloaded operator invocation for unary operators.
9264 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009265 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009266 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009267 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009268 }
Mike Stump1eb44332009-09-09 15:08:12 +00009269
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009270 if (Op == OO_Subscript) {
9271 SourceLocation LBrace;
9272 SourceLocation RBrace;
9273
9274 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9275 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9276 LBrace = SourceLocation::getFromRawEncoding(
9277 NameLoc.CXXOperatorName.BeginOpNameLoc);
9278 RBrace = SourceLocation::getFromRawEncoding(
9279 NameLoc.CXXOperatorName.EndOpNameLoc);
9280 } else {
9281 LBrace = Callee->getLocStart();
9282 RBrace = OpLoc;
9283 }
9284
9285 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9286 First, Second);
9287 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009288
Douglas Gregorb98b1992009-08-11 05:31:07 +00009289 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009290 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009291 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009292 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9293 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009294 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009295
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009296 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009297}
Mike Stump1eb44332009-09-09 15:08:12 +00009298
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009299template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009300ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009301TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009302 SourceLocation OperatorLoc,
9303 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009304 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009305 TypeSourceInfo *ScopeType,
9306 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009307 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009308 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009309 QualType BaseType = Base->getType();
9310 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009311 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009312 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009313 !BaseType->getAs<PointerType>()->getPointeeType()
9314 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009315 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009316 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009317 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009318 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009319 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009320 /*FIXME?*/true);
9321 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009322
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009323 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009324 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9325 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9326 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9327 NameInfo.setNamedTypeInfo(DestroyedType);
9328
Richard Smith6314db92012-05-15 06:15:11 +00009329 // The scope type is now known to be a valid nested name specifier
9330 // component. Tack it on to the end of the nested name specifier.
9331 if (ScopeType)
9332 SS.Extend(SemaRef.Context, SourceLocation(),
9333 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009334
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009335 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009336 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009337 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009338 SS, TemplateKWLoc,
9339 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009340 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009341 /*TemplateArgs*/ 0);
9342}
9343
Douglas Gregor577f75a2009-08-04 16:50:30 +00009344} // end namespace clang
9345
9346#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H