blob: af82abac93145ed912b184d948fffa1acccfad22 [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,
Richard Smitheefb3d52012-02-10 09:58:53 +0000717 bool Variadic, bool HasTrailingReturn,
718 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000719 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000720 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000721
John McCalla2becad2009-10-21 00:40:46 +0000722 /// \brief Build a new unprototyped function type.
723 QualType RebuildFunctionNoProtoType(QualType ResultType);
724
John McCalled976492009-12-04 22:46:56 +0000725 /// \brief Rebuild an unresolved typename type, given the decl that
726 /// the UnresolvedUsingTypenameDecl was transformed to.
727 QualType RebuildUnresolvedUsingType(Decl *D);
728
Douglas Gregor577f75a2009-08-04 16:50:30 +0000729 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000730 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000731 return SemaRef.Context.getTypeDeclType(Typedef);
732 }
733
734 /// \brief Build a new class/struct/union type.
735 QualType RebuildRecordType(RecordDecl *Record) {
736 return SemaRef.Context.getTypeDeclType(Record);
737 }
738
739 /// \brief Build a new Enum type.
740 QualType RebuildEnumType(EnumDecl *Enum) {
741 return SemaRef.Context.getTypeDeclType(Enum);
742 }
John McCall7da24312009-09-05 00:15:47 +0000743
Mike Stump1eb44332009-09-09 15:08:12 +0000744 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000745 ///
746 /// By default, performs semantic analysis when building the typeof type.
747 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000748 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749
Mike Stump1eb44332009-09-09 15:08:12 +0000750 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000751 ///
752 /// By default, builds a new TypeOfType with the given underlying type.
753 QualType RebuildTypeOfType(QualType Underlying);
754
Sean Huntca63c202011-05-24 22:41:36 +0000755 /// \brief Build a new unary transform type.
756 QualType RebuildUnaryTransformType(QualType BaseType,
757 UnaryTransformType::UTTKind UKind,
758 SourceLocation Loc);
759
Mike Stump1eb44332009-09-09 15:08:12 +0000760 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 ///
762 /// By default, performs semantic analysis when building the decltype type.
763 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000764 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000765
Richard Smith34b41d92011-02-20 03:19:35 +0000766 /// \brief Build a new C++0x auto type.
767 ///
768 /// By default, builds a new AutoType with the given deduced type.
769 QualType RebuildAutoType(QualType Deduced) {
770 return SemaRef.Context.getAutoType(Deduced);
771 }
772
Douglas Gregor577f75a2009-08-04 16:50:30 +0000773 /// \brief Build a new template specialization type.
774 ///
775 /// By default, performs semantic analysis when building the template
776 /// specialization type. Subclasses may override this routine to provide
777 /// different behavior.
778 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000779 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000780 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000781
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000782 /// \brief Build a new parenthesized type.
783 ///
784 /// By default, builds a new ParenType type from the inner type.
785 /// Subclasses may override this routine to provide different behavior.
786 QualType RebuildParenType(QualType InnerType) {
787 return SemaRef.Context.getParenType(InnerType);
788 }
789
Douglas Gregor577f75a2009-08-04 16:50:30 +0000790 /// \brief Build a new qualified name type.
791 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000792 /// By default, builds a new ElaboratedType type from the keyword,
793 /// the nested-name-specifier and the named type.
794 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000795 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
796 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000797 NestedNameSpecifierLoc QualifierLoc,
798 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000799 return SemaRef.Context.getElaboratedType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000801 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000802 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000803
804 /// \brief Build a new typename type that refers to a template-id.
805 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000806 /// By default, builds a new DependentNameType type from the
807 /// nested-name-specifier and the given type. Subclasses may override
808 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000809 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 ElaboratedTypeKeyword Keyword,
811 NestedNameSpecifierLoc QualifierLoc,
812 const IdentifierInfo *Name,
813 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000814 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000815 // Rebuild the template name.
816 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000817 CXXScopeSpec SS;
818 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000820 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000821
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000822 if (InstName.isNull())
823 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000824
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000825 // If it's still dependent, make a dependent specialization.
826 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000827 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
828 QualifierLoc.getNestedNameSpecifier(),
829 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000830 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000831
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000832 // Otherwise, make an elaborated type wrapping a non-dependent
833 // specialization.
834 QualType T =
835 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
836 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000837
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000838 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
839 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000840
841 return SemaRef.Context.getElaboratedType(Keyword,
842 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000843 T);
844 }
845
Douglas Gregor577f75a2009-08-04 16:50:30 +0000846 /// \brief Build a new typename type that refers to an identifier.
847 ///
848 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000849 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000850 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000851 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000853 NestedNameSpecifierLoc QualifierLoc,
854 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000855 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000856 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000857 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000858
Douglas Gregor2494dd02011-03-01 01:34:45 +0000859 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000860 // If the name is still dependent, just build a new dependent name type.
861 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000862 return SemaRef.Context.getDependentNameType(Keyword,
863 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000864 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 }
866
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000867 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000868 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000869 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000870
871 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
872
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000873 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000874 // into a non-dependent elaborated-type-specifier. Find the tag we're
875 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000876 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000877 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
878 if (!DC)
879 return QualType();
880
John McCall56138762010-05-27 06:40:31 +0000881 if (SemaRef.RequireCompleteDeclContext(SS, DC))
882 return QualType();
883
Douglas Gregor40336422010-03-31 22:19:08 +0000884 TagDecl *Tag = 0;
885 SemaRef.LookupQualifiedName(Result, DC);
886 switch (Result.getResultKind()) {
887 case LookupResult::NotFound:
888 case LookupResult::NotFoundInCurrentInstantiation:
889 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000890
Douglas Gregor40336422010-03-31 22:19:08 +0000891 case LookupResult::Found:
892 Tag = Result.getAsSingle<TagDecl>();
893 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000894
Douglas Gregor40336422010-03-31 22:19:08 +0000895 case LookupResult::FoundOverloaded:
896 case LookupResult::FoundUnresolvedValue:
897 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000898
Douglas Gregor40336422010-03-31 22:19:08 +0000899 case LookupResult::Ambiguous:
900 // Let the LookupResult structure handle ambiguities.
901 return QualType();
902 }
903
904 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000905 // Check where the name exists but isn't a tag type and use that to emit
906 // better diagnostics.
907 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
908 SemaRef.LookupQualifiedName(Result, DC);
909 switch (Result.getResultKind()) {
910 case LookupResult::Found:
911 case LookupResult::FoundOverloaded:
912 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000913 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000914 unsigned Kind = 0;
915 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000916 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
917 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000918 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
919 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
920 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000921 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000922 default:
923 // FIXME: Would be nice to highlight just the source range.
924 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
925 << Kind << Id << DC;
926 break;
927 }
Douglas Gregor40336422010-03-31 22:19:08 +0000928 return QualType();
929 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000930
Richard Trieubbf34c02011-06-10 03:11:26 +0000931 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
932 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000933 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000934 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
935 return QualType();
936 }
937
938 // Build the elaborated-type-specifier type.
939 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000940 return SemaRef.Context.getElaboratedType(Keyword,
941 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000942 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000945 /// \brief Build a new pack expansion type.
946 ///
947 /// By default, builds a new PackExpansionType type from the given pattern.
948 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000949 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000950 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000951 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +0000952 Optional<unsigned> NumExpansions) {
Douglas Gregorcded4f62011-01-14 17:04:44 +0000953 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
954 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000955 }
956
Eli Friedmanb001de72011-10-06 23:00:33 +0000957 /// \brief Build a new atomic type given its value type.
958 ///
959 /// By default, performs semantic analysis when building the atomic type.
960 /// Subclasses may override this routine to provide different behavior.
961 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
962
Douglas Gregord1067e52009-08-06 06:41:21 +0000963 /// \brief Build a new template name given a nested name specifier, a flag
964 /// indicating whether the "template" keyword was provided, and the template
965 /// that the template name refers to.
966 ///
967 /// By default, builds the new template name directly. Subclasses may override
968 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000969 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000970 bool TemplateKW,
971 TemplateDecl *Template);
972
Douglas Gregord1067e52009-08-06 06:41:21 +0000973 /// \brief Build a new template name given a nested name specifier and the
974 /// name that is referred to as a template.
975 ///
976 /// By default, performs semantic analysis to determine whether the name can
977 /// be resolved to a specific template, then builds the appropriate kind of
978 /// template name. Subclasses may override this routine to provide different
979 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000980 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
981 const IdentifierInfo &Name,
982 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000983 QualType ObjectType,
984 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000986 /// \brief Build a new template name given a nested name specifier and the
987 /// overloaded operator name that is referred to as a template.
988 ///
989 /// By default, performs semantic analysis to determine whether the name can
990 /// be resolved to a specific template, then builds the appropriate kind of
991 /// template name. Subclasses may override this routine to provide different
992 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000993 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000994 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000995 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000996 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000997
998 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000999 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +00001000 ///
1001 /// By default, performs semantic analysis to determine whether the name can
1002 /// be resolved to a specific template, then builds the appropriate kind of
1003 /// template name. Subclasses may override this routine to provide different
1004 /// behavior.
1005 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1006 const TemplateArgument &ArgPack) {
1007 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1008 }
1009
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 /// \brief Build a new compound statement.
1011 ///
1012 /// By default, performs semantic analysis to build the new statement.
1013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001014 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 MultiStmtArg Statements,
1016 SourceLocation RBraceLoc,
1017 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001018 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 IsStmtExpr);
1020 }
1021
1022 /// \brief Build a new case statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001027 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001029 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 ColonLoc);
1033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to a new case statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 getSema().ActOnCaseStmtBody(S, Body);
1041 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
Mike Stump1eb44332009-09-09 15:08:12 +00001043
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 /// \brief Build a new default statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001048 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Stmt *SubStmt) {
1051 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001052 /*CurScope=*/0);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Build a new label statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001059 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1060 SourceLocation ColonLoc, Stmt *SubStmt) {
1061 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
Mike Stump1eb44332009-09-09 15:08:12 +00001063
Richard Smith534986f2012-04-14 00:33:13 +00001064 /// \brief Build a new label statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001068 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1069 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001070 Stmt *SubStmt) {
1071 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1072 }
1073
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 /// \brief Build a new "if" statement.
1075 ///
1076 /// By default, performs semantic analysis to build the new statement.
1077 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001078 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001079 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001080 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001081 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 }
Mike Stump1eb44332009-09-09 15:08:12 +00001083
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 /// \brief Start building a new switch statement.
1085 ///
1086 /// By default, performs semantic analysis to build the new statement.
1087 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001088 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001089 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001090 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001091 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Douglas Gregor43959a92009-08-20 07:17:43 +00001094 /// \brief Attach the body to the switch statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001099 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
1102
1103 /// \brief Build a new while statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001107 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1108 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001109 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001110 }
Mike Stump1eb44332009-09-09 15:08:12 +00001111
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 /// \brief Build a new do-while statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 SourceLocation WhileLoc, SourceLocation LParenLoc,
1118 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001119 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1120 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
1122
1123 /// \brief Build a new for statement.
1124 ///
1125 /// By default, performs semantic analysis to build the new statement.
1126 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001127 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001128 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001129 VarDecl *CondVar, Sema::FullExprArg Inc,
1130 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001131 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001132 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001133 }
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor43959a92009-08-20 07:17:43 +00001135 /// \brief Build a new goto statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001139 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1140 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001141 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 }
1143
1144 /// \brief Build a new indirect goto statement.
1145 ///
1146 /// By default, performs semantic analysis to build the new statement.
1147 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001148 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001149 SourceLocation StarLoc,
1150 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001151 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001152 }
Mike Stump1eb44332009-09-09 15:08:12 +00001153
Douglas Gregor43959a92009-08-20 07:17:43 +00001154 /// \brief Build a new return statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001158 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001159 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001160 }
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Douglas Gregor43959a92009-08-20 07:17:43 +00001162 /// \brief Build a new declaration statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001167 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001168 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001169 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1170 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 }
Mike Stump1eb44332009-09-09 15:08:12 +00001172
Anders Carlsson703e3942010-01-24 05:50:09 +00001173 /// \brief Build a new inline asm statement.
1174 ///
1175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001177 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1178 bool IsVolatile, unsigned NumOutputs,
1179 unsigned NumInputs, IdentifierInfo **Names,
1180 MultiExprArg Constraints, MultiExprArg Exprs,
1181 Expr *AsmString, MultiExprArg Clobbers,
1182 SourceLocation RParenLoc) {
1183 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1184 NumInputs, Names, Constraints, Exprs,
1185 AsmString, Clobbers, RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001186 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001187
Chad Rosier8cd64b42012-06-11 20:47:18 +00001188 /// \brief Build a new MS style inline asm statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
Chad Rosierdf5faf52012-08-25 00:11:56 +00001192 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
1193 ArrayRef<Token> AsmToks, SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001194 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001195 }
1196
James Dennett699c9042012-06-15 07:13:21 +00001197 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001198 ///
1199 /// By default, performs semantic analysis to build the new statement.
1200 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001201 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001203 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001204 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001205 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001206 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001207 }
1208
Douglas Gregorbe270a02010-04-26 17:57:08 +00001209 /// \brief Rebuild an Objective-C exception declaration.
1210 ///
1211 /// By default, performs semantic analysis to build the new declaration.
1212 /// Subclasses may override this routine to provide different behavior.
1213 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1214 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001215 return getSema().BuildObjCExceptionDecl(TInfo, T,
1216 ExceptionDecl->getInnerLocStart(),
1217 ExceptionDecl->getLocation(),
1218 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001219 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001220
James Dennett699c9042012-06-15 07:13:21 +00001221 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001226 SourceLocation RParenLoc,
1227 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001228 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001229 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001230 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001232
James Dennett699c9042012-06-15 07:13:21 +00001233 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Stmt *Body) {
1239 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001240 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001241
James Dennett699c9042012-06-15 07:13:21 +00001242 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001246 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001247 Expr *Operand) {
1248 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001249 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001250
James Dennett699c9042012-06-15 07:13:21 +00001251 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
1255 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1256 Expr *object) {
1257 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1258 }
1259
James Dennett699c9042012-06-15 07:13:21 +00001260 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001261 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001265 Expr *Object, Stmt *Body) {
1266 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001267 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001268
James Dennett699c9042012-06-15 07:13:21 +00001269 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
1273 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1274 Stmt *Body) {
1275 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1276 }
John McCall990567c2011-07-27 01:07:15 +00001277
Douglas Gregorc3203e72010-04-22 23:10:45 +00001278 /// \brief Build a new Objective-C fast enumeration statement.
1279 ///
1280 /// By default, performs semantic analysis to build the new statement.
1281 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001282 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001283 Stmt *Element,
1284 Expr *Collection,
1285 SourceLocation RParenLoc,
1286 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001287 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001288 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001289 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001290 RParenLoc);
1291 if (ForEachStmt.isInvalid())
1292 return StmtError();
1293
1294 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001295 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001296
Douglas Gregor43959a92009-08-20 07:17:43 +00001297 /// \brief Build a new C++ exception declaration.
1298 ///
1299 /// By default, performs semantic analysis to build the new decaration.
1300 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001301 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001302 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001303 SourceLocation StartLoc,
1304 SourceLocation IdLoc,
1305 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001306 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1307 StartLoc, IdLoc, Id);
1308 if (Var)
1309 getSema().CurContext->addDecl(Var);
1310 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001311 }
1312
1313 /// \brief Build a new C++ catch statement.
1314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001317 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001318 VarDecl *ExceptionDecl,
1319 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001320 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1321 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregor43959a92009-08-20 07:17:43 +00001324 /// \brief Build a new C++ try statement.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001329 Stmt *TryBlock,
1330 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001331 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001332 }
Mike Stump1eb44332009-09-09 15:08:12 +00001333
Richard Smithad762fc2011-04-14 22:09:26 +00001334 /// \brief Build a new C++0x range-based for statement.
1335 ///
1336 /// By default, performs semantic analysis to build the new statement.
1337 /// Subclasses may override this routine to provide different behavior.
1338 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1339 SourceLocation ColonLoc,
1340 Stmt *Range, Stmt *BeginEnd,
1341 Expr *Cond, Expr *Inc,
1342 Stmt *LoopVar,
1343 SourceLocation RParenLoc) {
1344 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smith8b533d92012-09-20 21:52:32 +00001345 Cond, Inc, LoopVar, RParenLoc,
1346 Sema::BFRK_Rebuild);
Richard Smithad762fc2011-04-14 22:09:26 +00001347 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001348
1349 /// \brief Build a new C++0x range-based for statement.
1350 ///
1351 /// By default, performs semantic analysis to build the new statement.
1352 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001353 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001354 bool IsIfExists,
1355 NestedNameSpecifierLoc QualifierLoc,
1356 DeclarationNameInfo NameInfo,
1357 Stmt *Nested) {
1358 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1359 QualifierLoc, NameInfo, Nested);
1360 }
1361
Richard Smithad762fc2011-04-14 22:09:26 +00001362 /// \brief Attach body to a C++0x range-based for statement.
1363 ///
1364 /// By default, performs semantic analysis to finish the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
1366 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1367 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1368 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001369
John Wiegley28bbe4b2011-04-28 01:08:34 +00001370 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1371 SourceLocation TryLoc,
1372 Stmt *TryBlock,
1373 Stmt *Handler) {
1374 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1375 }
1376
1377 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1378 Expr *FilterExpr,
1379 Stmt *Block) {
1380 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1381 }
1382
1383 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1384 Stmt *Block) {
1385 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1386 }
1387
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 /// \brief Build a new expression that references a declaration.
1389 ///
1390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001392 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001393 LookupResult &R,
1394 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001395 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1396 }
1397
1398
1399 /// \brief Build a new expression that references a declaration.
1400 ///
1401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001403 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001404 ValueDecl *VD,
1405 const DeclarationNameInfo &NameInfo,
1406 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001407 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001408 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001409
1410 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001411
1412 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 }
Mike Stump1eb44332009-09-09 15:08:12 +00001414
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001416 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001419 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001421 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 }
1423
Douglas Gregora71d8192009-09-04 17:36:40 +00001424 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001425 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001429 SourceLocation OperatorLoc,
1430 bool isArrow,
1431 CXXScopeSpec &SS,
1432 TypeSourceInfo *ScopeType,
1433 SourceLocation CCLoc,
1434 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001435 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001436
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001438 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 /// By default, performs semantic analysis to build the new expression.
1440 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001441 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001442 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001443 Expr *SubExpr) {
1444 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 }
Mike Stump1eb44332009-09-09 15:08:12 +00001446
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001447 /// \brief Build a new builtin offsetof expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001451 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001452 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001453 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001454 unsigned NumComponents,
1455 SourceLocation RParenLoc) {
1456 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1457 NumComponents, RParenLoc);
1458 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001459
1460 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001461 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001465 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1466 SourceLocation OpLoc,
1467 UnaryExprOrTypeTrait ExprKind,
1468 SourceRange R) {
1469 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 }
1471
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001472 /// \brief Build a new sizeof, alignof or vec step expression with an
1473 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001474 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001477 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1478 UnaryExprOrTypeTrait ExprKind,
1479 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001480 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001481 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001484
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001485 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 }
Mike Stump1eb44332009-09-09 15:08:12 +00001487
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001489 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001492 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001494 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001496 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1497 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 RBracketLoc);
1499 }
1500
1501 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001502 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001505 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001507 SourceLocation RParenLoc,
1508 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001509 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001510 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
1512
1513 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001518 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001519 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001520 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001521 const DeclarationNameInfo &MemberNameInfo,
1522 ValueDecl *Member,
1523 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001524 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001525 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001526 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1527 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001528 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001529 // We have a reference to an unnamed field. This is always the
1530 // base of an anonymous struct/union member access, i.e. the
1531 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001532 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001533 assert(Member->getType()->isRecordType() &&
1534 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001535
Richard Smith9138b4e2011-10-26 19:06:56 +00001536 BaseResult =
1537 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001538 QualifierLoc.getNestedNameSpecifier(),
1539 FoundDecl, Member);
1540 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001541 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001542 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001543 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001544 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001545 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001546 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001547 cast<FieldDecl>(Member)->getType(),
1548 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001549 return getSema().Owned(ME);
1550 }
Mike Stump1eb44332009-09-09 15:08:12 +00001551
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001552 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001553 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001554
John Wiegley429bb272011-04-08 18:41:53 +00001555 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001556 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001557
John McCall6bb80172010-03-30 21:47:33 +00001558 // FIXME: this involves duplicating earlier analysis in a lot of
1559 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001560 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001561 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001562 R.resolveKind();
1563
John McCall9ae2f072010-08-23 23:25:46 +00001564 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001565 SS, TemplateKWLoc,
1566 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001567 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 }
Mike Stump1eb44332009-09-09 15:08:12 +00001569
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001571 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001574 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001575 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001576 Expr *LHS, Expr *RHS) {
1577 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 }
1579
1580 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001581 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001584 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001585 SourceLocation QuestionLoc,
1586 Expr *LHS,
1587 SourceLocation ColonLoc,
1588 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001589 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1590 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 }
1592
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001594 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001597 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001598 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001600 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001601 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001602 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
Mike Stump1eb44332009-09-09 15:08:12 +00001604
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001610 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001612 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001613 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001614 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 }
Mike Stump1eb44332009-09-09 15:08:12 +00001616
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001618 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 /// By default, performs semantic analysis to build the new expression.
1620 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001621 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 SourceLocation OpLoc,
1623 SourceLocation AccessorLoc,
1624 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001625
John McCall129e2df2009-11-30 22:42:35 +00001626 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001627 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001628 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001629 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001630 SS, SourceLocation(),
1631 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001632 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001633 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 }
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001637 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001640 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001641 MultiExprArg Inits,
1642 SourceLocation RBraceLoc,
1643 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001644 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001645 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001646 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001647 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001648
Douglas Gregore48319a2009-11-09 17:16:50 +00001649 // Patch in the result type we were given, which may have been computed
1650 // when the initial InitListExpr was built.
1651 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1652 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001653 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 }
Mike Stump1eb44332009-09-09 15:08:12 +00001655
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001657 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// By default, performs semantic analysis to build the new expression.
1659 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001660 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 MultiExprArg ArrayExprs,
1662 SourceLocation EqualOrColonLoc,
1663 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001664 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001665 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001667 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001669 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001671 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
Mike Stump1eb44332009-09-09 15:08:12 +00001673
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001675 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 /// By default, builds the implicit value initialization without performing
1677 /// any semantic analysis. Subclasses may override this routine to provide
1678 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001679 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1681 }
Mike Stump1eb44332009-09-09 15:08:12 +00001682
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001684 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001687 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001688 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001689 SourceLocation RParenLoc) {
1690 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001692 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 }
1694
1695 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001696 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001699 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001700 MultiExprArg SubExprs,
1701 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001702 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
Mike Stump1eb44332009-09-09 15:08:12 +00001704
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001706 ///
1707 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// rather than attempting to map the label statement itself.
1709 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001711 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001712 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 }
Mike Stump1eb44332009-09-09 15:08:12 +00001714
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001716 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001719 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001720 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001722 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 }
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 /// \brief Build a new __builtin_choose_expr expression.
1726 ///
1727 /// By default, performs semantic analysis to build the new expression.
1728 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001729 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001730 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
1732 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001733 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 RParenLoc);
1735 }
Mike Stump1eb44332009-09-09 15:08:12 +00001736
Peter Collingbournef111d932011-04-15 00:35:48 +00001737 /// \brief Build a new generic selection expression.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
1741 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1742 SourceLocation DefaultLoc,
1743 SourceLocation RParenLoc,
1744 Expr *ControllingExpr,
1745 TypeSourceInfo **Types,
1746 Expr **Exprs,
1747 unsigned NumAssocs) {
1748 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1749 ControllingExpr, Types, Exprs,
1750 NumAssocs);
1751 }
1752
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 /// \brief Build a new overloaded operator call expression.
1754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// The semantic analysis provides the behavior of template instantiation,
1757 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001758 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// argument-dependent lookup, etc. Subclasses may override this routine to
1760 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001761 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001763 Expr *Callee,
1764 Expr *First,
1765 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001766
1767 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 /// reinterpret_cast.
1769 ///
1770 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001771 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001773 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 Stmt::StmtClass Class,
1775 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001776 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation RAngleLoc,
1778 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001779 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 SourceLocation RParenLoc) {
1781 switch (Class) {
1782 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001783 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001784 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786
1787 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001788 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001789 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001790 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001791
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001793 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001794 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001795 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001797
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001799 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001800 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001801 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001804 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001805 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 }
Mike Stump1eb44332009-09-09 15:08:12 +00001807
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 /// \brief Build a new C++ static_cast expression.
1809 ///
1810 /// By default, performs semantic analysis to build the new expression.
1811 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001812 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001814 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 SourceLocation RAngleLoc,
1816 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001817 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001819 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001820 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001821 SourceRange(LAngleLoc, RAngleLoc),
1822 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 }
1824
1825 /// \brief Build a new C++ dynamic_cast expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001829 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001831 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 SourceLocation RAngleLoc,
1833 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001834 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001836 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001837 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001838 SourceRange(LAngleLoc, RAngleLoc),
1839 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new C++ reinterpret_cast expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001848 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RAngleLoc,
1850 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001851 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001853 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001854 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001855 SourceRange(LAngleLoc, RAngleLoc),
1856 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 }
1858
1859 /// \brief Build a new C++ const_cast expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001863 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001865 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001866 SourceLocation RAngleLoc,
1867 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001868 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001870 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001871 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001872 SourceRange(LAngleLoc, RAngleLoc),
1873 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001874 }
Mike Stump1eb44332009-09-09 15:08:12 +00001875
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 /// \brief Build a new C++ functional-style cast expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001880 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1881 SourceLocation LParenLoc,
1882 Expr *Sub,
1883 SourceLocation RParenLoc) {
1884 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001885 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 RParenLoc);
1887 }
Mike Stump1eb44332009-09-09 15:08:12 +00001888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new C++ typeid(type) expression.
1890 ///
1891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001893 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001894 SourceLocation TypeidLoc,
1895 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001897 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001898 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 }
Mike Stump1eb44332009-09-09 15:08:12 +00001900
Francois Pichet01b7c302010-09-08 12:20:18 +00001901
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 /// \brief Build a new C++ typeid(expr) expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001906 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001907 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001908 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001910 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001911 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001912 }
1913
Francois Pichet01b7c302010-09-08 12:20:18 +00001914 /// \brief Build a new C++ __uuidof(type) expression.
1915 ///
1916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
1918 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1919 SourceLocation TypeidLoc,
1920 TypeSourceInfo *Operand,
1921 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001922 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001923 RParenLoc);
1924 }
1925
1926 /// \brief Build a new C++ __uuidof(expr) expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
1930 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1931 SourceLocation TypeidLoc,
1932 Expr *Operand,
1933 SourceLocation RParenLoc) {
1934 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1935 RParenLoc);
1936 }
1937
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 /// \brief Build a new C++ "this" expression.
1939 ///
1940 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001941 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001943 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001944 QualType ThisType,
1945 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001946 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001948 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1949 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 }
1951
1952 /// \brief Build a new C++ throw expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001956 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1957 bool IsThrownVariableInScope) {
1958 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 }
1960
1961 /// \brief Build a new C++ default-argument expression.
1962 ///
1963 /// By default, builds a new default-argument expression, which does not
1964 /// require any semantic analysis. Subclasses may override this routine to
1965 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001966 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001967 ParmVarDecl *Param) {
1968 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1969 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 }
1971
1972 /// \brief Build a new C++ zero-initialization expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001976 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1977 SourceLocation LParenLoc,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Benjamin Kramer5354e772012-08-23 23:38:35 +00001980 MultiExprArg(), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981 }
Mike Stump1eb44332009-09-09 15:08:12 +00001982
Douglas Gregorb98b1992009-08-11 05:31:07 +00001983 /// \brief Build a new C++ "new" expression.
1984 ///
1985 /// By default, performs semantic analysis to build the new expression.
1986 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001987 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001988 bool UseGlobal,
1989 SourceLocation PlacementLParen,
1990 MultiExprArg PlacementArgs,
1991 SourceLocation PlacementRParen,
1992 SourceRange TypeIdParens,
1993 QualType AllocatedType,
1994 TypeSourceInfo *AllocatedTypeInfo,
1995 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001996 SourceRange DirectInitRange,
1997 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001998 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001999 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002000 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002001 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00002002 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00002003 AllocatedType,
2004 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002005 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002006 DirectInitRange,
2007 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 }
Mike Stump1eb44332009-09-09 15:08:12 +00002009
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010 /// \brief Build a new C++ "delete" expression.
2011 ///
2012 /// By default, performs semantic analysis to build the new expression.
2013 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002014 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002015 bool IsGlobalDelete,
2016 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002017 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002019 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 }
Mike Stump1eb44332009-09-09 15:08:12 +00002021
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 /// \brief Build a new unary type trait expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002026 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002027 SourceLocation StartLoc,
2028 TypeSourceInfo *T,
2029 SourceLocation RParenLoc) {
2030 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002031 }
2032
Francois Pichet6ad6f282010-12-07 00:08:36 +00002033 /// \brief Build a new binary type trait expression.
2034 ///
2035 /// By default, performs semantic analysis to build the new expression.
2036 /// Subclasses may override this routine to provide different behavior.
2037 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2038 SourceLocation StartLoc,
2039 TypeSourceInfo *LhsT,
2040 TypeSourceInfo *RhsT,
2041 SourceLocation RParenLoc) {
2042 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2043 }
2044
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002045 /// \brief Build a new type trait expression.
2046 ///
2047 /// By default, performs semantic analysis to build the new expression.
2048 /// Subclasses may override this routine to provide different behavior.
2049 ExprResult RebuildTypeTrait(TypeTrait Trait,
2050 SourceLocation StartLoc,
2051 ArrayRef<TypeSourceInfo *> Args,
2052 SourceLocation RParenLoc) {
2053 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2054 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002055
John Wiegley21ff2e52011-04-28 00:16:57 +00002056 /// \brief Build a new array type trait expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
2060 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2061 SourceLocation StartLoc,
2062 TypeSourceInfo *TSInfo,
2063 Expr *DimExpr,
2064 SourceLocation RParenLoc) {
2065 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2066 }
2067
John Wiegley55262202011-04-25 06:54:41 +00002068 /// \brief Build a new expression trait expression.
2069 ///
2070 /// By default, performs semantic analysis to build the new expression.
2071 /// Subclasses may override this routine to provide different behavior.
2072 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2073 SourceLocation StartLoc,
2074 Expr *Queried,
2075 SourceLocation RParenLoc) {
2076 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2077 }
2078
Mike Stump1eb44332009-09-09 15:08:12 +00002079 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002080 /// expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002084 ExprResult RebuildDependentScopeDeclRefExpr(
2085 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002086 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002087 const DeclarationNameInfo &NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00002088 const TemplateArgumentListInfo *TemplateArgs,
2089 bool IsAddressOfOperand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002091 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002092
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002093 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002094 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002095 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002096
Richard Smithefeeccf2012-10-21 03:28:35 +00002097 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo,
2098 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002099 }
2100
2101 /// \brief Build a new template-id expression.
2102 ///
2103 /// By default, performs semantic analysis to build the new expression.
2104 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002105 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002106 SourceLocation TemplateKWLoc,
2107 LookupResult &R,
2108 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002109 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002110 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2111 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 }
2113
2114 /// \brief Build a new object-construction expression.
2115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002118 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002119 SourceLocation Loc,
2120 CXXConstructorDecl *Constructor,
2121 bool IsElidable,
2122 MultiExprArg Args,
2123 bool HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002124 bool ListInitialization,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002125 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002126 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002127 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002128 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002129 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002130 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002131 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002132
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002133 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002134 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002135 HadMultipleCandidates,
Richard Smithc83c2302012-12-19 01:39:02 +00002136 ListInitialization,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002137 RequiresZeroInit, ConstructKind,
2138 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002139 }
2140
2141 /// \brief Build a new object-construction expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002145 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2146 SourceLocation LParenLoc,
2147 MultiExprArg Args,
2148 SourceLocation RParenLoc) {
2149 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002151 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002152 RParenLoc);
2153 }
2154
2155 /// \brief Build a new object-construction expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002159 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2160 SourceLocation LParenLoc,
2161 MultiExprArg Args,
2162 SourceLocation RParenLoc) {
2163 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002165 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002166 RParenLoc);
2167 }
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregorb98b1992009-08-11 05:31:07 +00002169 /// \brief Build a new member reference expression.
2170 ///
2171 /// By default, performs semantic analysis to build the new expression.
2172 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002173 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002174 QualType BaseType,
2175 bool IsArrow,
2176 SourceLocation OperatorLoc,
2177 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002178 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002179 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002180 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002181 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002182 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002183 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002184
John McCall9ae2f072010-08-23 23:25:46 +00002185 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002186 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002187 SS, TemplateKWLoc,
2188 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002189 MemberNameInfo,
2190 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 }
2192
John McCall129e2df2009-11-30 22:42:35 +00002193 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002194 ///
2195 /// By default, performs semantic analysis to build the new expression.
2196 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002197 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2198 SourceLocation OperatorLoc,
2199 bool IsArrow,
2200 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002201 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002202 NamedDecl *FirstQualifierInScope,
2203 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002204 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002205 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002206 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002207
John McCall9ae2f072010-08-23 23:25:46 +00002208 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002209 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002210 SS, TemplateKWLoc,
2211 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002212 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002213 }
Mike Stump1eb44332009-09-09 15:08:12 +00002214
Sebastian Redl2e156222010-09-10 20:55:43 +00002215 /// \brief Build a new noexcept expression.
2216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
2219 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2220 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2221 }
2222
Douglas Gregoree8aff02011-01-04 17:33:58 +00002223 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002224 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2225 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002226 SourceLocation RParenLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002227 Optional<unsigned> Length) {
Douglas Gregor089e8932011-10-10 18:59:29 +00002228 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002229 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2230 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002231 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002232
2233 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2234 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002235 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002236 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002237
Patrick Beardeb382ec2012-04-19 00:25:12 +00002238 /// \brief Build a new Objective-C boxed expression.
2239 ///
2240 /// By default, performs semantic analysis to build the new expression.
2241 /// Subclasses may override this routine to provide different behavior.
2242 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2243 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2244 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002245
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002246 /// \brief Build a new Objective-C array literal.
2247 ///
2248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
2250 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2251 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002252 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002253 MultiExprArg(Elements, NumElements));
2254 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002255
2256 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002257 Expr *Base, Expr *Key,
2258 ObjCMethodDecl *getterMethod,
2259 ObjCMethodDecl *setterMethod) {
2260 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2261 getterMethod, setterMethod);
2262 }
2263
2264 /// \brief Build a new Objective-C dictionary literal.
2265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2269 ObjCDictionaryElement *Elements,
2270 unsigned NumElements) {
2271 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002273
James Dennett699c9042012-06-15 07:13:21 +00002274 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002279 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002281 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002282 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002283 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002284
Douglas Gregor92e986e2010-04-22 16:44:27 +00002285 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002286 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002287 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002288 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002289 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002290 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002291 MultiExprArg Args,
2292 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002293 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2294 ReceiverTypeInfo->getType(),
2295 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002296 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002297 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002298 }
2299
2300 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002301 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002302 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002303 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002304 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002305 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002306 MultiExprArg Args,
2307 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002308 return SemaRef.BuildInstanceMessage(Receiver,
2309 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002310 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002311 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002312 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002313 }
2314
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 /// \brief Build a new Objective-C ivar reference expression.
2316 ///
2317 /// By default, performs semantic analysis to build the new expression.
2318 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002319 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002320 SourceLocation IvarLoc,
2321 bool IsArrow, bool IsFreeIvar) {
2322 // FIXME: We lose track of the IsFreeIvar bit.
2323 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002324 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002325 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2326 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002327 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002328 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002329 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002330 false);
John Wiegley429bb272011-04-08 18:41:53 +00002331 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002332 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002333
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002334 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002335 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002336
John Wiegley429bb272011-04-08 18:41:53 +00002337 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002338 /*FIXME:*/IvarLoc, IsArrow,
2339 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002340 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002341 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002342 /*TemplateArgs=*/0);
2343 }
Douglas Gregore3303542010-04-26 20:47:02 +00002344
2345 /// \brief Build a new Objective-C property reference expression.
2346 ///
2347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002349 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002350 ObjCPropertyDecl *Property,
2351 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002352 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002353 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002354 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2355 Sema::LookupMemberName);
2356 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002357 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002358 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002359 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002360 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002361 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362
Douglas Gregore3303542010-04-26 20:47:02 +00002363 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002364 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002365
John Wiegley429bb272011-04-08 18:41:53 +00002366 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002367 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002368 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002369 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002370 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002371 /*TemplateArgs=*/0);
2372 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002373
John McCall12f78a62010-12-02 01:19:52 +00002374 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002375 ///
2376 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002377 /// Subclasses may override this routine to provide different behavior.
2378 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2379 ObjCMethodDecl *Getter,
2380 ObjCMethodDecl *Setter,
2381 SourceLocation PropertyLoc) {
2382 // Since these expressions can only be value-dependent, we do not
2383 // need to perform semantic analysis again.
2384 return Owned(
2385 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2386 VK_LValue, OK_ObjCProperty,
2387 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002388 }
2389
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002390 /// \brief Build a new Objective-C "isa" expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002394 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002395 bool IsArrow) {
2396 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002397 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002398 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2399 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002400 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002401 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002402 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002403 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002404 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002405
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002406 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002407 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002408
John Wiegley429bb272011-04-08 18:41:53 +00002409 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002410 /*FIXME:*/IsaLoc, IsArrow,
2411 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002412 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002413 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002414 /*TemplateArgs=*/0);
2415 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002416
Douglas Gregorb98b1992009-08-11 05:31:07 +00002417 /// \brief Build a new shuffle vector expression.
2418 ///
2419 /// By default, performs semantic analysis to build the new expression.
2420 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002421 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002422 MultiExprArg SubExprs,
2423 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002425 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002426 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2427 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2428 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikie3bc93e32012-12-19 00:45:41 +00002429 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002430
Douglas Gregorb98b1992009-08-11 05:31:07 +00002431 // Build a reference to the __builtin_shufflevector builtin
David Blaikie3bc93e32012-12-19 00:45:41 +00002432 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002433 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2434 SemaRef.Context.BuiltinFnTy,
2435 VK_RValue, BuiltinLoc);
2436 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2437 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
2438 CK_BuiltinFnToFnPtr).take();
Mike Stump1eb44332009-09-09 15:08:12 +00002439
2440 // Build the CallExpr
John Wiegley429bb272011-04-08 18:41:53 +00002441 ExprResult TheCall = SemaRef.Owned(
Eli Friedmana6c66ce2012-08-31 00:14:07 +00002442 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, SubExprs,
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002443 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002444 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002445 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002446
Douglas Gregorb98b1992009-08-11 05:31:07 +00002447 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002448 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002449 }
John McCall43fed0d2010-11-12 08:19:04 +00002450
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002451 /// \brief Build a new template argument pack expansion.
2452 ///
2453 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002454 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002455 /// different behavior.
2456 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002457 SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002458 Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002459 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002460 case TemplateArgument::Expression: {
2461 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002462 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2463 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002464 if (Result.isInvalid())
2465 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002466
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002467 return TemplateArgumentLoc(Result.get(), Result.get());
2468 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002469
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002470 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002471 return TemplateArgumentLoc(TemplateArgument(
2472 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002473 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002474 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002475 Pattern.getTemplateNameLoc(),
2476 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002477
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002478 case TemplateArgument::Null:
2479 case TemplateArgument::Integral:
2480 case TemplateArgument::Declaration:
2481 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002482 case TemplateArgument::TemplateExpansion:
Eli Friedmand7a6b162012-09-26 02:36:12 +00002483 case TemplateArgument::NullPtr:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002484 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002485
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002487 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002488 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002489 EllipsisLoc,
2490 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002491 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2492 Expansion);
2493 break;
2494 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002495
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002496 return TemplateArgumentLoc();
2497 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002498
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002499 /// \brief Build a new expression pack expansion.
2500 ///
2501 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002502 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002503 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002504 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikiedc84cd52013-02-20 22:23:23 +00002505 Optional<unsigned> NumExpansions) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002506 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002507 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002508
2509 /// \brief Build a new atomic operation expression.
2510 ///
2511 /// By default, performs semantic analysis to build the new expression.
2512 /// Subclasses may override this routine to provide different behavior.
2513 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2514 MultiExprArg SubExprs,
2515 QualType RetTy,
2516 AtomicExpr::AtomicOp Op,
2517 SourceLocation RParenLoc) {
2518 // Just create the expression; there is not any interesting semantic
2519 // analysis here because we can't actually build an AtomicExpr until
2520 // we are sure it is semantically sound.
Benjamin Kramer3b6bef92012-08-24 11:54:20 +00002521 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002522 RParenLoc);
2523 }
2524
John McCall43fed0d2010-11-12 08:19:04 +00002525private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002526 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2527 QualType ObjectType,
2528 NamedDecl *FirstQualifierInScope,
2529 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002530
2531 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2532 QualType ObjectType,
2533 NamedDecl *FirstQualifierInScope,
2534 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002535};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002536
Douglas Gregor43959a92009-08-20 07:17:43 +00002537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002538StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002539 if (!S)
2540 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002541
Douglas Gregor43959a92009-08-20 07:17:43 +00002542 switch (S->getStmtClass()) {
2543 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002544
Douglas Gregor43959a92009-08-20 07:17:43 +00002545 // Transform individual statement nodes
2546#define STMT(Node, Parent) \
2547 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002548#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002549#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002550#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002551
Douglas Gregor43959a92009-08-20 07:17:43 +00002552 // Transform expressions by calling TransformExpr.
2553#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002554#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002555#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002556#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002557 {
John McCall60d7b3a2010-08-24 06:29:42 +00002558 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002559 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002560 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002561
Richard Smith41956372013-01-14 22:39:08 +00002562 return getSema().ActOnExprStmt(E);
Douglas Gregor43959a92009-08-20 07:17:43 +00002563 }
Mike Stump1eb44332009-09-09 15:08:12 +00002564 }
2565
John McCall3fa5cae2010-10-26 07:05:15 +00002566 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002567}
Mike Stump1eb44332009-09-09 15:08:12 +00002568
2569
Douglas Gregor670444e2009-08-04 22:27:00 +00002570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002571ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002572 if (!E)
2573 return SemaRef.Owned(E);
2574
2575 switch (E->getStmtClass()) {
2576 case Stmt::NoStmtClass: break;
2577#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002578#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002579#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002580 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002581#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002582 }
2583
John McCall3fa5cae2010-10-26 07:05:15 +00002584 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002585}
2586
2587template<typename Derived>
Richard Smithc83c2302012-12-19 01:39:02 +00002588ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
2589 bool CXXDirectInit) {
2590 // Initializers are instantiated like expressions, except that various outer
2591 // layers are stripped.
2592 if (!Init)
2593 return SemaRef.Owned(Init);
2594
2595 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
2596 Init = ExprTemp->getSubExpr();
2597
2598 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
2599 Init = Binder->getSubExpr();
2600
2601 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
2602 Init = ICE->getSubExprAsWritten();
2603
Richard Smith5cf15892012-12-21 08:13:35 +00002604 // If this is not a direct-initializer, we only need to reconstruct
2605 // InitListExprs. Other forms of copy-initialization will be a no-op if
2606 // the initializer is already the right type.
2607 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
2608 if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
2609 return getDerived().TransformExpr(Init);
2610
2611 // Revert value-initialization back to empty parens.
2612 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
2613 SourceRange Parens = VIE->getSourceRange();
2614 return getDerived().RebuildParenListExpr(Parens.getBegin(), MultiExprArg(),
2615 Parens.getEnd());
2616 }
2617
2618 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
2619 if (isa<ImplicitValueInitExpr>(Init))
2620 return getDerived().RebuildParenListExpr(SourceLocation(), MultiExprArg(),
2621 SourceLocation());
2622
2623 // Revert initialization by constructor back to a parenthesized or braced list
2624 // of expressions. Any other form of initializer can just be reused directly.
2625 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithc83c2302012-12-19 01:39:02 +00002626 return getDerived().TransformExpr(Init);
2627
2628 SmallVector<Expr*, 8> NewArgs;
2629 bool ArgChanged = false;
2630 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
2631 /*IsCall*/true, NewArgs, &ArgChanged))
2632 return ExprError();
2633
2634 // If this was list initialization, revert to list form.
2635 if (Construct->isListInitialization())
2636 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
2637 Construct->getLocEnd(),
2638 Construct->getType());
2639
Richard Smithc83c2302012-12-19 01:39:02 +00002640 // Build a ParenListExpr to represent anything else.
2641 SourceRange Parens = Construct->getParenRange();
2642 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
2643 Parens.getEnd());
2644}
2645
2646template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002647bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2648 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002649 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002650 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002651 bool *ArgChanged) {
2652 for (unsigned I = 0; I != NumInputs; ++I) {
2653 // If requested, drop call arguments that need to be dropped.
2654 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2655 if (ArgChanged)
2656 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002657
Douglas Gregoraa165f82011-01-03 19:04:46 +00002658 break;
2659 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002660
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002661 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2662 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002663
Chris Lattner686775d2011-07-20 06:58:45 +00002664 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002665 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2666 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002667
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002668 // Determine whether the set of unexpanded parameter packs can and should
2669 // be expanded.
2670 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002671 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00002672 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
2673 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002674 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2675 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002676 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002677 Expand, RetainExpansion,
2678 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002679 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002680
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002681 if (!Expand) {
2682 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002683 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002684 // expansion.
2685 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2686 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2687 if (OutPattern.isInvalid())
2688 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002689
2690 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002691 Expansion->getEllipsisLoc(),
2692 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002693 if (Out.isInvalid())
2694 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002695
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002696 if (ArgChanged)
2697 *ArgChanged = true;
2698 Outputs.push_back(Out.get());
2699 continue;
2700 }
John McCallc8fc90a2011-07-06 07:30:07 +00002701
2702 // Record right away that the argument was changed. This needs
2703 // to happen even if the array expands to nothing.
2704 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002705
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002706 // The transform has determined that we should perform an elementwise
2707 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002708 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002709 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2710 ExprResult Out = getDerived().TransformExpr(Pattern);
2711 if (Out.isInvalid())
2712 return true;
2713
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002714 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002715 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2716 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002717 if (Out.isInvalid())
2718 return true;
2719 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002720
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002721 Outputs.push_back(Out.get());
2722 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002723
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002724 continue;
2725 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002726
Richard Smithc83c2302012-12-19 01:39:02 +00002727 ExprResult Result =
2728 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
2729 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregoraa165f82011-01-03 19:04:46 +00002730 if (Result.isInvalid())
2731 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002732
Douglas Gregoraa165f82011-01-03 19:04:46 +00002733 if (Result.get() != Inputs[I] && ArgChanged)
2734 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002735
2736 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002738
Douglas Gregoraa165f82011-01-03 19:04:46 +00002739 return false;
2740}
2741
2742template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002743NestedNameSpecifierLoc
2744TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2745 NestedNameSpecifierLoc NNS,
2746 QualType ObjectType,
2747 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002748 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002749 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002750 Qualifier = Qualifier.getPrefix())
2751 Qualifiers.push_back(Qualifier);
2752
2753 CXXScopeSpec SS;
2754 while (!Qualifiers.empty()) {
2755 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2756 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002757
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002758 switch (QNNS->getKind()) {
2759 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002760 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002761 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002762 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002763 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002765 FirstQualifierInScope, false))
2766 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002767
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002768 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002770 case NestedNameSpecifier::Namespace: {
2771 NamespaceDecl *NS
2772 = cast_or_null<NamespaceDecl>(
2773 getDerived().TransformDecl(
2774 Q.getLocalBeginLoc(),
2775 QNNS->getAsNamespace()));
2776 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2777 break;
2778 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002779
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002780 case NestedNameSpecifier::NamespaceAlias: {
2781 NamespaceAliasDecl *Alias
2782 = cast_or_null<NamespaceAliasDecl>(
2783 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2784 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002785 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002786 Q.getLocalEndLoc());
2787 break;
2788 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002789
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002790 case NestedNameSpecifier::Global:
2791 // There is no meaningful transformation that one could perform on the
2792 // global scope.
2793 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2794 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002795
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002796 case NestedNameSpecifier::TypeSpecWithTemplate:
2797 case NestedNameSpecifier::TypeSpec: {
2798 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2799 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002800
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002801 if (!TL)
2802 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002803
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002804 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith80ad52f2013-01-02 11:42:31 +00002805 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002806 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002807 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002808 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002809 if (TL.getType()->isEnumeralType())
2810 SemaRef.Diag(TL.getBeginLoc(),
2811 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002812 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2813 Q.getLocalEndLoc());
2814 break;
2815 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002816 // If the nested-name-specifier is an invalid type def, don't emit an
2817 // error because a previous error should have already been emitted.
David Blaikie39e6ab42013-02-18 22:06:02 +00002818 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
2819 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002820 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002821 << TL.getType() << SS.getRange();
2822 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002823 return NestedNameSpecifierLoc();
2824 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002825 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002826
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002827 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002828 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002829 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002830 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002831
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002832 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002833 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002834 !getDerived().AlwaysRebuild())
2835 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002836
2837 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002838 // nested-name-specifier, do so.
2839 if (SS.location_size() == NNS.getDataLength() &&
2840 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2841 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2842
2843 // Allocate new nested-name-specifier location information.
2844 return SS.getWithLocInContext(SemaRef.Context);
2845}
2846
2847template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002848DeclarationNameInfo
2849TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002850::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002851 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002852 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002853 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002854
2855 switch (Name.getNameKind()) {
2856 case DeclarationName::Identifier:
2857 case DeclarationName::ObjCZeroArgSelector:
2858 case DeclarationName::ObjCOneArgSelector:
2859 case DeclarationName::ObjCMultiArgSelector:
2860 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002861 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002862 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002863 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002864
Douglas Gregor81499bb2009-09-03 22:13:48 +00002865 case DeclarationName::CXXConstructorName:
2866 case DeclarationName::CXXDestructorName:
2867 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002868 TypeSourceInfo *NewTInfo;
2869 CanQualType NewCanTy;
2870 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002871 NewTInfo = getDerived().TransformType(OldTInfo);
2872 if (!NewTInfo)
2873 return DeclarationNameInfo();
2874 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002875 }
2876 else {
2877 NewTInfo = 0;
2878 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002879 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002880 if (NewT.isNull())
2881 return DeclarationNameInfo();
2882 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2883 }
Mike Stump1eb44332009-09-09 15:08:12 +00002884
Abramo Bagnara25777432010-08-11 22:01:17 +00002885 DeclarationName NewName
2886 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2887 NewCanTy);
2888 DeclarationNameInfo NewNameInfo(NameInfo);
2889 NewNameInfo.setName(NewName);
2890 NewNameInfo.setNamedTypeInfo(NewTInfo);
2891 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002892 }
Mike Stump1eb44332009-09-09 15:08:12 +00002893 }
2894
David Blaikieb219cfc2011-09-23 05:06:16 +00002895 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002896}
2897
2898template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002899TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002900TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2901 TemplateName Name,
2902 SourceLocation NameLoc,
2903 QualType ObjectType,
2904 NamedDecl *FirstQualifierInScope) {
2905 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2906 TemplateDecl *Template = QTN->getTemplateDecl();
2907 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002908
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002909 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002910 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002911 Template));
2912 if (!TransTemplate)
2913 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002914
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002915 if (!getDerived().AlwaysRebuild() &&
2916 SS.getScopeRep() == QTN->getQualifier() &&
2917 TransTemplate == Template)
2918 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002919
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002920 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2921 TransTemplate);
2922 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002923
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002924 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2925 if (SS.getScopeRep()) {
2926 // These apply to the scope specifier, not the template.
2927 ObjectType = QualType();
2928 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002929 }
2930
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002931 if (!getDerived().AlwaysRebuild() &&
2932 SS.getScopeRep() == DTN->getQualifier() &&
2933 ObjectType.isNull())
2934 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002935
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002936 if (DTN->isIdentifier()) {
2937 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002938 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002939 NameLoc,
2940 ObjectType,
2941 FirstQualifierInScope);
2942 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002943
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002944 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2945 ObjectType);
2946 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002947
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002948 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2949 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002951 Template));
2952 if (!TransTemplate)
2953 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002954
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002955 if (!getDerived().AlwaysRebuild() &&
2956 TransTemplate == Template)
2957 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002958
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002959 return TemplateName(TransTemplate);
2960 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002961
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002962 if (SubstTemplateTemplateParmPackStorage *SubstPack
2963 = Name.getAsSubstTemplateTemplateParmPack()) {
2964 TemplateTemplateParmDecl *TransParam
2965 = cast_or_null<TemplateTemplateParmDecl>(
2966 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2967 if (!TransParam)
2968 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002969
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002970 if (!getDerived().AlwaysRebuild() &&
2971 TransParam == SubstPack->getParameterPack())
2972 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002973
2974 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002975 SubstPack->getArgumentPack());
2976 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002977
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002978 // These should be getting filtered out before they reach the AST.
2979 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002980}
2981
2982template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002983void TreeTransform<Derived>::InventTemplateArgumentLoc(
2984 const TemplateArgument &Arg,
2985 TemplateArgumentLoc &Output) {
2986 SourceLocation Loc = getDerived().getBaseLocation();
2987 switch (Arg.getKind()) {
2988 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002989 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002990 break;
2991
2992 case TemplateArgument::Type:
2993 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002994 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002995
John McCall833ca992009-10-29 08:12:44 +00002996 break;
2997
Douglas Gregor788cd062009-11-11 01:00:40 +00002998 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002999 case TemplateArgument::TemplateExpansion: {
3000 NestedNameSpecifierLocBuilder Builder;
3001 TemplateName Template = Arg.getAsTemplate();
3002 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3003 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3004 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3005 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003006
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003007 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00003008 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003009 Builder.getWithLocInContext(SemaRef.Context),
3010 Loc);
3011 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00003012 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003013 Builder.getWithLocInContext(SemaRef.Context),
3014 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003015
Douglas Gregor788cd062009-11-11 01:00:40 +00003016 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003017 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003018
John McCall833ca992009-10-29 08:12:44 +00003019 case TemplateArgument::Expression:
3020 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3021 break;
3022
3023 case TemplateArgument::Declaration:
3024 case TemplateArgument::Integral:
3025 case TemplateArgument::Pack:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003026 case TemplateArgument::NullPtr:
John McCall828bff22009-10-29 18:45:58 +00003027 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003028 break;
3029 }
3030}
3031
3032template<typename Derived>
3033bool TreeTransform<Derived>::TransformTemplateArgument(
3034 const TemplateArgumentLoc &Input,
3035 TemplateArgumentLoc &Output) {
3036 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00003037 switch (Arg.getKind()) {
3038 case TemplateArgument::Null:
3039 case TemplateArgument::Integral:
Eli Friedman511e3ae2012-09-25 01:02:42 +00003040 case TemplateArgument::Pack:
3041 case TemplateArgument::Declaration:
Eli Friedmand7a6b162012-09-26 02:36:12 +00003042 case TemplateArgument::NullPtr:
3043 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump1eb44332009-09-09 15:08:12 +00003044
Douglas Gregor670444e2009-08-04 22:27:00 +00003045 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00003046 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00003047 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00003048 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00003049
3050 DI = getDerived().TransformType(DI);
3051 if (!DI) return true;
3052
3053 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3054 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 }
Mike Stump1eb44332009-09-09 15:08:12 +00003056
Douglas Gregor788cd062009-11-11 01:00:40 +00003057 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003058 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3059 if (QualifierLoc) {
3060 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3061 if (!QualifierLoc)
3062 return true;
3063 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003064
Douglas Gregor1d752d72011-03-02 18:46:51 +00003065 CXXScopeSpec SS;
3066 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003067 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003068 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3069 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003070 if (Template.isNull())
3071 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003072
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003073 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003074 Input.getTemplateNameLoc());
3075 return false;
3076 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003077
3078 case TemplateArgument::TemplateExpansion:
3079 llvm_unreachable("Caller should expand pack expansions");
3080
Douglas Gregor670444e2009-08-04 22:27:00 +00003081 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003082 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003083 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003084 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003085
John McCall833ca992009-10-29 08:12:44 +00003086 Expr *InputExpr = Input.getSourceExpression();
3087 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3088
Chris Lattner223de242011-04-25 20:37:58 +00003089 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003090 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003091 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003092 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003093 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003094 }
Douglas Gregor670444e2009-08-04 22:27:00 +00003095 }
Mike Stump1eb44332009-09-09 15:08:12 +00003096
Douglas Gregor670444e2009-08-04 22:27:00 +00003097 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003098 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003099}
3100
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003101/// \brief Iterator adaptor that invents template argument location information
3102/// for each of the template arguments in its underlying iterator.
3103template<typename Derived, typename InputIterator>
3104class TemplateArgumentLocInventIterator {
3105 TreeTransform<Derived> &Self;
3106 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003107
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003108public:
3109 typedef TemplateArgumentLoc value_type;
3110 typedef TemplateArgumentLoc reference;
3111 typedef typename std::iterator_traits<InputIterator>::difference_type
3112 difference_type;
3113 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003114
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003115 class pointer {
3116 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003117
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003118 public:
3119 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003121 const TemplateArgumentLoc *operator->() const { return &Arg; }
3122 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003123
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003124 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003125
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003126 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3127 InputIterator Iter)
3128 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003129
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003130 TemplateArgumentLocInventIterator &operator++() {
3131 ++Iter;
3132 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003133 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003134
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003135 TemplateArgumentLocInventIterator operator++(int) {
3136 TemplateArgumentLocInventIterator Old(*this);
3137 ++(*this);
3138 return Old;
3139 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003140
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003141 reference operator*() const {
3142 TemplateArgumentLoc Result;
3143 Self.InventTemplateArgumentLoc(*Iter, Result);
3144 return Result;
3145 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003146
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003148
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003149 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3150 const TemplateArgumentLocInventIterator &Y) {
3151 return X.Iter == Y.Iter;
3152 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003153
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003154 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3155 const TemplateArgumentLocInventIterator &Y) {
3156 return X.Iter != Y.Iter;
3157 }
3158};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003159
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003160template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003161template<typename InputIterator>
3162bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3163 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003164 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003166 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003167 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003168
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003169 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3170 // Unpack argument packs, which we translate them into separate
3171 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003172 // FIXME: We could do much better if we could guarantee that the
3173 // TemplateArgumentLocInfo for the pack expansion would be usable for
3174 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003175 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003176 TemplateArgument::pack_iterator>
3177 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003178 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003179 In.getArgument().pack_begin()),
3180 PackLocIterator(*this,
3181 In.getArgument().pack_end()),
3182 Outputs))
3183 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003184
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003185 continue;
3186 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003187
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003188 if (In.getArgument().isPackExpansion()) {
3189 // We have a pack expansion, for which we will be substituting into
3190 // the pattern.
3191 SourceLocation Ellipsis;
David Blaikiedc84cd52013-02-20 22:23:23 +00003192 Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003193 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003194 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003195 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003196
Chris Lattner686775d2011-07-20 06:58:45 +00003197 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003198 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3199 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003200
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003201 // Determine whether the set of unexpanded parameter packs can and should
3202 // be expanded.
3203 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003204 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00003205 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003206 if (getDerived().TryExpandParameterPacks(Ellipsis,
3207 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003208 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003209 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003210 RetainExpansion,
3211 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003212 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 if (!Expand) {
3215 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003216 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003217 // expansion.
3218 TemplateArgumentLoc OutPattern;
3219 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3220 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3221 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003222
Douglas Gregorcded4f62011-01-14 17:04:44 +00003223 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3224 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003225 if (Out.getArgument().isNull())
3226 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003227
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003228 Outputs.addArgument(Out);
3229 continue;
3230 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003231
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003232 // The transform has determined that we should perform an elementwise
3233 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003234 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003235 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3236
3237 if (getDerived().TransformTemplateArgument(Pattern, Out))
3238 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003239
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003240 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003241 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3242 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003243 if (Out.getArgument().isNull())
3244 return true;
3245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003246
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003247 Outputs.addArgument(Out);
3248 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003249
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003250 // If we're supposed to retain a pack expansion, do so by temporarily
3251 // forgetting the partially-substituted parameter pack.
3252 if (RetainExpansion) {
3253 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003255 if (getDerived().TransformTemplateArgument(Pattern, Out))
3256 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003257
Douglas Gregorcded4f62011-01-14 17:04:44 +00003258 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3259 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003260 if (Out.getArgument().isNull())
3261 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003262
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003263 Outputs.addArgument(Out);
3264 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003265
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003266 continue;
3267 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003268
3269 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003270 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003271 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003272
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003273 Outputs.addArgument(Out);
3274 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003275
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003276 return false;
3277
3278}
3279
Douglas Gregor577f75a2009-08-04 16:50:30 +00003280//===----------------------------------------------------------------------===//
3281// Type transformation
3282//===----------------------------------------------------------------------===//
3283
3284template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003285QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003286 if (getDerived().AlreadyTransformed(T))
3287 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003288
John McCalla2becad2009-10-21 00:40:46 +00003289 // Temporary workaround. All of these transformations should
3290 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003291 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3292 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003293
John McCall43fed0d2010-11-12 08:19:04 +00003294 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003295
John McCalla2becad2009-10-21 00:40:46 +00003296 if (!NewDI)
3297 return QualType();
3298
3299 return NewDI->getType();
3300}
3301
3302template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003303TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003304 // Refine the base location to the type's location.
3305 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3306 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003307 if (getDerived().AlreadyTransformed(DI->getType()))
3308 return DI;
3309
3310 TypeLocBuilder TLB;
3311
3312 TypeLoc TL = DI->getTypeLoc();
3313 TLB.reserve(TL.getFullDataSize());
3314
John McCall43fed0d2010-11-12 08:19:04 +00003315 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003316 if (Result.isNull())
3317 return 0;
3318
John McCalla93c9342009-12-07 02:54:59 +00003319 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003320}
3321
3322template<typename Derived>
3323QualType
John McCall43fed0d2010-11-12 08:19:04 +00003324TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003325 switch (T.getTypeLocClass()) {
3326#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie39e6ab42013-02-18 22:06:02 +00003327#define TYPELOC(CLASS, PARENT) \
3328 case TypeLoc::CLASS: \
3329 return getDerived().Transform##CLASS##Type(TLB, \
3330 T.castAs<CLASS##TypeLoc>());
John McCalla2becad2009-10-21 00:40:46 +00003331#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003332 }
Mike Stump1eb44332009-09-09 15:08:12 +00003333
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003334 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003335}
3336
3337/// FIXME: By default, this routine adds type qualifiers only to types
3338/// that can have qualifiers, and silently suppresses those qualifiers
3339/// that are not permitted (e.g., qualifiers on reference or function
3340/// types). This is the right thing for template instantiation, but
3341/// probably not for other clients.
3342template<typename Derived>
3343QualType
3344TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003345 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003346 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003347
John McCall43fed0d2010-11-12 08:19:04 +00003348 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003349 if (Result.isNull())
3350 return QualType();
3351
3352 // Silently suppress qualifiers if the result type can't be qualified.
3353 // FIXME: this is the right thing for template instantiation, but
3354 // probably not for other clients.
3355 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003356 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003357
John McCallf85e1932011-06-15 23:02:42 +00003358 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003359 // resulting type.
3360 if (Quals.hasObjCLifetime()) {
3361 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3362 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003363 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003364 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003365 // A lifetime qualifier applied to a substituted template parameter
3366 // overrides the lifetime qualifier from the template argument.
Douglas Gregor92d13872013-01-17 23:59:28 +00003367 const AutoType *AutoTy;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003368 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003369 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3370 QualType Replacement = SubstTypeParam->getReplacementType();
3371 Qualifiers Qs = Replacement.getQualifiers();
3372 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003373 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003374 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3375 Qs);
3376 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003377 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003378 Replacement);
3379 TLB.TypeWasModifiedSafely(Result);
Douglas Gregor92d13872013-01-17 23:59:28 +00003380 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3381 // 'auto' types behave the same way as template parameters.
3382 QualType Deduced = AutoTy->getDeducedType();
3383 Qualifiers Qs = Deduced.getQualifiers();
3384 Qs.removeObjCLifetime();
3385 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3386 Qs);
3387 Result = SemaRef.Context.getAutoType(Deduced);
3388 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore559ca12011-06-17 22:11:49 +00003389 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003390 // Otherwise, complain about the addition of a qualifier to an
3391 // already-qualified type.
3392 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003393 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003394 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003395
Douglas Gregore559ca12011-06-17 22:11:49 +00003396 Quals.removeObjCLifetime();
3397 }
3398 }
3399 }
John McCall28654742010-06-05 06:41:15 +00003400 if (!Quals.empty()) {
3401 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3402 TLB.push<QualifiedTypeLoc>(Result);
3403 // 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,
John McCalla2becad2009-10-21 00:40:46 +00004269 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004270 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004271 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004272 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004273 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004274 if (Result.isNull())
4275 return QualType();
4276 }
Mike Stump1eb44332009-09-09 15:08:12 +00004277
John McCalla2becad2009-10-21 00:40:46 +00004278 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004279 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004280 NewTL.setLParenLoc(TL.getLParenLoc());
4281 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004282 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004283 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4284 NewTL.setArg(i, ParamDecls[i]);
4285
4286 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
Douglas Gregor577f75a2009-08-04 16:50:30 +00004289template<typename Derived>
4290QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004291 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004292 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004293 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004294 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4295 if (ResultType.isNull())
4296 return QualType();
4297
4298 QualType Result = TL.getType();
4299 if (getDerived().AlwaysRebuild() ||
4300 ResultType != T->getResultType())
4301 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4302
4303 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004304 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnara59c0a812012-10-04 21:42:10 +00004305 NewTL.setLParenLoc(TL.getLParenLoc());
4306 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnara796aa442011-03-12 11:17:06 +00004307 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004308
4309 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004310}
Mike Stump1eb44332009-09-09 15:08:12 +00004311
John McCalled976492009-12-04 22:46:56 +00004312template<typename Derived> QualType
4313TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004314 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004315 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004316 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004317 if (!D)
4318 return QualType();
4319
4320 QualType Result = TL.getType();
4321 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4322 Result = getDerived().RebuildUnresolvedUsingType(D);
4323 if (Result.isNull())
4324 return QualType();
4325 }
4326
4327 // We might get an arbitrary type spec type back. We should at
4328 // least always get a type spec type, though.
4329 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4330 NewTL.setNameLoc(TL.getNameLoc());
4331
4332 return Result;
4333}
4334
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004336QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004337 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004338 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004339 TypedefNameDecl *Typedef
4340 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4341 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342 if (!Typedef)
4343 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
John McCalla2becad2009-10-21 00:40:46 +00004345 QualType Result = TL.getType();
4346 if (getDerived().AlwaysRebuild() ||
4347 Typedef != T->getDecl()) {
4348 Result = getDerived().RebuildTypedefType(Typedef);
4349 if (Result.isNull())
4350 return QualType();
4351 }
Mike Stump1eb44332009-09-09 15:08:12 +00004352
John McCalla2becad2009-10-21 00:40:46 +00004353 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4354 NewTL.setNameLoc(TL.getNameLoc());
4355
4356 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357}
Mike Stump1eb44332009-09-09 15:08:12 +00004358
Douglas Gregor577f75a2009-08-04 16:50:30 +00004359template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004360QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004361 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004362 // typeof expressions are not potentially evaluated contexts
Eli Friedman80bfa3d2012-09-26 04:34:21 +00004363 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4364 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00004365
John McCall60d7b3a2010-08-24 06:29:42 +00004366 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004367 if (E.isInvalid())
4368 return QualType();
4369
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004370 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4371 if (E.isInvalid())
4372 return QualType();
4373
John McCalla2becad2009-10-21 00:40:46 +00004374 QualType Result = TL.getType();
4375 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004376 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004377 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004378 if (Result.isNull())
4379 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380 }
John McCalla2becad2009-10-21 00:40:46 +00004381 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004382
John McCalla2becad2009-10-21 00:40:46 +00004383 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004384 NewTL.setTypeofLoc(TL.getTypeofLoc());
4385 NewTL.setLParenLoc(TL.getLParenLoc());
4386 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004387
4388 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389}
Mike Stump1eb44332009-09-09 15:08:12 +00004390
4391template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004392QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004393 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004394 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4395 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4396 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004397 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004398
John McCalla2becad2009-10-21 00:40:46 +00004399 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004400 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4401 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004402 if (Result.isNull())
4403 return QualType();
4404 }
Mike Stump1eb44332009-09-09 15:08:12 +00004405
John McCalla2becad2009-10-21 00:40:46 +00004406 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004407 NewTL.setTypeofLoc(TL.getTypeofLoc());
4408 NewTL.setLParenLoc(TL.getLParenLoc());
4409 NewTL.setRParenLoc(TL.getRParenLoc());
4410 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004411
4412 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004413}
Mike Stump1eb44332009-09-09 15:08:12 +00004414
4415template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004416QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004417 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004418 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004419
Douglas Gregor670444e2009-08-04 22:27:00 +00004420 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004421 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4422 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004423
John McCall60d7b3a2010-08-24 06:29:42 +00004424 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004425 if (E.isInvalid())
4426 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004427
Richard Smith76f3f692012-02-22 02:04:18 +00004428 E = getSema().ActOnDecltypeExpression(E.take());
4429 if (E.isInvalid())
4430 return QualType();
4431
John McCalla2becad2009-10-21 00:40:46 +00004432 QualType Result = TL.getType();
4433 if (getDerived().AlwaysRebuild() ||
4434 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004435 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004436 if (Result.isNull())
4437 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004438 }
John McCalla2becad2009-10-21 00:40:46 +00004439 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004440
John McCalla2becad2009-10-21 00:40:46 +00004441 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4442 NewTL.setNameLoc(TL.getNameLoc());
4443
4444 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004445}
4446
4447template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004448QualType TreeTransform<Derived>::TransformUnaryTransformType(
4449 TypeLocBuilder &TLB,
4450 UnaryTransformTypeLoc TL) {
4451 QualType Result = TL.getType();
4452 if (Result->isDependentType()) {
4453 const UnaryTransformType *T = TL.getTypePtr();
4454 QualType NewBase =
4455 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4456 Result = getDerived().RebuildUnaryTransformType(NewBase,
4457 T->getUTTKind(),
4458 TL.getKWLoc());
4459 if (Result.isNull())
4460 return QualType();
4461 }
4462
4463 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4464 NewTL.setKWLoc(TL.getKWLoc());
4465 NewTL.setParensRange(TL.getParensRange());
4466 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4467 return Result;
4468}
4469
4470template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004471QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4472 AutoTypeLoc TL) {
4473 const AutoType *T = TL.getTypePtr();
4474 QualType OldDeduced = T->getDeducedType();
4475 QualType NewDeduced;
4476 if (!OldDeduced.isNull()) {
4477 NewDeduced = getDerived().TransformType(OldDeduced);
4478 if (NewDeduced.isNull())
4479 return QualType();
4480 }
4481
4482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4484 Result = getDerived().RebuildAutoType(NewDeduced);
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4490 NewTL.setNameLoc(TL.getNameLoc());
4491
4492 return Result;
4493}
4494
4495template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004496QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004497 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004498 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004500 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4501 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502 if (!Record)
4503 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004504
John McCalla2becad2009-10-21 00:40:46 +00004505 QualType Result = TL.getType();
4506 if (getDerived().AlwaysRebuild() ||
4507 Record != T->getDecl()) {
4508 Result = getDerived().RebuildRecordType(Record);
4509 if (Result.isNull())
4510 return QualType();
4511 }
Mike Stump1eb44332009-09-09 15:08:12 +00004512
John McCalla2becad2009-10-21 00:40:46 +00004513 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4514 NewTL.setNameLoc(TL.getNameLoc());
4515
4516 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517}
Mike Stump1eb44332009-09-09 15:08:12 +00004518
4519template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004520QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004521 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004522 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004523 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004524 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4525 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004526 if (!Enum)
4527 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004528
John McCalla2becad2009-10-21 00:40:46 +00004529 QualType Result = TL.getType();
4530 if (getDerived().AlwaysRebuild() ||
4531 Enum != T->getDecl()) {
4532 Result = getDerived().RebuildEnumType(Enum);
4533 if (Result.isNull())
4534 return QualType();
4535 }
Mike Stump1eb44332009-09-09 15:08:12 +00004536
John McCalla2becad2009-10-21 00:40:46 +00004537 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4538 NewTL.setNameLoc(TL.getNameLoc());
4539
4540 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541}
John McCall7da24312009-09-05 00:15:47 +00004542
John McCall3cb0ebd2010-03-10 03:28:59 +00004543template<typename Derived>
4544QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4545 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004546 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004547 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4548 TL.getTypePtr()->getDecl());
4549 if (!D) return QualType();
4550
4551 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4552 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4553 return T;
4554}
4555
Douglas Gregor577f75a2009-08-04 16:50:30 +00004556template<typename Derived>
4557QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004558 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004559 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004560 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004561}
4562
Mike Stump1eb44332009-09-09 15:08:12 +00004563template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004564QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004565 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004566 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004567 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004568
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004569 // Substitute into the replacement type, which itself might involve something
4570 // that needs to be transformed. This only tends to occur with default
4571 // template arguments of template template parameters.
4572 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4573 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4574 if (Replacement.isNull())
4575 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004576
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004577 // Always canonicalize the replacement type.
4578 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4579 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004580 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004581 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004582
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004583 // Propagate type-source information.
4584 SubstTemplateTypeParmTypeLoc NewTL
4585 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4586 NewTL.setNameLoc(TL.getNameLoc());
4587 return Result;
4588
John McCall49a832b2009-10-18 09:09:24 +00004589}
4590
4591template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004592QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4593 TypeLocBuilder &TLB,
4594 SubstTemplateTypeParmPackTypeLoc TL) {
4595 return TransformTypeSpecType(TLB, TL);
4596}
4597
4598template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004599QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004600 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004601 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004602 const TemplateSpecializationType *T = TL.getTypePtr();
4603
Douglas Gregor1d752d72011-03-02 18:46:51 +00004604 // The nested-name-specifier never matters in a TemplateSpecializationType,
4605 // because we can't have a dependent nested-name-specifier anyway.
4606 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004607 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004608 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4609 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004610 if (Template.isNull())
4611 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004612
John McCall43fed0d2010-11-12 08:19:04 +00004613 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4614}
4615
Eli Friedmanb001de72011-10-06 23:00:33 +00004616template<typename Derived>
4617QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4618 AtomicTypeLoc TL) {
4619 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4620 if (ValueType.isNull())
4621 return QualType();
4622
4623 QualType Result = TL.getType();
4624 if (getDerived().AlwaysRebuild() ||
4625 ValueType != TL.getValueLoc().getType()) {
4626 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4627 if (Result.isNull())
4628 return QualType();
4629 }
4630
4631 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4632 NewTL.setKWLoc(TL.getKWLoc());
4633 NewTL.setLParenLoc(TL.getLParenLoc());
4634 NewTL.setRParenLoc(TL.getRParenLoc());
4635
4636 return Result;
4637}
4638
Chad Rosier4a9d7952012-08-08 18:46:20 +00004639 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004640 /// container that provides a \c getArgLoc() member function.
4641 ///
4642 /// This iterator is intended to be used with the iterator form of
4643 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4644 template<typename ArgLocContainer>
4645 class TemplateArgumentLocContainerIterator {
4646 ArgLocContainer *Container;
4647 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004648
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004649 public:
4650 typedef TemplateArgumentLoc value_type;
4651 typedef TemplateArgumentLoc reference;
4652 typedef int difference_type;
4653 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004654
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004655 class pointer {
4656 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004657
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004658 public:
4659 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004660
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004661 const TemplateArgumentLoc *operator->() const {
4662 return &Arg;
4663 }
4664 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004665
4666
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004667 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004668
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004669 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4670 unsigned Index)
4671 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004672
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004673 TemplateArgumentLocContainerIterator &operator++() {
4674 ++Index;
4675 return *this;
4676 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004677
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004678 TemplateArgumentLocContainerIterator operator++(int) {
4679 TemplateArgumentLocContainerIterator Old(*this);
4680 ++(*this);
4681 return Old;
4682 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004683
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004684 TemplateArgumentLoc operator*() const {
4685 return Container->getArgLoc(Index);
4686 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004687
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004688 pointer operator->() const {
4689 return pointer(Container->getArgLoc(Index));
4690 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004691
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004692 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004693 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004694 return X.Container == Y.Container && X.Index == Y.Index;
4695 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004696
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004697 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004698 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004699 return !(X == Y);
4700 }
4701 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004702
4703
John McCall43fed0d2010-11-12 08:19:04 +00004704template <typename Derived>
4705QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4706 TypeLocBuilder &TLB,
4707 TemplateSpecializationTypeLoc TL,
4708 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004709 TemplateArgumentListInfo NewTemplateArgs;
4710 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4711 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004712 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4713 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004714 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004715 ArgIterator(TL, TL.getNumArgs()),
4716 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004717 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004718
John McCall833ca992009-10-29 08:12:44 +00004719 // FIXME: maybe don't rebuild if all the template arguments are the same.
4720
4721 QualType Result =
4722 getDerived().RebuildTemplateSpecializationType(Template,
4723 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004724 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004725
4726 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004727 // Specializations of template template parameters are represented as
4728 // TemplateSpecializationTypes, and substitution of type alias templates
4729 // within a dependent context can transform them into
4730 // DependentTemplateSpecializationTypes.
4731 if (isa<DependentTemplateSpecializationType>(Result)) {
4732 DependentTemplateSpecializationTypeLoc NewTL
4733 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004734 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004735 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004736 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004737 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004738 NewTL.setLAngleLoc(TL.getLAngleLoc());
4739 NewTL.setRAngleLoc(TL.getRAngleLoc());
4740 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4741 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4742 return Result;
4743 }
4744
John McCall833ca992009-10-29 08:12:44 +00004745 TemplateSpecializationTypeLoc NewTL
4746 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004747 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004748 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4749 NewTL.setLAngleLoc(TL.getLAngleLoc());
4750 NewTL.setRAngleLoc(TL.getRAngleLoc());
4751 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4752 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004753 }
Mike Stump1eb44332009-09-09 15:08:12 +00004754
John McCall833ca992009-10-29 08:12:44 +00004755 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004756}
Mike Stump1eb44332009-09-09 15:08:12 +00004757
Douglas Gregora88f09f2011-02-28 17:23:35 +00004758template <typename Derived>
4759QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4760 TypeLocBuilder &TLB,
4761 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004762 TemplateName Template,
4763 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004764 TemplateArgumentListInfo NewTemplateArgs;
4765 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4766 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4767 typedef TemplateArgumentLocContainerIterator<
4768 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004769 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004770 ArgIterator(TL, TL.getNumArgs()),
4771 NewTemplateArgs))
4772 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004773
Douglas Gregora88f09f2011-02-28 17:23:35 +00004774 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004775
Douglas Gregora88f09f2011-02-28 17:23:35 +00004776 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4777 QualType Result
4778 = getSema().Context.getDependentTemplateSpecializationType(
4779 TL.getTypePtr()->getKeyword(),
4780 DTN->getQualifier(),
4781 DTN->getIdentifier(),
4782 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004783
Douglas Gregora88f09f2011-02-28 17:23:35 +00004784 DependentTemplateSpecializationTypeLoc NewTL
4785 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004786 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004787 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004788 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004789 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004790 NewTL.setLAngleLoc(TL.getLAngleLoc());
4791 NewTL.setRAngleLoc(TL.getRAngleLoc());
4792 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4793 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4794 return Result;
4795 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004796
4797 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004798 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004799 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004800 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004801
Douglas Gregora88f09f2011-02-28 17:23:35 +00004802 if (!Result.isNull()) {
4803 /// FIXME: Wrap this in an elaborated-type-specifier?
4804 TemplateSpecializationTypeLoc NewTL
4805 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004806 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004807 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004808 NewTL.setLAngleLoc(TL.getLAngleLoc());
4809 NewTL.setRAngleLoc(TL.getRAngleLoc());
4810 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4811 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4812 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004813
Douglas Gregora88f09f2011-02-28 17:23:35 +00004814 return Result;
4815}
4816
Mike Stump1eb44332009-09-09 15:08:12 +00004817template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004818QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004819TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004820 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004821 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004822
Douglas Gregor9e876872011-03-01 18:12:44 +00004823 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004824 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004825 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004826 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004827 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4828 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004829 return QualType();
4830 }
Mike Stump1eb44332009-09-09 15:08:12 +00004831
John McCall43fed0d2010-11-12 08:19:04 +00004832 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4833 if (NamedT.isNull())
4834 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004835
Richard Smith3e4c6c42011-05-05 21:57:07 +00004836 // C++0x [dcl.type.elab]p2:
4837 // If the identifier resolves to a typedef-name or the simple-template-id
4838 // resolves to an alias template specialization, the
4839 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004840 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4841 if (const TemplateSpecializationType *TST =
4842 NamedT->getAs<TemplateSpecializationType>()) {
4843 TemplateName Template = TST->getTemplateName();
4844 if (TypeAliasTemplateDecl *TAT =
4845 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4846 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4847 diag::err_tag_reference_non_tag) << 4;
4848 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4849 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004850 }
4851 }
4852
John McCalla2becad2009-10-21 00:40:46 +00004853 QualType Result = TL.getType();
4854 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004855 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004856 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004857 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004858 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004859 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004860 if (Result.isNull())
4861 return QualType();
4862 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004863
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004864 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004865 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004866 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004867 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004868}
Mike Stump1eb44332009-09-09 15:08:12 +00004869
4870template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004871QualType TreeTransform<Derived>::TransformAttributedType(
4872 TypeLocBuilder &TLB,
4873 AttributedTypeLoc TL) {
4874 const AttributedType *oldType = TL.getTypePtr();
4875 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4876 if (modifiedType.isNull())
4877 return QualType();
4878
4879 QualType result = TL.getType();
4880
4881 // FIXME: dependent operand expressions?
4882 if (getDerived().AlwaysRebuild() ||
4883 modifiedType != oldType->getModifiedType()) {
4884 // TODO: this is really lame; we should really be rebuilding the
4885 // equivalent type from first principles.
4886 QualType equivalentType
4887 = getDerived().TransformType(oldType->getEquivalentType());
4888 if (equivalentType.isNull())
4889 return QualType();
4890 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4891 modifiedType,
4892 equivalentType);
4893 }
4894
4895 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4896 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4897 if (TL.hasAttrOperand())
4898 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4899 if (TL.hasAttrExprOperand())
4900 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4901 else if (TL.hasAttrEnumOperand())
4902 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4903
4904 return result;
4905}
4906
4907template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004908QualType
4909TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4910 ParenTypeLoc TL) {
4911 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4912 if (Inner.isNull())
4913 return QualType();
4914
4915 QualType Result = TL.getType();
4916 if (getDerived().AlwaysRebuild() ||
4917 Inner != TL.getInnerLoc().getType()) {
4918 Result = getDerived().RebuildParenType(Inner);
4919 if (Result.isNull())
4920 return QualType();
4921 }
4922
4923 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4924 NewTL.setLParenLoc(TL.getLParenLoc());
4925 NewTL.setRParenLoc(TL.getRParenLoc());
4926 return Result;
4927}
4928
4929template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004930QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004931 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004932 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004933
Douglas Gregor2494dd02011-03-01 01:34:45 +00004934 NestedNameSpecifierLoc QualifierLoc
4935 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4936 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004937 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004938
John McCall33500952010-06-11 00:33:02 +00004939 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004940 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004941 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004942 QualifierLoc,
4943 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004944 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004945 if (Result.isNull())
4946 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004947
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004948 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4949 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004950 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4951
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004952 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004953 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004954 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004955 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004956 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004957 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004958 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004959 NewTL.setNameLoc(TL.getNameLoc());
4960 }
John McCalla2becad2009-10-21 00:40:46 +00004961 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004962}
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregor577f75a2009-08-04 16:50:30 +00004964template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004965QualType TreeTransform<Derived>::
4966 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004967 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004968 NestedNameSpecifierLoc QualifierLoc;
4969 if (TL.getQualifierLoc()) {
4970 QualifierLoc
4971 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4972 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004973 return QualType();
4974 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004975
John McCall43fed0d2010-11-12 08:19:04 +00004976 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004977 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004978}
4979
4980template<typename Derived>
4981QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004982TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4983 DependentTemplateSpecializationTypeLoc TL,
4984 NestedNameSpecifierLoc QualifierLoc) {
4985 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004986
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004987 TemplateArgumentListInfo NewTemplateArgs;
4988 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4989 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004990
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004991 typedef TemplateArgumentLocContainerIterator<
4992 DependentTemplateSpecializationTypeLoc> ArgIterator;
4993 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4994 ArgIterator(TL, TL.getNumArgs()),
4995 NewTemplateArgs))
4996 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004997
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998 QualType Result
4999 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5000 QualifierLoc,
5001 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005002 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005003 NewTemplateArgs);
5004 if (Result.isNull())
5005 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005006
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005007 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5008 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005009
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005010 // Copy information relevant to the template specialization.
5011 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005012 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005013 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005014 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005015 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5016 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005017 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005018 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005019
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005020 // Copy information relevant to the elaborated type.
5021 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005022 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005023 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005024 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5025 DependentTemplateSpecializationTypeLoc SpecTL
5026 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005027 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005028 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005029 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005030 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005031 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5032 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005033 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005034 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005035 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005036 TemplateSpecializationTypeLoc SpecTL
5037 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005038 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005039 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005040 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5041 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005042 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005043 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005044 }
5045 return Result;
5046}
5047
5048template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005049QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5050 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005051 QualType Pattern
5052 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005053 if (Pattern.isNull())
5054 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005055
5056 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005057 if (getDerived().AlwaysRebuild() ||
5058 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005059 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005060 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005061 TL.getEllipsisLoc(),
5062 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005063 if (Result.isNull())
5064 return QualType();
5065 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005066
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005067 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5068 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5069 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005070}
5071
5072template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005073QualType
5074TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005075 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005076 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005077 TLB.pushFullCopy(TL);
5078 return TL.getType();
5079}
5080
5081template<typename Derived>
5082QualType
5083TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005084 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005085 // ObjCObjectType is never dependent.
5086 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005087 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005088}
Mike Stump1eb44332009-09-09 15:08:12 +00005089
5090template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005091QualType
5092TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005093 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005094 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005095 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005096 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005097}
5098
Douglas Gregor577f75a2009-08-04 16:50:30 +00005099//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005100// Statement transformation
5101//===----------------------------------------------------------------------===//
5102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005103StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005104TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005105 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005106}
5107
5108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005109StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005110TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5111 return getDerived().TransformCompoundStmt(S, false);
5112}
5113
5114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005115StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005116TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005118 Sema::CompoundScopeRAII CompoundScope(getSema());
5119
John McCall7114cba2010-08-27 19:56:05 +00005120 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005122 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5124 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005125 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005126 if (Result.isInvalid()) {
5127 // Immediately fail if this was a DeclStmt, since it's very
5128 // likely that this will cause problems for future statements.
5129 if (isa<DeclStmt>(*B))
5130 return StmtError();
5131
5132 // Otherwise, just keep processing substatements and fail later.
5133 SubStmtInvalid = true;
5134 continue;
5135 }
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5138 Statements.push_back(Result.takeAs<Stmt>());
5139 }
Mike Stump1eb44332009-09-09 15:08:12 +00005140
John McCall7114cba2010-08-27 19:56:05 +00005141 if (SubStmtInvalid)
5142 return StmtError();
5143
Douglas Gregor43959a92009-08-20 07:17:43 +00005144 if (!getDerived().AlwaysRebuild() &&
5145 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005146 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005147
5148 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005149 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 S->getRBracLoc(),
5151 IsStmtExpr);
5152}
Mike Stump1eb44332009-09-09 15:08:12 +00005153
Douglas Gregor43959a92009-08-20 07:17:43 +00005154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005155StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005156TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005157 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005158 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005159 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5160 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Eli Friedman264c1f82009-11-19 03:14:00 +00005162 // Transform the left-hand case value.
5163 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005164 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005165 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005166 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Eli Friedman264c1f82009-11-19 03:14:00 +00005168 // Transform the right-hand case value (for the GNU case-range extension).
5169 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005170 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005171 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005173 }
Mike Stump1eb44332009-09-09 15:08:12 +00005174
Douglas Gregor43959a92009-08-20 07:17:43 +00005175 // Build the case statement.
5176 // Case statements are always rebuilt so that they will attached to their
5177 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005178 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005179 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005181 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 S->getColonLoc());
5183 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005187 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005188 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005189 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005190
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005192 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005193}
5194
5195template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005196StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005197TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005198 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005199 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005201 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregor43959a92009-08-20 07:17:43 +00005203 // Default statements are always rebuilt
5204 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005205 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005206}
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Douglas Gregor43959a92009-08-20 07:17:43 +00005208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005209StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005210TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005213 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005214
Chris Lattner57ad3782011-02-17 20:34:02 +00005215 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5216 S->getDecl());
5217 if (!LD)
5218 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005219
5220
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005222 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005223 cast<LabelDecl>(LD), SourceLocation(),
5224 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005225}
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005228StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005229TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5230 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5231 if (SubStmt.isInvalid())
5232 return StmtError();
5233
5234 // TODO: transform attributes
5235 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5236 return S;
5237
5238 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5239 S->getAttrs(),
5240 SubStmt.get());
5241}
5242
5243template<typename Derived>
5244StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005245TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005246 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005247 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005248 VarDecl *ConditionVar = 0;
5249 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005250 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005251 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005252 getDerived().TransformDefinition(
5253 S->getConditionVariable()->getLocation(),
5254 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005255 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005257 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005258 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005259
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005260 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005261 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005262
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005263 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005264 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005265 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005266 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005267 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005269
John McCall9ae2f072010-08-23 23:25:46 +00005270 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005271 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005273
John McCall9ae2f072010-08-23 23:25:46 +00005274 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5275 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005276 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005277
Douglas Gregor43959a92009-08-20 07:17:43 +00005278 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005279 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005284 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005285 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005286 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005289 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005290 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005291 Then.get() == S->getThen() &&
5292 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005293 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005294
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005295 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005296 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005297 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005298}
5299
5300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005301StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005302TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005304 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005305 VarDecl *ConditionVar = 0;
5306 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005307 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005308 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005309 getDerived().TransformDefinition(
5310 S->getConditionVariable()->getLocation(),
5311 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005312 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005314 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005315 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005316
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005317 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005318 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005319 }
Mike Stump1eb44332009-09-09 15:08:12 +00005320
Douglas Gregor43959a92009-08-20 07:17:43 +00005321 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005322 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005323 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005324 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005325 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005326 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregor43959a92009-08-20 07:17:43 +00005328 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005329 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005330 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005331 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005332
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005334 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5335 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336}
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor43959a92009-08-20 07:17:43 +00005338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005339StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005340TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005341 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005342 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005343 VarDecl *ConditionVar = 0;
5344 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005345 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005346 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005347 getDerived().TransformDefinition(
5348 S->getConditionVariable()->getLocation(),
5349 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005350 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005351 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005352 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005353 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005354
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005355 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005356 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005357
5358 if (S->getCond()) {
5359 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005360 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005361 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005362 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005364 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005365 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005366 }
Mike Stump1eb44332009-09-09 15:08:12 +00005367
John McCall9ae2f072010-08-23 23:25:46 +00005368 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5369 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005370 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005371
Douglas Gregor43959a92009-08-20 07:17:43 +00005372 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005373 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005376
Douglas Gregor43959a92009-08-20 07:17:43 +00005377 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005378 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005379 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005380 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005381 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005383 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005384 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005385}
Mike Stump1eb44332009-09-09 15:08:12 +00005386
Douglas Gregor43959a92009-08-20 07:17:43 +00005387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005388StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005389TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005390 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005391 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005393 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005394
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005395 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005396 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005397 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005398 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005399
Douglas Gregor43959a92009-08-20 07:17:43 +00005400 if (!getDerived().AlwaysRebuild() &&
5401 Cond.get() == S->getCond() &&
5402 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005403 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005404
John McCall9ae2f072010-08-23 23:25:46 +00005405 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5406 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005407 S->getRParenLoc());
5408}
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005412TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005413 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005414 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005415 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005419 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005420 VarDecl *ConditionVar = 0;
5421 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005422 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005423 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005424 getDerived().TransformDefinition(
5425 S->getConditionVariable()->getLocation(),
5426 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005427 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005428 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005429 } else {
5430 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005431
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005432 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005434
5435 if (S->getCond()) {
5436 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005437 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005438 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005439 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005441
John McCall9ae2f072010-08-23 23:25:46 +00005442 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005443 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005444 }
Mike Stump1eb44332009-09-09 15:08:12 +00005445
Chad Rosier4a9d7952012-08-08 18:46:20 +00005446 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005447 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005448 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005449
Douglas Gregor43959a92009-08-20 07:17:43 +00005450 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005451 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005452 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005453 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005454
Richard Smith41956372013-01-14 22:39:08 +00005455 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCall9ae2f072010-08-23 23:25:46 +00005456 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005457 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005460 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005461 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005462 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005463
Douglas Gregor43959a92009-08-20 07:17:43 +00005464 if (!getDerived().AlwaysRebuild() &&
5465 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005466 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005467 Inc.get() == S->getInc() &&
5468 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005470
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005472 Init.get(), FullCond, ConditionVar,
5473 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005474}
5475
5476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005479 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5480 S->getLabel());
5481 if (!LD)
5482 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005483
Douglas Gregor43959a92009-08-20 07:17:43 +00005484 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005485 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005486 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005487}
5488
5489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005490StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005491TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005492 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005493 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005494 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005495 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005496
Douglas Gregor43959a92009-08-20 07:17:43 +00005497 if (!getDerived().AlwaysRebuild() &&
5498 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005499 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005500
5501 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005502 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005503}
5504
5505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005506StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005507TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005508 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005509}
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregor43959a92009-08-20 07:17:43 +00005511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005513TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005514 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005515}
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregor43959a92009-08-20 07:17:43 +00005517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005519TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005520 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005521 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005522 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005523
Mike Stump1eb44332009-09-09 15:08:12 +00005524 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005526 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005527}
Mike Stump1eb44332009-09-09 15:08:12 +00005528
Douglas Gregor43959a92009-08-20 07:17:43 +00005529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005530StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005531TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005532 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005533 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005534 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5535 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005536 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5537 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005538 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005539 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregor43959a92009-08-20 07:17:43 +00005541 if (Transformed != *D)
5542 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005543
Douglas Gregor43959a92009-08-20 07:17:43 +00005544 Decls.push_back(Transformed);
5545 }
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregor43959a92009-08-20 07:17:43 +00005547 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005548 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005549
5550 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005551 S->getStartLoc(), S->getEndLoc());
5552}
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregor43959a92009-08-20 07:17:43 +00005554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005555StmtResult
Chad Rosierdf5faf52012-08-25 00:11:56 +00005556TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005557
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005558 SmallVector<Expr*, 8> Constraints;
5559 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005560 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005561
John McCall60d7b3a2010-08-24 06:29:42 +00005562 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005563 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005564
5565 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 // Go through the outputs.
5568 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005569 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005570
Anders Carlsson703e3942010-01-24 05:50:09 +00005571 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005572 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005573
Anders Carlsson703e3942010-01-24 05:50:09 +00005574 // Transform the output expr.
5575 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005576 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005577 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005578 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005579
Anders Carlsson703e3942010-01-24 05:50:09 +00005580 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005581
John McCall9ae2f072010-08-23 23:25:46 +00005582 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005583 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005584
Anders Carlsson703e3942010-01-24 05:50:09 +00005585 // Go through the inputs.
5586 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005587 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005588
Anders Carlsson703e3942010-01-24 05:50:09 +00005589 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005590 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005591
Anders Carlsson703e3942010-01-24 05:50:09 +00005592 // Transform the input expr.
5593 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005594 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005595 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005596 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005597
Anders Carlsson703e3942010-01-24 05:50:09 +00005598 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005599
John McCall9ae2f072010-08-23 23:25:46 +00005600 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005601 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005602
Anders Carlsson703e3942010-01-24 05:50:09 +00005603 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005604 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005605
5606 // Go through the clobbers.
5607 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosier5c7f5942012-08-27 23:28:41 +00005608 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005609
5610 // No need to transform the asm string literal.
5611 AsmString = SemaRef.Owned(S->getAsmString());
Chad Rosierdf5faf52012-08-25 00:11:56 +00005612 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
5613 S->isVolatile(), S->getNumOutputs(),
5614 S->getNumInputs(), Names.data(),
5615 Constraints, Exprs, AsmString.get(),
5616 Clobbers, S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005617}
5618
Chad Rosier8cd64b42012-06-11 20:47:18 +00005619template<typename Derived>
5620StmtResult
5621TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005622 ArrayRef<Token> AsmToks =
5623 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005624
Chad Rosier7bd092b2012-08-15 16:53:30 +00005625 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5626 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005627}
Douglas Gregor43959a92009-08-20 07:17:43 +00005628
5629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005630StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005631TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005632 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005633 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005635 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005636
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005637 // Transform the @catch statements (if present).
5638 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005639 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005640 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005641 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005642 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005643 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005644 if (Catch.get() != S->getCatchStmt(I))
5645 AnyCatchChanged = true;
5646 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005647 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005648
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005649 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005650 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005651 if (S->getFinallyStmt()) {
5652 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5653 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005654 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005655 }
5656
5657 // If nothing changed, just retain this statement.
5658 if (!getDerived().AlwaysRebuild() &&
5659 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005660 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005661 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005662 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005663
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005664 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005665 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005666 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005667}
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregor43959a92009-08-20 07:17:43 +00005669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005670StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005671TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005672 // Transform the @catch parameter, if there is one.
5673 VarDecl *Var = 0;
5674 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5675 TypeSourceInfo *TSInfo = 0;
5676 if (FromVar->getTypeSourceInfo()) {
5677 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5678 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005679 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005680 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005681
Douglas Gregorbe270a02010-04-26 17:57:08 +00005682 QualType T;
5683 if (TSInfo)
5684 T = TSInfo->getType();
5685 else {
5686 T = getDerived().TransformType(FromVar->getType());
5687 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005688 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005689 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005690
Douglas Gregorbe270a02010-04-26 17:57:08 +00005691 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5692 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005693 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005694 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005695
John McCall60d7b3a2010-08-24 06:29:42 +00005696 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005697 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005698 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005699
5700 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005701 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005702 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005703}
Mike Stump1eb44332009-09-09 15:08:12 +00005704
Douglas Gregor43959a92009-08-20 07:17:43 +00005705template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005706StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005707TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005708 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005709 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005710 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005711 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005712
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005713 // If nothing changed, just retain this statement.
5714 if (!getDerived().AlwaysRebuild() &&
5715 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005716 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005717
5718 // Build a new statement.
5719 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005720 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005721}
Mike Stump1eb44332009-09-09 15:08:12 +00005722
Douglas Gregor43959a92009-08-20 07:17:43 +00005723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005724StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005725TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005726 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005727 if (S->getThrowExpr()) {
5728 Operand = getDerived().TransformExpr(S->getThrowExpr());
5729 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005730 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005731 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005732
Douglas Gregord1377b22010-04-22 21:44:01 +00005733 if (!getDerived().AlwaysRebuild() &&
5734 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005735 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005736
John McCall9ae2f072010-08-23 23:25:46 +00005737 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005738}
Mike Stump1eb44332009-09-09 15:08:12 +00005739
Douglas Gregor43959a92009-08-20 07:17:43 +00005740template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005741StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005742TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005743 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005744 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005745 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005746 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005747 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005748 Object =
5749 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5750 Object.get());
5751 if (Object.isInvalid())
5752 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005753
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005754 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005755 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005756 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005757 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005758
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005759 // If nothing change, just retain the current statement.
5760 if (!getDerived().AlwaysRebuild() &&
5761 Object.get() == S->getSynchExpr() &&
5762 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005763 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005764
5765 // Build a new statement.
5766 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005767 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005768}
5769
5770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005771StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005772TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5773 ObjCAutoreleasePoolStmt *S) {
5774 // Transform the body.
5775 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5776 if (Body.isInvalid())
5777 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005778
John McCallf85e1932011-06-15 23:02:42 +00005779 // If nothing changed, just retain this statement.
5780 if (!getDerived().AlwaysRebuild() &&
5781 Body.get() == S->getSubStmt())
5782 return SemaRef.Owned(S);
5783
5784 // Build a new statement.
5785 return getDerived().RebuildObjCAutoreleasePoolStmt(
5786 S->getAtLoc(), Body.get());
5787}
5788
5789template<typename Derived>
5790StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005791TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005792 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005794 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005795 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005796 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005797
Douglas Gregorc3203e72010-04-22 23:10:45 +00005798 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005799 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005800 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005801 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005802
Douglas Gregorc3203e72010-04-22 23:10:45 +00005803 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005804 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005805 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005806 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005807
Douglas Gregorc3203e72010-04-22 23:10:45 +00005808 // If nothing changed, just retain this statement.
5809 if (!getDerived().AlwaysRebuild() &&
5810 Element.get() == S->getElement() &&
5811 Collection.get() == S->getCollection() &&
5812 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005813 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005814
Douglas Gregorc3203e72010-04-22 23:10:45 +00005815 // Build a new statement.
5816 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005817 Element.get(),
5818 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005819 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005820 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005821}
5822
5823
5824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005825StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005826TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5827 // Transform the exception declaration, if any.
5828 VarDecl *Var = 0;
5829 if (S->getExceptionDecl()) {
5830 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005831 TypeSourceInfo *T = getDerived().TransformType(
5832 ExceptionDecl->getTypeSourceInfo());
5833 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005834 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005835
Douglas Gregor83cb9422010-09-09 17:09:21 +00005836 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005837 ExceptionDecl->getInnerLocStart(),
5838 ExceptionDecl->getLocation(),
5839 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005840 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005841 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005842 }
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor43959a92009-08-20 07:17:43 +00005844 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005845 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005846 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005847 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005848
Douglas Gregor43959a92009-08-20 07:17:43 +00005849 if (!getDerived().AlwaysRebuild() &&
5850 !Var &&
5851 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005852 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005853
5854 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5855 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005856 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005857}
Mike Stump1eb44332009-09-09 15:08:12 +00005858
Douglas Gregor43959a92009-08-20 07:17:43 +00005859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005860StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005861TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5862 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005863 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005864 = getDerived().TransformCompoundStmt(S->getTryBlock());
5865 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005866 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregor43959a92009-08-20 07:17:43 +00005868 // Transform the handlers.
5869 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005870 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005871 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005872 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005873 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5874 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005875 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregor43959a92009-08-20 07:17:43 +00005877 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5878 Handlers.push_back(Handler.takeAs<Stmt>());
5879 }
Mike Stump1eb44332009-09-09 15:08:12 +00005880
Douglas Gregor43959a92009-08-20 07:17:43 +00005881 if (!getDerived().AlwaysRebuild() &&
5882 TryBlock.get() == S->getTryBlock() &&
5883 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005884 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005885
John McCall9ae2f072010-08-23 23:25:46 +00005886 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005887 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005888}
Mike Stump1eb44332009-09-09 15:08:12 +00005889
Richard Smithad762fc2011-04-14 22:09:26 +00005890template<typename Derived>
5891StmtResult
5892TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5893 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5894 if (Range.isInvalid())
5895 return StmtError();
5896
5897 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5898 if (BeginEnd.isInvalid())
5899 return StmtError();
5900
5901 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5902 if (Cond.isInvalid())
5903 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005904 if (Cond.get())
5905 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5906 if (Cond.isInvalid())
5907 return StmtError();
5908 if (Cond.get())
5909 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005910
5911 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5912 if (Inc.isInvalid())
5913 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005914 if (Inc.get())
5915 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005916
5917 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5918 if (LoopVar.isInvalid())
5919 return StmtError();
5920
5921 StmtResult NewStmt = S;
5922 if (getDerived().AlwaysRebuild() ||
5923 Range.get() != S->getRangeStmt() ||
5924 BeginEnd.get() != S->getBeginEndStmt() ||
5925 Cond.get() != S->getCond() ||
5926 Inc.get() != S->getInc() ||
5927 LoopVar.get() != S->getLoopVarStmt())
5928 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5929 S->getColonLoc(), Range.get(),
5930 BeginEnd.get(), Cond.get(),
5931 Inc.get(), LoopVar.get(),
5932 S->getRParenLoc());
5933
5934 StmtResult Body = getDerived().TransformStmt(S->getBody());
5935 if (Body.isInvalid())
5936 return StmtError();
5937
5938 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5939 // it now so we have a new statement to attach the body to.
5940 if (Body.get() != S->getBody() && NewStmt.get() == S)
5941 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5942 S->getColonLoc(), Range.get(),
5943 BeginEnd.get(), Cond.get(),
5944 Inc.get(), LoopVar.get(),
5945 S->getRParenLoc());
5946
5947 if (NewStmt.get() == S)
5948 return SemaRef.Owned(S);
5949
5950 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5951}
5952
John Wiegley28bbe4b2011-04-28 01:08:34 +00005953template<typename Derived>
5954StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005955TreeTransform<Derived>::TransformMSDependentExistsStmt(
5956 MSDependentExistsStmt *S) {
5957 // Transform the nested-name-specifier, if any.
5958 NestedNameSpecifierLoc QualifierLoc;
5959 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005960 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005961 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5962 if (!QualifierLoc)
5963 return StmtError();
5964 }
5965
5966 // Transform the declaration name.
5967 DeclarationNameInfo NameInfo = S->getNameInfo();
5968 if (NameInfo.getName()) {
5969 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5970 if (!NameInfo.getName())
5971 return StmtError();
5972 }
5973
5974 // Check whether anything changed.
5975 if (!getDerived().AlwaysRebuild() &&
5976 QualifierLoc == S->getQualifierLoc() &&
5977 NameInfo.getName() == S->getNameInfo().getName())
5978 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005979
Douglas Gregorba0513d2011-10-25 01:33:02 +00005980 // Determine whether this name exists, if we can.
5981 CXXScopeSpec SS;
5982 SS.Adopt(QualifierLoc);
5983 bool Dependent = false;
5984 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5985 case Sema::IER_Exists:
5986 if (S->isIfExists())
5987 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005988
Douglas Gregorba0513d2011-10-25 01:33:02 +00005989 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5990
5991 case Sema::IER_DoesNotExist:
5992 if (S->isIfNotExists())
5993 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005994
Douglas Gregorba0513d2011-10-25 01:33:02 +00005995 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005996
Douglas Gregorba0513d2011-10-25 01:33:02 +00005997 case Sema::IER_Dependent:
5998 Dependent = true;
5999 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006000
Douglas Gregor65019ac2011-10-25 03:44:56 +00006001 case Sema::IER_Error:
6002 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00006003 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006004
Douglas Gregorba0513d2011-10-25 01:33:02 +00006005 // We need to continue with the instantiation, so do so now.
6006 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6007 if (SubStmt.isInvalid())
6008 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006009
Douglas Gregorba0513d2011-10-25 01:33:02 +00006010 // If we have resolved the name, just transform to the substatement.
6011 if (!Dependent)
6012 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006013
Douglas Gregorba0513d2011-10-25 01:33:02 +00006014 // The name is still dependent, so build a dependent expression again.
6015 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6016 S->isIfExists(),
6017 QualifierLoc,
6018 NameInfo,
6019 SubStmt.get());
6020}
6021
6022template<typename Derived>
6023StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006024TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6025 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6026 if(TryBlock.isInvalid()) return StmtError();
6027
6028 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6029 if(!getDerived().AlwaysRebuild() &&
6030 TryBlock.get() == S->getTryBlock() &&
6031 Handler.get() == S->getHandler())
6032 return SemaRef.Owned(S);
6033
6034 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6035 S->getTryLoc(),
6036 TryBlock.take(),
6037 Handler.take());
6038}
6039
6040template<typename Derived>
6041StmtResult
6042TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6043 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6044 if(Block.isInvalid()) return StmtError();
6045
6046 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6047 Block.take());
6048}
6049
6050template<typename Derived>
6051StmtResult
6052TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6053 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6054 if(FilterExpr.isInvalid()) return StmtError();
6055
6056 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6057 if(Block.isInvalid()) return StmtError();
6058
6059 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6060 FilterExpr.take(),
6061 Block.take());
6062}
6063
6064template<typename Derived>
6065StmtResult
6066TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6067 if(isa<SEHFinallyStmt>(Handler))
6068 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6069 else
6070 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6071}
6072
Douglas Gregor43959a92009-08-20 07:17:43 +00006073//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074// Expression transformation
6075//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006076template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006077ExprResult
John McCall454feb92009-12-08 09:21:05 +00006078TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006079 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006080}
Mike Stump1eb44332009-09-09 15:08:12 +00006081
6082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006083ExprResult
John McCall454feb92009-12-08 09:21:05 +00006084TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006085 NestedNameSpecifierLoc QualifierLoc;
6086 if (E->getQualifierLoc()) {
6087 QualifierLoc
6088 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6089 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006091 }
John McCalldbd872f2009-12-08 09:08:17 +00006092
6093 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006094 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6095 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006098
John McCallec8045d2010-08-17 21:27:17 +00006099 DeclarationNameInfo NameInfo = E->getNameInfo();
6100 if (NameInfo.getName()) {
6101 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6102 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006103 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006104 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006105
6106 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006107 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006108 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006109 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006110 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006111
6112 // Mark it referenced in the new context regardless.
6113 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006114 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006115
John McCall3fa5cae2010-10-26 07:05:15 +00006116 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006117 }
John McCalldbd872f2009-12-08 09:08:17 +00006118
6119 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006120 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006121 TemplateArgs = &TransArgs;
6122 TransArgs.setLAngleLoc(E->getLAngleLoc());
6123 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006124 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6125 E->getNumTemplateArgs(),
6126 TransArgs))
6127 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006128 }
6129
Chad Rosier4a9d7952012-08-08 18:46:20 +00006130 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006131 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132}
Mike Stump1eb44332009-09-09 15:08:12 +00006133
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006135ExprResult
John McCall454feb92009-12-08 09:21:05 +00006136TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138}
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006141ExprResult
John McCall454feb92009-12-08 09:21:05 +00006142TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006143 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144}
Mike Stump1eb44332009-09-09 15:08:12 +00006145
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006147ExprResult
John McCall454feb92009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006149 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150}
Mike Stump1eb44332009-09-09 15:08:12 +00006151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006153ExprResult
John McCall454feb92009-12-08 09:21:05 +00006154TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006155 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156}
Mike Stump1eb44332009-09-09 15:08:12 +00006157
Douglas Gregorb98b1992009-08-11 05:31:07 +00006158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006159ExprResult
John McCall454feb92009-12-08 09:21:05 +00006160TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006161 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006162}
6163
6164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006165ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006166TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6167 return SemaRef.MaybeBindToTemporary(E);
6168}
6169
6170template<typename Derived>
6171ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006172TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6173 ExprResult ControllingExpr =
6174 getDerived().TransformExpr(E->getControllingExpr());
6175 if (ControllingExpr.isInvalid())
6176 return ExprError();
6177
Chris Lattner686775d2011-07-20 06:58:45 +00006178 SmallVector<Expr *, 4> AssocExprs;
6179 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006180 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6181 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6182 if (TS) {
6183 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6184 if (!AssocType)
6185 return ExprError();
6186 AssocTypes.push_back(AssocType);
6187 } else {
6188 AssocTypes.push_back(0);
6189 }
6190
6191 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6192 if (AssocExpr.isInvalid())
6193 return ExprError();
6194 AssocExprs.push_back(AssocExpr.release());
6195 }
6196
6197 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6198 E->getDefaultLoc(),
6199 E->getRParenLoc(),
6200 ControllingExpr.release(),
6201 AssocTypes.data(),
6202 AssocExprs.data(),
6203 E->getNumAssocs());
6204}
6205
6206template<typename Derived>
6207ExprResult
John McCall454feb92009-12-08 09:21:05 +00006208TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006209 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006212
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006214 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006215
John McCall9ae2f072010-08-23 23:25:46 +00006216 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 E->getRParen());
6218}
6219
Richard Smithefeeccf2012-10-21 03:28:35 +00006220/// \brief The operand of a unary address-of operator has special rules: it's
6221/// allowed to refer to a non-static member of a class even if there's no 'this'
6222/// object available.
6223template<typename Derived>
6224ExprResult
6225TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
6226 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
6227 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true);
6228 else
6229 return getDerived().TransformExpr(E);
6230}
6231
Mike Stump1eb44332009-09-09 15:08:12 +00006232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
John McCall454feb92009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00006235 ExprResult SubExpr = TransformAddressOfOperand(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006237 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006238
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006240 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006241
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6243 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006244 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245}
Mike Stump1eb44332009-09-09 15:08:12 +00006246
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006248ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006249TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6250 // Transform the type.
6251 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6252 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006253 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006254
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006255 // Transform all of the components into components similar to what the
6256 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006257 // FIXME: It would be slightly more efficient in the non-dependent case to
6258 // just map FieldDecls, rather than requiring the rebuilder to look for
6259 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006260 // template code that we don't care.
6261 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006262 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006263 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006264 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006265 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6266 const Node &ON = E->getComponent(I);
6267 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006268 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006269 Comp.LocStart = ON.getSourceRange().getBegin();
6270 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 switch (ON.getKind()) {
6272 case Node::Array: {
6273 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006274 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006275 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006276 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006277
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006278 ExprChanged = ExprChanged || Index.get() != FromIndex;
6279 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006280 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006281 break;
6282 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006283
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006284 case Node::Field:
6285 case Node::Identifier:
6286 Comp.isBrackets = false;
6287 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006288 if (!Comp.U.IdentInfo)
6289 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006290
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006291 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006292
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006293 case Node::Base:
6294 // Will be recomputed during the rebuild.
6295 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006296 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006297
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006298 Components.push_back(Comp);
6299 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006300
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006301 // If nothing changed, retain the existing expression.
6302 if (!getDerived().AlwaysRebuild() &&
6303 Type == E->getTypeSourceInfo() &&
6304 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006306
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006307 // Build a new offsetof expression.
6308 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6309 Components.data(), Components.size(),
6310 E->getRParenLoc());
6311}
6312
6313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006314ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006315TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6316 assert(getDerived().AlreadyTransformed(E->getType()) &&
6317 "opaque value expression requires transformation");
6318 return SemaRef.Owned(E);
6319}
6320
6321template<typename Derived>
6322ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006323TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006324 // Rebuild the syntactic form. The original syntactic form has
6325 // opaque-value expressions in it, so strip those away and rebuild
6326 // the result. This is a really awful way of doing this, but the
6327 // better solution (rebuilding the semantic expressions and
6328 // rebinding OVEs as necessary) doesn't work; we'd need
6329 // TreeTransform to not strip away implicit conversions.
6330 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6331 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006332 if (result.isInvalid()) return ExprError();
6333
6334 // If that gives us a pseudo-object result back, the pseudo-object
6335 // expression must have been an lvalue-to-rvalue conversion which we
6336 // should reapply.
6337 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6338 result = SemaRef.checkPseudoObjectRValue(result.take());
6339
6340 return result;
6341}
6342
6343template<typename Derived>
6344ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006345TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6346 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006348 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006349
John McCalla93c9342009-12-07 02:54:59 +00006350 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006351 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006353
John McCall5ab75172009-11-04 07:28:41 +00006354 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006355 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006356
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006357 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6358 E->getKind(),
6359 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 }
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006362 // C++0x [expr.sizeof]p1:
6363 // The operand is either an expression, which is an unevaluated operand
6364 // [...]
Eli Friedman80bfa3d2012-09-26 04:34:21 +00006365 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
6366 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00006367
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006368 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6369 if (SubExpr.isInvalid())
6370 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006372 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6373 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006374
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006375 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6376 E->getOperatorLoc(),
6377 E->getKind(),
6378 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379}
Mike Stump1eb44332009-09-09 15:08:12 +00006380
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006382ExprResult
John McCall454feb92009-12-08 09:21:05 +00006383TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006384 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006387
John McCall60d7b3a2010-08-24 06:29:42 +00006388 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006389 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006390 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006391
6392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (!getDerived().AlwaysRebuild() &&
6394 LHS.get() == E->getLHS() &&
6395 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006397
John McCall9ae2f072010-08-23 23:25:46 +00006398 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006400 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 E->getRBracketLoc());
6402}
Mike Stump1eb44332009-09-09 15:08:12 +00006403
6404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006405ExprResult
John McCall454feb92009-12-08 09:21:05 +00006406TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006408 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006410 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411
6412 // Transform arguments.
6413 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006414 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006415 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006416 &ArgChanged))
6417 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006418
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 if (!getDerived().AlwaysRebuild() &&
6420 Callee.get() == E->getCallee() &&
6421 !ArgChanged)
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +00006422 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006425 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006427 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006428 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429 E->getRParenLoc());
6430}
Mike Stump1eb44332009-09-09 15:08:12 +00006431
6432template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006433ExprResult
John McCall454feb92009-12-08 09:21:05 +00006434TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006435 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006438
Douglas Gregor40d96a62011-02-28 21:54:11 +00006439 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006440 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006441 QualifierLoc
6442 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006443
Douglas Gregor40d96a62011-02-28 21:54:11 +00006444 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006445 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006446 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006447 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Eli Friedmanf595cc42009-12-04 06:40:45 +00006449 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006450 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6451 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006453 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006454
John McCall6bb80172010-03-30 21:47:33 +00006455 NamedDecl *FoundDecl = E->getFoundDecl();
6456 if (FoundDecl == E->getMemberDecl()) {
6457 FoundDecl = Member;
6458 } else {
6459 FoundDecl = cast_or_null<NamedDecl>(
6460 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6461 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006462 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006463 }
6464
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 if (!getDerived().AlwaysRebuild() &&
6466 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006467 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006468 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006469 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006470 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006471
Anders Carlsson1f240322009-12-22 05:24:09 +00006472 // Mark it referenced in the new context regardless.
6473 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006474 SemaRef.MarkMemberReferenced(E);
6475
John McCall3fa5cae2010-10-26 07:05:15 +00006476 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006477 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478
John McCalld5532b62009-11-23 01:53:49 +00006479 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006480 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006481 TransArgs.setLAngleLoc(E->getLAngleLoc());
6482 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006483 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6484 E->getNumTemplateArgs(),
6485 TransArgs))
6486 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006487 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 // FIXME: Bogus source location for the operator
6490 SourceLocation FakeOperatorLoc
6491 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6492
John McCallc2233c52010-01-15 08:34:02 +00006493 // FIXME: to do this check properly, we will need to preserve the
6494 // first-qualifier-in-scope here, just in case we had a dependent
6495 // base (and therefore couldn't do the check) and a
6496 // nested-name-qualifier (and therefore could do the lookup).
6497 NamedDecl *FirstQualifierInScope = 0;
6498
John McCall9ae2f072010-08-23 23:25:46 +00006499 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006501 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006502 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006503 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006504 Member,
John McCall6bb80172010-03-30 21:47:33 +00006505 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006506 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006507 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006508 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509}
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006512ExprResult
John McCall454feb92009-12-08 09:21:05 +00006513TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006514 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006517
John McCall60d7b3a2010-08-24 06:29:42 +00006518 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006520 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 if (!getDerived().AlwaysRebuild() &&
6523 LHS.get() == E->getLHS() &&
6524 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006525 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006526
Lang Hamesbe9af122012-10-02 04:45:10 +00006527 Sema::FPContractStateRAII FPContractState(getSema());
6528 getSema().FPFeatures.fp_contract = E->isFPContractable();
6529
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006531 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532}
6533
Mike Stump1eb44332009-09-09 15:08:12 +00006534template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006535ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006537 CompoundAssignOperator *E) {
6538 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539}
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006542ExprResult TreeTransform<Derived>::
6543TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6544 // Just rebuild the common and RHS expressions and see whether we
6545 // get any changes.
6546
6547 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6548 if (commonExpr.isInvalid())
6549 return ExprError();
6550
6551 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6552 if (rhs.isInvalid())
6553 return ExprError();
6554
6555 if (!getDerived().AlwaysRebuild() &&
6556 commonExpr.get() == e->getCommon() &&
6557 rhs.get() == e->getFalseExpr())
6558 return SemaRef.Owned(e);
6559
6560 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6561 e->getQuestionLoc(),
6562 0,
6563 e->getColonLoc(),
6564 rhs.get());
6565}
6566
6567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006568ExprResult
John McCall454feb92009-12-08 09:21:05 +00006569TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006570 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006576 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006577
John McCall60d7b3a2010-08-24 06:29:42 +00006578 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006581
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582 if (!getDerived().AlwaysRebuild() &&
6583 Cond.get() == E->getCond() &&
6584 LHS.get() == E->getLHS() &&
6585 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006586 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006587
John McCall9ae2f072010-08-23 23:25:46 +00006588 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006589 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006590 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006591 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006592 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593}
Mike Stump1eb44332009-09-09 15:08:12 +00006594
6595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006596ExprResult
John McCall454feb92009-12-08 09:21:05 +00006597TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006598 // Implicit casts are eliminated during transformation, since they
6599 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006600 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601}
Mike Stump1eb44332009-09-09 15:08:12 +00006602
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006604ExprResult
John McCall454feb92009-12-08 09:21:05 +00006605TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006606 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6607 if (!Type)
6608 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006609
John McCall60d7b3a2010-08-24 06:29:42 +00006610 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006611 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006616 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006618 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006619
John McCall9d125032010-01-15 18:39:57 +00006620 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006621 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006623 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624}
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006627ExprResult
John McCall454feb92009-12-08 09:21:05 +00006628TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006629 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6630 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6631 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006633
John McCall60d7b3a2010-08-24 06:29:42 +00006634 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006636 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006639 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006641 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642
John McCall1d7d8d62010-01-19 22:33:45 +00006643 // Note: the expression type doesn't necessarily match the
6644 // type-as-written, but that's okay, because it should always be
6645 // derivable from the initializer.
6646
John McCall42f56b52010-01-18 19:35:47 +00006647 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006649 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650}
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
John McCall454feb92009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006655 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006657 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 if (!getDerived().AlwaysRebuild() &&
6660 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006661 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006664 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006666 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 E->getAccessorLoc(),
6668 E->getAccessor());
6669}
Mike Stump1eb44332009-09-09 15:08:12 +00006670
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006672ExprResult
John McCall454feb92009-12-08 09:21:05 +00006673TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006676 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006677 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006678 Inits, &InitChanged))
6679 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006680
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006682 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006684 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006685 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686}
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006689ExprResult
John McCall454feb92009-12-08 09:21:05 +00006690TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Douglas Gregor43959a92009-08-20 07:17:43 +00006693 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006694 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregor43959a92009-08-20 07:17:43 +00006698 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006699 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 bool ExprChanged = false;
6701 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6702 DEnd = E->designators_end();
6703 D != DEnd; ++D) {
6704 if (D->isFieldDesignator()) {
6705 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6706 D->getDotLoc(),
6707 D->getFieldLoc()));
6708 continue;
6709 }
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006712 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006713 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006714 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006715
6716 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006718
Douglas Gregorb98b1992009-08-11 05:31:07 +00006719 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6720 ArrayExprs.push_back(Index.release());
6721 continue;
6722 }
Mike Stump1eb44332009-09-09 15:08:12 +00006723
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006725 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6727 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006729
John McCall60d7b3a2010-08-24 06:29:42 +00006730 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006733
6734 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735 End.get(),
6736 D->getLBracketLoc(),
6737 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6740 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 ArrayExprs.push_back(Start.release());
6743 ArrayExprs.push_back(End.release());
6744 }
Mike Stump1eb44332009-09-09 15:08:12 +00006745
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746 if (!getDerived().AlwaysRebuild() &&
6747 Init.get() == E->getInit() &&
6748 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006749 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006751 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006753 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006754}
Mike Stump1eb44332009-09-09 15:08:12 +00006755
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006757ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006759 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006760 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006761
Douglas Gregor5557b252009-10-28 00:29:27 +00006762 // FIXME: Will we ever have proper type location here? Will we actually
6763 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 QualType T = getDerived().TransformType(E->getType());
6765 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006766 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006767
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 if (!getDerived().AlwaysRebuild() &&
6769 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006770 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 return getDerived().RebuildImplicitValueInitExpr(T);
6773}
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006776ExprResult
John McCall454feb92009-12-08 09:21:05 +00006777TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006778 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6779 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
John McCall60d7b3a2010-08-24 06:29:42 +00006782 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006784 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006785
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006787 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006789 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006790
John McCall9ae2f072010-08-23 23:25:46 +00006791 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006792 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793}
6794
6795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006796ExprResult
John McCall454feb92009-12-08 09:21:05 +00006797TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006798 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006799 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006800 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6801 &ArgumentChanged))
6802 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006803
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006805 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 E->getRParenLoc());
6807}
Mike Stump1eb44332009-09-09 15:08:12 +00006808
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809/// \brief Transform an address-of-label expression.
6810///
6811/// By default, the transformation of an address-of-label expression always
6812/// rebuilds the expression, so that the label identifier can be resolved to
6813/// the corresponding label statement by semantic analysis.
6814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006815ExprResult
John McCall454feb92009-12-08 09:21:05 +00006816TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006817 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6818 E->getLabel());
6819 if (!LD)
6820 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006821
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006823 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824}
Mike Stump1eb44332009-09-09 15:08:12 +00006825
6826template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006827ExprResult
John McCall454feb92009-12-08 09:21:05 +00006828TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006829 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006830 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006832 if (SubStmt.isInvalid()) {
6833 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006834 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006835 }
Mike Stump1eb44332009-09-09 15:08:12 +00006836
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006838 SubStmt.get() == E->getSubStmt()) {
6839 // Calling this an 'error' is unintuitive, but it does the right thing.
6840 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006841 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006842 }
Mike Stump1eb44332009-09-09 15:08:12 +00006843
6844 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006845 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 E->getRParenLoc());
6847}
Mike Stump1eb44332009-09-09 15:08:12 +00006848
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006850ExprResult
John McCall454feb92009-12-08 09:21:05 +00006851TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006852 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 if (Cond.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 LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006857 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006858 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006859
John McCall60d7b3a2010-08-24 06:29:42 +00006860 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006863
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (!getDerived().AlwaysRebuild() &&
6865 Cond.get() == E->getCond() &&
6866 LHS.get() == E->getLHS() &&
6867 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006868 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006871 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 E->getRParenLoc());
6873}
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006876ExprResult
John McCall454feb92009-12-08 09:21:05 +00006877TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006878 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879}
6880
6881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006882ExprResult
John McCall454feb92009-12-08 09:21:05 +00006883TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006884 switch (E->getOperator()) {
6885 case OO_New:
6886 case OO_Delete:
6887 case OO_Array_New:
6888 case OO_Array_Delete:
6889 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006890
Douglas Gregor668d6d92009-12-13 20:44:55 +00006891 case OO_Call: {
6892 // This is a call to an object's operator().
6893 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6894
6895 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006896 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006897 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006898 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006899
6900 // FIXME: Poor location information
6901 SourceLocation FakeLParenLoc
6902 = SemaRef.PP.getLocForEndOfToken(
6903 static_cast<Expr *>(Object.get())->getLocEnd());
6904
6905 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006906 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006907 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006908 Args))
6909 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006910
John McCall9ae2f072010-08-23 23:25:46 +00006911 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006912 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006913 E->getLocEnd());
6914 }
6915
6916#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6917 case OO_##Name:
6918#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6919#include "clang/Basic/OperatorKinds.def"
6920 case OO_Subscript:
6921 // Handled below.
6922 break;
6923
6924 case OO_Conditional:
6925 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006926
6927 case OO_None:
6928 case NUM_OVERLOADED_OPERATORS:
6929 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006930 }
6931
John McCall60d7b3a2010-08-24 06:29:42 +00006932 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006934 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006935
Richard Smithefeeccf2012-10-21 03:28:35 +00006936 ExprResult First;
6937 if (E->getOperator() == OO_Amp)
6938 First = getDerived().TransformAddressOfOperand(E->getArg(0));
6939 else
6940 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006942 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943
John McCall60d7b3a2010-08-24 06:29:42 +00006944 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 if (E->getNumArgs() == 2) {
6946 Second = getDerived().TransformExpr(E->getArg(1));
6947 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006948 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 }
Mike Stump1eb44332009-09-09 15:08:12 +00006950
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951 if (!getDerived().AlwaysRebuild() &&
6952 Callee.get() == E->getCallee() &&
6953 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006954 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006955 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006956
Lang Hamesbe9af122012-10-02 04:45:10 +00006957 Sema::FPContractStateRAII FPContractState(getSema());
6958 getSema().FPFeatures.fp_contract = E->isFPContractable();
6959
Douglas Gregorb98b1992009-08-11 05:31:07 +00006960 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6961 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006962 Callee.get(),
6963 First.get(),
6964 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965}
Mike Stump1eb44332009-09-09 15:08:12 +00006966
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006968ExprResult
John McCall454feb92009-12-08 09:21:05 +00006969TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6970 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971}
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006974ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006975TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6976 // Transform the callee.
6977 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6978 if (Callee.isInvalid())
6979 return ExprError();
6980
6981 // Transform exec config.
6982 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6983 if (EC.isInvalid())
6984 return ExprError();
6985
6986 // Transform arguments.
6987 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006988 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006989 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006990 &ArgChanged))
6991 return ExprError();
6992
6993 if (!getDerived().AlwaysRebuild() &&
6994 Callee.get() == E->getCallee() &&
6995 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006996 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006997
6998 // FIXME: Wrong source location information for the '('.
6999 SourceLocation FakeLParenLoc
7000 = ((Expr *)Callee.get())->getSourceRange().getBegin();
7001 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007002 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00007003 E->getRParenLoc(), EC.get());
7004}
7005
7006template<typename Derived>
7007ExprResult
John McCall454feb92009-12-08 09:21:05 +00007008TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007009 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7010 if (!Type)
7011 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007012
John McCall60d7b3a2010-08-24 06:29:42 +00007013 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007014 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007016 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007019 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007021 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00007023 E->getStmtClass(),
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007024 E->getAngleBrackets().getBegin(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007025 Type,
Fariborz Jahanianf799ae12013-02-22 22:02:53 +00007026 E->getAngleBrackets().getEnd(),
7027 // FIXME. this should be '(' location
7028 E->getAngleBrackets().getEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00007029 SubExpr.get(),
Abramo Bagnara6cf7d7d2012-10-15 21:08:58 +00007030 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007031}
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007034ExprResult
John McCall454feb92009-12-08 09:21:05 +00007035TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7036 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037}
Mike Stump1eb44332009-09-09 15:08:12 +00007038
7039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007040ExprResult
John McCall454feb92009-12-08 09:21:05 +00007041TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7042 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007043}
7044
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007046ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007048 CXXReinterpretCastExpr *E) {
7049 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007050}
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Douglas Gregorb98b1992009-08-11 05:31:07 +00007052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007053ExprResult
John McCall454feb92009-12-08 09:21:05 +00007054TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7055 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056}
Mike Stump1eb44332009-09-09 15:08:12 +00007057
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007059ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007061 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007062 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7063 if (!Type)
7064 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007065
John McCall60d7b3a2010-08-24 06:29:42 +00007066 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007067 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007069 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007072 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007074 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007075
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007076 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007078 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 E->getRParenLoc());
7080}
Mike Stump1eb44332009-09-09 15:08:12 +00007081
Douglas Gregorb98b1992009-08-11 05:31:07 +00007082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007083ExprResult
John McCall454feb92009-12-08 09:21:05 +00007084TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007086 TypeSourceInfo *TInfo
7087 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7088 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007089 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007090
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007092 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007093 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007094
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007095 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7096 E->getLocStart(),
7097 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098 E->getLocEnd());
7099 }
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Eli Friedmanef331b72012-01-20 01:26:23 +00007101 // We don't know whether the subexpression is potentially evaluated until
7102 // after we perform semantic analysis. We speculatively assume it is
7103 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 // potentially evaluated.
Eli Friedman80bfa3d2012-09-26 04:34:21 +00007105 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7106 Sema::ReuseLambdaContextDecl);
Mike Stump1eb44332009-09-09 15:08:12 +00007107
John McCall60d7b3a2010-08-24 06:29:42 +00007108 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007110 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 if (!getDerived().AlwaysRebuild() &&
7113 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007114 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007115
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007116 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7117 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007118 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 E->getLocEnd());
7120}
7121
7122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007123ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007124TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7125 if (E->isTypeOperand()) {
7126 TypeSourceInfo *TInfo
7127 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7128 if (!TInfo)
7129 return ExprError();
7130
7131 if (!getDerived().AlwaysRebuild() &&
7132 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007133 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007134
Douglas Gregor3c52a212011-03-06 17:40:41 +00007135 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007136 E->getLocStart(),
7137 TInfo,
7138 E->getLocEnd());
7139 }
7140
Francois Pichet01b7c302010-09-08 12:20:18 +00007141 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7142
7143 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7144 if (SubExpr.isInvalid())
7145 return ExprError();
7146
7147 if (!getDerived().AlwaysRebuild() &&
7148 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007149 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007150
7151 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7152 E->getLocStart(),
7153 SubExpr.get(),
7154 E->getLocEnd());
7155}
7156
7157template<typename Derived>
7158ExprResult
John McCall454feb92009-12-08 09:21:05 +00007159TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007160 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007161}
Mike Stump1eb44332009-09-09 15:08:12 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007164ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007166 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007167 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168}
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007171ExprResult
John McCall454feb92009-12-08 09:21:05 +00007172TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007173 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007174 QualType T;
7175 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7176 T = MD->getThisType(getSema().Context);
7177 else
7178 T = getSema().Context.getPointerType(
7179 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007180
Douglas Gregorec79d872012-02-24 17:41:38 +00007181 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7182 // Make sure that we capture 'this'.
7183 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007184 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007185 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007186
Douglas Gregor828a1972010-01-07 23:12:05 +00007187 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
John McCall454feb92009-12-08 09:21:05 +00007192TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007193 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 if (!getDerived().AlwaysRebuild() &&
7198 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007199 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007200
Douglas Gregorbca01b42011-07-06 22:04:06 +00007201 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7202 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007203}
Mike Stump1eb44332009-09-09 15:08:12 +00007204
Douglas Gregorb98b1992009-08-11 05:31:07 +00007205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007206ExprResult
John McCall454feb92009-12-08 09:21:05 +00007207TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007208 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007209 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7210 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007211 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007213
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007216 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007217
Douglas Gregor036aed12009-12-23 23:03:06 +00007218 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219}
Mike Stump1eb44332009-09-09 15:08:12 +00007220
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007222ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007223TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7224 CXXScalarValueInitExpr *E) {
7225 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7226 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007227 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007228
Douglas Gregorb98b1992009-08-11 05:31:07 +00007229 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007230 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007231 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007232
Chad Rosier4a9d7952012-08-08 18:46:20 +00007233 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007234 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007235 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236}
Mike Stump1eb44332009-09-09 15:08:12 +00007237
Douglas Gregorb98b1992009-08-11 05:31:07 +00007238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007239ExprResult
John McCall454feb92009-12-08 09:21:05 +00007240TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007241 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007242 TypeSourceInfo *AllocTypeInfo
7243 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7244 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Douglas Gregorb98b1992009-08-11 05:31:07 +00007247 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007248 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007250 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007251
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252 // Transform the placement arguments (if any).
7253 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007254 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007255 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007256 E->getNumPlacementArgs(), true,
7257 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007260 // Transform the initializer (if any).
7261 Expr *OldInit = E->getInitializer();
7262 ExprResult NewInit;
7263 if (OldInit)
7264 NewInit = getDerived().TransformExpr(OldInit);
7265 if (NewInit.isInvalid())
7266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007267
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007268 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007269 FunctionDecl *OperatorNew = 0;
7270 if (E->getOperatorNew()) {
7271 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007272 getDerived().TransformDecl(E->getLocStart(),
7273 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007274 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007275 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007276 }
7277
7278 FunctionDecl *OperatorDelete = 0;
7279 if (E->getOperatorDelete()) {
7280 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007281 getDerived().TransformDecl(E->getLocStart(),
7282 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007283 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007284 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007285 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007286
Douglas Gregorb98b1992009-08-11 05:31:07 +00007287 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007288 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007290 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007291 OperatorNew == E->getOperatorNew() &&
7292 OperatorDelete == E->getOperatorDelete() &&
7293 !ArgumentChanged) {
7294 // Mark any declarations we need as referenced.
7295 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007296 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007297 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007298 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007299 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007300
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007301 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007302 QualType ElementType
7303 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7304 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7305 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7306 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007307 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007308 }
7309 }
7310 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007311
John McCall3fa5cae2010-10-26 07:05:15 +00007312 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007313 }
Mike Stump1eb44332009-09-09 15:08:12 +00007314
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007315 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007316 if (!ArraySize.get()) {
7317 // If no array size was specified, but the new expression was
7318 // instantiated with an array type (e.g., "new T" where T is
7319 // instantiated with "int[4]"), extract the outer bound from the
7320 // array type as our array size. We do this with constant and
7321 // dependently-sized array types.
7322 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7323 if (!ArrayT) {
7324 // Do nothing
7325 } else if (const ConstantArrayType *ConsArrayT
7326 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007327 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007328 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007329 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007330 SemaRef.Context.getSizeType(),
7331 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007332 AllocType = ConsArrayT->getElementType();
7333 } else if (const DependentSizedArrayType *DepArrayT
7334 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7335 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007336 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007337 AllocType = DepArrayT->getElementType();
7338 }
7339 }
7340 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7343 E->isGlobalNew(),
7344 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007345 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007347 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007348 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007349 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007350 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007351 E->getDirectInitRange(),
7352 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353}
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Douglas Gregorb98b1992009-08-11 05:31:07 +00007355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007356ExprResult
John McCall454feb92009-12-08 09:21:05 +00007357TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007358 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007359 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007361
Douglas Gregor1af74512010-02-26 00:38:10 +00007362 // Transform the delete operator, if known.
7363 FunctionDecl *OperatorDelete = 0;
7364 if (E->getOperatorDelete()) {
7365 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007366 getDerived().TransformDecl(E->getLocStart(),
7367 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007368 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007369 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007370 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007371
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007373 Operand.get() == E->getArgument() &&
7374 OperatorDelete == E->getOperatorDelete()) {
7375 // Mark any declarations we need as referenced.
7376 // FIXME: instantiation-specific.
7377 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007378 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007379
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007380 if (!E->getArgument()->isTypeDependent()) {
7381 QualType Destroyed = SemaRef.Context.getBaseElementType(
7382 E->getDestroyedType());
7383 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7384 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007385 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007386 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007387 }
7388 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007389
John McCall3fa5cae2010-10-26 07:05:15 +00007390 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007391 }
Mike Stump1eb44332009-09-09 15:08:12 +00007392
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7394 E->isGlobalDelete(),
7395 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007396 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007397}
Mike Stump1eb44332009-09-09 15:08:12 +00007398
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007400ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007401TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007402 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007403 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007404 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007406
John McCallb3d87482010-08-24 05:47:05 +00007407 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007408 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007409 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007410 E->getOperatorLoc(),
7411 E->isArrow()? tok::arrow : tok::period,
7412 ObjectTypePtr,
7413 MayBePseudoDestructor);
7414 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007415 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007416
John McCallb3d87482010-08-24 05:47:05 +00007417 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007418 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7419 if (QualifierLoc) {
7420 QualifierLoc
7421 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7422 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007423 return ExprError();
7424 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007425 CXXScopeSpec SS;
7426 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007427
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007428 PseudoDestructorTypeStorage Destroyed;
7429 if (E->getDestroyedTypeInfo()) {
7430 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007431 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007432 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007433 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007434 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007435 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007436 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007437 // We aren't likely to be able to resolve the identifier down to a type
7438 // now anyway, so just retain the identifier.
7439 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7440 E->getDestroyedTypeLoc());
7441 } else {
7442 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007443 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007444 *E->getDestroyedTypeIdentifier(),
7445 E->getDestroyedTypeLoc(),
7446 /*Scope=*/0,
7447 SS, ObjectTypePtr,
7448 false);
7449 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007450 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007451
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007452 Destroyed
7453 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7454 E->getDestroyedTypeLoc());
7455 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007456
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007457 TypeSourceInfo *ScopeTypeInfo = 0;
7458 if (E->getScopeTypeInfo()) {
Douglas Gregor303b96f2013-03-08 21:25:01 +00007459 CXXScopeSpec EmptySS;
7460 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
7461 E->getScopeTypeInfo(), ObjectType, 0, EmptySS);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007462 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007463 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007464 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007465
John McCall9ae2f072010-08-23 23:25:46 +00007466 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007467 E->getOperatorLoc(),
7468 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007469 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007470 ScopeTypeInfo,
7471 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007472 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007473 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007474}
Mike Stump1eb44332009-09-09 15:08:12 +00007475
Douglas Gregora71d8192009-09-04 17:36:40 +00007476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007477ExprResult
John McCallba135432009-11-21 08:51:07 +00007478TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007479 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007480 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7481 Sema::LookupOrdinaryName);
7482
7483 // Transform all the decls.
7484 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7485 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007486 NamedDecl *InstD = static_cast<NamedDecl*>(
7487 getDerived().TransformDecl(Old->getNameLoc(),
7488 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007489 if (!InstD) {
7490 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7491 // This can happen because of dependent hiding.
7492 if (isa<UsingShadowDecl>(*I))
7493 continue;
7494 else
John McCallf312b1e2010-08-26 23:41:50 +00007495 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007496 }
John McCallf7a1a742009-11-24 19:00:30 +00007497
7498 // Expand using declarations.
7499 if (isa<UsingDecl>(InstD)) {
7500 UsingDecl *UD = cast<UsingDecl>(InstD);
7501 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7502 E = UD->shadow_end(); I != E; ++I)
7503 R.addDecl(*I);
7504 continue;
7505 }
7506
7507 R.addDecl(InstD);
7508 }
7509
7510 // Resolve a kind, but don't do any further analysis. If it's
7511 // ambiguous, the callee needs to deal with it.
7512 R.resolveKind();
7513
7514 // Rebuild the nested-name qualifier, if present.
7515 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007516 if (Old->getQualifierLoc()) {
7517 NestedNameSpecifierLoc QualifierLoc
7518 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7519 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007520 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007521
Douglas Gregor4c9be892011-02-28 20:01:57 +00007522 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007523 }
7524
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007525 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007526 CXXRecordDecl *NamingClass
7527 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7528 Old->getNameLoc(),
7529 Old->getNamingClass()));
7530 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007532
Douglas Gregor66c45152010-04-27 16:10:10 +00007533 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007534 }
7535
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007536 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7537
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007538 // If we have neither explicit template arguments, nor the template keyword,
7539 // it's a normal declaration name.
7540 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007541 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7542
7543 // If we have template arguments, rebuild them, then rebuild the
7544 // templateid expression.
7545 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola02e221b2012-08-28 04:13:54 +00007546 if (Old->hasExplicitTemplateArgs() &&
7547 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregorfcc12532010-12-20 17:31:10 +00007548 Old->getNumTemplateArgs(),
7549 TransArgs))
7550 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007551
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007552 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007553 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554}
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Douglas Gregorb98b1992009-08-11 05:31:07 +00007556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007557ExprResult
John McCall454feb92009-12-08 09:21:05 +00007558TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007559 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7560 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007561 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007562
Douglas Gregorb98b1992009-08-11 05:31:07 +00007563 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007564 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007565 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007566
Mike Stump1eb44332009-09-09 15:08:12 +00007567 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569 T,
7570 E->getLocEnd());
7571}
Mike Stump1eb44332009-09-09 15:08:12 +00007572
Douglas Gregorb98b1992009-08-11 05:31:07 +00007573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007574ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007575TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7576 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7577 if (!LhsT)
7578 return ExprError();
7579
7580 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7581 if (!RhsT)
7582 return ExprError();
7583
7584 if (!getDerived().AlwaysRebuild() &&
7585 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7586 return SemaRef.Owned(E);
7587
7588 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7589 E->getLocStart(),
7590 LhsT, RhsT,
7591 E->getLocEnd());
7592}
7593
7594template<typename Derived>
7595ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007596TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7597 bool ArgChanged = false;
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007598 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007599 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7600 TypeSourceInfo *From = E->getArg(I);
7601 TypeLoc FromTL = From->getTypeLoc();
David Blaikie39e6ab42013-02-18 22:06:02 +00007602 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007603 TypeLocBuilder TLB;
7604 TLB.reserve(FromTL.getFullDataSize());
7605 QualType To = getDerived().TransformType(TLB, FromTL);
7606 if (To.isNull())
7607 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007608
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007609 if (To == From->getType())
7610 Args.push_back(From);
7611 else {
7612 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7613 ArgChanged = true;
7614 }
7615 continue;
7616 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007617
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007618 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007619
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007620 // We have a pack expansion. Instantiate it.
David Blaikie39e6ab42013-02-18 22:06:02 +00007621 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007622 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7623 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7624 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007625
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007626 // Determine whether the set of unexpanded parameter packs can and should
7627 // be expanded.
7628 bool Expand = true;
7629 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00007630 Optional<unsigned> OrigNumExpansions =
7631 ExpansionTL.getTypePtr()->getNumExpansions();
7632 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007633 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7634 PatternTL.getSourceRange(),
7635 Unexpanded,
7636 Expand, RetainExpansion,
7637 NumExpansions))
7638 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007639
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007640 if (!Expand) {
7641 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007642 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007643 // expansion.
7644 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007645
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007646 TypeLocBuilder TLB;
7647 TLB.reserve(From->getTypeLoc().getFullDataSize());
7648
7649 QualType To = getDerived().TransformType(TLB, PatternTL);
7650 if (To.isNull())
7651 return ExprError();
7652
Chad Rosier4a9d7952012-08-08 18:46:20 +00007653 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007654 PatternTL.getSourceRange(),
7655 ExpansionTL.getEllipsisLoc(),
7656 NumExpansions);
7657 if (To.isNull())
7658 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007659
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007660 PackExpansionTypeLoc ToExpansionTL
7661 = TLB.push<PackExpansionTypeLoc>(To);
7662 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7663 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7664 continue;
7665 }
7666
7667 // Expand the pack expansion by substituting for each argument in the
7668 // pack(s).
7669 for (unsigned I = 0; I != *NumExpansions; ++I) {
7670 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7671 TypeLocBuilder TLB;
7672 TLB.reserve(PatternTL.getFullDataSize());
7673 QualType To = getDerived().TransformType(TLB, PatternTL);
7674 if (To.isNull())
7675 return ExprError();
7676
7677 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7678 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007679
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007680 if (!RetainExpansion)
7681 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007682
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007683 // If we're supposed to retain a pack expansion, do so by temporarily
7684 // forgetting the partially-substituted parameter pack.
7685 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7686
7687 TypeLocBuilder TLB;
7688 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007689
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007690 QualType To = getDerived().TransformType(TLB, PatternTL);
7691 if (To.isNull())
7692 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007693
7694 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007695 PatternTL.getSourceRange(),
7696 ExpansionTL.getEllipsisLoc(),
7697 NumExpansions);
7698 if (To.isNull())
7699 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007700
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007701 PackExpansionTypeLoc ToExpansionTL
7702 = TLB.push<PackExpansionTypeLoc>(To);
7703 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7704 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7705 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007706
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007707 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7708 return SemaRef.Owned(E);
7709
7710 return getDerived().RebuildTypeTrait(E->getTrait(),
7711 E->getLocStart(),
7712 Args,
7713 E->getLocEnd());
7714}
7715
7716template<typename Derived>
7717ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007718TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7719 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7720 if (!T)
7721 return ExprError();
7722
7723 if (!getDerived().AlwaysRebuild() &&
7724 T == E->getQueriedTypeSourceInfo())
7725 return SemaRef.Owned(E);
7726
7727 ExprResult SubExpr;
7728 {
7729 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7730 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7731 if (SubExpr.isInvalid())
7732 return ExprError();
7733
7734 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7735 return SemaRef.Owned(E);
7736 }
7737
7738 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7739 E->getLocStart(),
7740 T,
7741 SubExpr.get(),
7742 E->getLocEnd());
7743}
7744
7745template<typename Derived>
7746ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007747TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7748 ExprResult SubExpr;
7749 {
7750 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7751 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7752 if (SubExpr.isInvalid())
7753 return ExprError();
7754
7755 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7756 return SemaRef.Owned(E);
7757 }
7758
7759 return getDerived().RebuildExpressionTrait(
7760 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7761}
7762
7763template<typename Derived>
7764ExprResult
John McCall865d4472009-11-19 22:55:06 +00007765TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007766 DependentScopeDeclRefExpr *E) {
Richard Smithefeeccf2012-10-21 03:28:35 +00007767 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand*/false);
7768}
7769
7770template<typename Derived>
7771ExprResult
7772TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
7773 DependentScopeDeclRefExpr *E,
7774 bool IsAddressOfOperand) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007775 NestedNameSpecifierLoc QualifierLoc
7776 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7777 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007778 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007779 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007780
John McCall43fed0d2010-11-12 08:19:04 +00007781 // TODO: If this is a conversion-function-id, verify that the
7782 // destination type name (if present) resolves the same way after
7783 // instantiation as it did in the local scope.
7784
Abramo Bagnara25777432010-08-11 22:01:17 +00007785 DeclarationNameInfo NameInfo
7786 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7787 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007789
John McCallf7a1a742009-11-24 19:00:30 +00007790 if (!E->hasExplicitTemplateArgs()) {
7791 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007792 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007793 // Note: it is sufficient to compare the Name component of NameInfo:
7794 // if name has not changed, DNLoc has not changed either.
7795 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007796 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007797
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007798 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007799 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007800 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007801 /*TemplateArgs*/ 0,
7802 IsAddressOfOperand);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007803 }
John McCalld5532b62009-11-23 01:53:49 +00007804
7805 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007806 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7807 E->getNumTemplateArgs(),
7808 TransArgs))
7809 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007811 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007812 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007813 NameInfo,
Richard Smithefeeccf2012-10-21 03:28:35 +00007814 &TransArgs,
7815 IsAddressOfOperand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007816}
7817
7818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007819ExprResult
John McCall454feb92009-12-08 09:21:05 +00007820TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithc83c2302012-12-19 01:39:02 +00007821 // CXXConstructExprs other than for list-initialization and
7822 // CXXTemporaryObjectExpr are always implicit, so when we have
7823 // a 1-argument construction we just transform that argument.
Richard Smith73ed67c2012-11-26 08:32:48 +00007824 if ((E->getNumArgs() == 1 ||
7825 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithc83c2302012-12-19 01:39:02 +00007826 (!getDerived().DropCallArgument(E->getArg(0))) &&
7827 !E->isListInitialization())
Douglas Gregor321725d2010-02-03 03:01:57 +00007828 return getDerived().TransformExpr(E->getArg(0));
7829
Douglas Gregorb98b1992009-08-11 05:31:07 +00007830 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7831
7832 QualType T = getDerived().TransformType(E->getType());
7833 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007834 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007835
7836 CXXConstructorDecl *Constructor
7837 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007838 getDerived().TransformDecl(E->getLocStart(),
7839 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007840 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007841 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007842
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007844 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007845 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007846 &ArgumentChanged))
7847 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007848
Douglas Gregorb98b1992009-08-11 05:31:07 +00007849 if (!getDerived().AlwaysRebuild() &&
7850 T == E->getType() &&
7851 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007852 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007853 // Mark the constructor as referenced.
7854 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007855 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007856 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007857 }
Mike Stump1eb44332009-09-09 15:08:12 +00007858
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007859 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7860 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007861 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007862 E->hadMultipleCandidates(),
Richard Smithc83c2302012-12-19 01:39:02 +00007863 E->isListInitialization(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007864 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007865 E->getConstructionKind(),
7866 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007867}
Mike Stump1eb44332009-09-09 15:08:12 +00007868
Douglas Gregorb98b1992009-08-11 05:31:07 +00007869/// \brief Transform a C++ temporary-binding expression.
7870///
Douglas Gregor51326552009-12-24 18:51:59 +00007871/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7872/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007873template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007874ExprResult
John McCall454feb92009-12-08 09:21:05 +00007875TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007876 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007877}
Mike Stump1eb44332009-09-09 15:08:12 +00007878
John McCall4765fa02010-12-06 08:20:24 +00007879/// \brief Transform a C++ expression that contains cleanups that should
7880/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007881///
John McCall4765fa02010-12-06 08:20:24 +00007882/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007883/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007885ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007886TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007887 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007888}
Mike Stump1eb44332009-09-09 15:08:12 +00007889
Douglas Gregorb98b1992009-08-11 05:31:07 +00007890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007891ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007893 CXXTemporaryObjectExpr *E) {
7894 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7895 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007897
Douglas Gregorb98b1992009-08-11 05:31:07 +00007898 CXXConstructorDecl *Constructor
7899 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007900 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007901 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007903 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007904
Douglas Gregorb98b1992009-08-11 05:31:07 +00007905 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007906 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007907 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007908 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007909 &ArgumentChanged))
7910 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007911
Douglas Gregorb98b1992009-08-11 05:31:07 +00007912 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007913 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007914 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007915 !ArgumentChanged) {
7916 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007917 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007918 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007919 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007920
Richard Smithc83c2302012-12-19 01:39:02 +00007921 // FIXME: Pass in E->isListInitialization().
Douglas Gregorab6677e2010-09-08 00:15:04 +00007922 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7923 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007924 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007925 E->getLocEnd());
7926}
Mike Stump1eb44332009-09-09 15:08:12 +00007927
Douglas Gregorb98b1992009-08-11 05:31:07 +00007928template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007929ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007930TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007931 // Transform the type of the lambda parameters and start the definition of
7932 // the lambda itself.
7933 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007934 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007935 if (!MethodTy)
7936 return ExprError();
7937
Eli Friedman8da8a662012-09-19 01:18:11 +00007938 // Create the local class that will describe the lambda.
7939 CXXRecordDecl *Class
7940 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7941 MethodTy,
7942 /*KnownDependent=*/false);
7943 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
7944
Douglas Gregorc6889e72012-02-14 22:28:59 +00007945 // Transform lambda parameters.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00007946 SmallVector<QualType, 4> ParamTypes;
7947 SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorc6889e72012-02-14 22:28:59 +00007948 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7949 E->getCallOperator()->param_begin(),
7950 E->getCallOperator()->param_size(),
7951 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007952 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007953
Douglas Gregordfca6f52012-02-13 22:00:16 +00007954 // Build the call operator.
7955 CXXMethodDecl *CallOperator
7956 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007957 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007958 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007959 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007960 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007961
Richard Smith612409e2012-07-25 03:56:55 +00007962 return getDerived().TransformLambdaScope(E, CallOperator);
7963}
7964
7965template<typename Derived>
7966ExprResult
7967TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7968 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007969 // Introduce the context of the call operator.
7970 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7971
Douglas Gregordfca6f52012-02-13 22:00:16 +00007972 // Enter the scope of the lambda.
7973 sema::LambdaScopeInfo *LSI
7974 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7975 E->getCaptureDefault(),
7976 E->hasExplicitParameters(),
7977 E->hasExplicitResultType(),
7978 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007979
Douglas Gregordfca6f52012-02-13 22:00:16 +00007980 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007981 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007982 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007983 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007984 CEnd = E->capture_end();
7985 C != CEnd; ++C) {
7986 // When we hit the first implicit capture, tell Sema that we've finished
7987 // the list of explicit captures.
7988 if (!FinishedExplicitCaptures && C->isImplicit()) {
7989 getSema().finishLambdaExplicitCaptures(LSI);
7990 FinishedExplicitCaptures = true;
7991 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007992
Douglas Gregordfca6f52012-02-13 22:00:16 +00007993 // Capturing 'this' is trivial.
7994 if (C->capturesThis()) {
7995 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7996 continue;
7997 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007998
Douglas Gregora7365242012-02-14 19:27:52 +00007999 // Determine the capture kind for Sema.
8000 Sema::TryCaptureKind Kind
8001 = C->isImplicit()? Sema::TryCapture_Implicit
8002 : C->getCaptureKind() == LCK_ByCopy
8003 ? Sema::TryCapture_ExplicitByVal
8004 : Sema::TryCapture_ExplicitByRef;
8005 SourceLocation EllipsisLoc;
8006 if (C->isPackExpansion()) {
8007 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
8008 bool ShouldExpand = false;
8009 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008010 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008011 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
8012 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008013 Unexpanded,
8014 ShouldExpand, RetainExpansion,
8015 NumExpansions))
8016 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008017
Douglas Gregora7365242012-02-14 19:27:52 +00008018 if (ShouldExpand) {
8019 // The transform has determined that we should perform an expansion;
8020 // transform and capture each of the arguments.
8021 // expansion of the pattern. Do so.
8022 VarDecl *Pack = C->getCapturedVar();
8023 for (unsigned I = 0; I != *NumExpansions; ++I) {
8024 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8025 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008026 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00008027 Pack));
8028 if (!CapturedVar) {
8029 Invalid = true;
8030 continue;
8031 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008032
Douglas Gregora7365242012-02-14 19:27:52 +00008033 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008034 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
8035 }
Douglas Gregora7365242012-02-14 19:27:52 +00008036 continue;
8037 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008038
Douglas Gregora7365242012-02-14 19:27:52 +00008039 EllipsisLoc = C->getEllipsisLoc();
8040 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008041
Douglas Gregordfca6f52012-02-13 22:00:16 +00008042 // Transform the captured variable.
8043 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00008044 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00008045 C->getCapturedVar()));
8046 if (!CapturedVar) {
8047 Invalid = true;
8048 continue;
8049 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008050
Douglas Gregordfca6f52012-02-13 22:00:16 +00008051 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008052 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008053 }
8054 if (!FinishedExplicitCaptures)
8055 getSema().finishLambdaExplicitCaptures(LSI);
8056
Douglas Gregordfca6f52012-02-13 22:00:16 +00008057
8058 // Enter a new evaluation context to insulate the lambda from any
8059 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008060 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008061
8062 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008063 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008064 /*IsInstantiation=*/true);
8065 return ExprError();
8066 }
8067
8068 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008069 StmtResult Body = getDerived().TransformStmt(E->getBody());
8070 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008071 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008072 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008073 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008074 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008075
Chad Rosier4a9d7952012-08-08 18:46:20 +00008076 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008077 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008078}
8079
8080template<typename Derived>
8081ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008082TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008083 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008084 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8085 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008086 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008087
Douglas Gregorb98b1992009-08-11 05:31:07 +00008088 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008089 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008090 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008091 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008092 &ArgumentChanged))
8093 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008094
Douglas Gregorb98b1992009-08-11 05:31:07 +00008095 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008096 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008097 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008098 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008099
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008101 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008102 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008103 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008104 E->getRParenLoc());
8105}
Mike Stump1eb44332009-09-09 15:08:12 +00008106
Douglas Gregorb98b1992009-08-11 05:31:07 +00008107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008108ExprResult
John McCall865d4472009-11-19 22:55:06 +00008109TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008110 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008111 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008112 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008113 Expr *OldBase;
8114 QualType BaseType;
8115 QualType ObjectType;
8116 if (!E->isImplicitAccess()) {
8117 OldBase = E->getBase();
8118 Base = getDerived().TransformExpr(OldBase);
8119 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008121
John McCallaa81e162009-12-01 22:10:20 +00008122 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008123 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008124 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008125 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008126 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008127 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008128 ObjectTy,
8129 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008130 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008131 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008132
John McCallb3d87482010-08-24 05:47:05 +00008133 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008134 BaseType = ((Expr*) Base.get())->getType();
8135 } else {
8136 OldBase = 0;
8137 BaseType = getDerived().TransformType(E->getBaseType());
8138 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8139 }
Mike Stump1eb44332009-09-09 15:08:12 +00008140
Douglas Gregor6cd21982009-10-20 05:58:46 +00008141 // Transform the first part of the nested-name-specifier that qualifies
8142 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008143 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008144 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008145 E->getFirstQualifierFoundInScope(),
8146 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008147
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008148 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008149 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008150 QualifierLoc
8151 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8152 ObjectType,
8153 FirstQualifierInScope);
8154 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008155 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008156 }
Mike Stump1eb44332009-09-09 15:08:12 +00008157
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008158 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8159
John McCall43fed0d2010-11-12 08:19:04 +00008160 // TODO: If this is a conversion-function-id, verify that the
8161 // destination type name (if present) resolves the same way after
8162 // instantiation as it did in the local scope.
8163
Abramo Bagnara25777432010-08-11 22:01:17 +00008164 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008165 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008166 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008168
John McCallaa81e162009-12-01 22:10:20 +00008169 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008170 // This is a reference to a member without an explicitly-specified
8171 // template argument list. Optimize for this common case.
8172 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008173 Base.get() == OldBase &&
8174 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008175 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008176 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008177 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008178 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008179
John McCall9ae2f072010-08-23 23:25:46 +00008180 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008181 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008182 E->isArrow(),
8183 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008184 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008185 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008186 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008187 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008188 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008189 }
8190
John McCalld5532b62009-11-23 01:53:49 +00008191 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008192 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8193 E->getNumTemplateArgs(),
8194 TransArgs))
8195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008196
John McCall9ae2f072010-08-23 23:25:46 +00008197 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008198 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008199 E->isArrow(),
8200 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008201 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008202 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008203 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008204 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008205 &TransArgs);
8206}
8207
8208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008209ExprResult
John McCall454feb92009-12-08 09:21:05 +00008210TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008211 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008212 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008213 QualType BaseType;
8214 if (!Old->isImplicitAccess()) {
8215 Base = getDerived().TransformExpr(Old->getBase());
8216 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008217 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008218 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8219 Old->isArrow());
8220 if (Base.isInvalid())
8221 return ExprError();
8222 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008223 } else {
8224 BaseType = getDerived().TransformType(Old->getBaseType());
8225 }
John McCall129e2df2009-11-30 22:42:35 +00008226
Douglas Gregor4c9be892011-02-28 20:01:57 +00008227 NestedNameSpecifierLoc QualifierLoc;
8228 if (Old->getQualifierLoc()) {
8229 QualifierLoc
8230 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8231 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008232 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008233 }
8234
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008235 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8236
Abramo Bagnara25777432010-08-11 22:01:17 +00008237 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008238 Sema::LookupOrdinaryName);
8239
8240 // Transform all the decls.
8241 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8242 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008243 NamedDecl *InstD = static_cast<NamedDecl*>(
8244 getDerived().TransformDecl(Old->getMemberLoc(),
8245 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008246 if (!InstD) {
8247 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8248 // This can happen because of dependent hiding.
8249 if (isa<UsingShadowDecl>(*I))
8250 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008251 else {
8252 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008253 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008254 }
John McCall9f54ad42009-12-10 09:41:52 +00008255 }
John McCall129e2df2009-11-30 22:42:35 +00008256
8257 // Expand using declarations.
8258 if (isa<UsingDecl>(InstD)) {
8259 UsingDecl *UD = cast<UsingDecl>(InstD);
8260 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8261 E = UD->shadow_end(); I != E; ++I)
8262 R.addDecl(*I);
8263 continue;
8264 }
8265
8266 R.addDecl(InstD);
8267 }
8268
8269 R.resolveKind();
8270
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008271 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008272 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008273 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008274 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008275 Old->getMemberLoc(),
8276 Old->getNamingClass()));
8277 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008278 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008279
Douglas Gregor66c45152010-04-27 16:10:10 +00008280 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008281 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008282
John McCall129e2df2009-11-30 22:42:35 +00008283 TemplateArgumentListInfo TransArgs;
8284 if (Old->hasExplicitTemplateArgs()) {
8285 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8286 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008287 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8288 Old->getNumTemplateArgs(),
8289 TransArgs))
8290 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008291 }
John McCallc2233c52010-01-15 08:34:02 +00008292
8293 // FIXME: to do this check properly, we will need to preserve the
8294 // first-qualifier-in-scope here, just in case we had a dependent
8295 // base (and therefore couldn't do the check) and a
8296 // nested-name-qualifier (and therefore could do the lookup).
8297 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008298
John McCall9ae2f072010-08-23 23:25:46 +00008299 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008300 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008301 Old->getOperatorLoc(),
8302 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008303 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008304 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008305 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008306 R,
8307 (Old->hasExplicitTemplateArgs()
8308 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008309}
8310
8311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008312ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008313TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008314 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008315 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8316 if (SubExpr.isInvalid())
8317 return ExprError();
8318
8319 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008320 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008321
8322 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8323}
8324
8325template<typename Derived>
8326ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008327TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008328 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8329 if (Pattern.isInvalid())
8330 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008331
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008332 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8333 return SemaRef.Owned(E);
8334
Douglas Gregor67fd1252011-01-14 21:20:45 +00008335 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8336 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008337}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008338
8339template<typename Derived>
8340ExprResult
8341TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8342 // If E is not value-dependent, then nothing will change when we transform it.
8343 // Note: This is an instantiation-centric view.
8344 if (!E->isValueDependent())
8345 return SemaRef.Owned(E);
8346
8347 // Note: None of the implementations of TryExpandParameterPacks can ever
8348 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008349 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008350 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8351 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008352 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008353 Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008354 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008355 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008356 ShouldExpand, RetainExpansion,
8357 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008358 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008359
Douglas Gregor089e8932011-10-10 18:59:29 +00008360 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008361 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008362
Douglas Gregor089e8932011-10-10 18:59:29 +00008363 NamedDecl *Pack = E->getPack();
8364 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008365 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008366 Pack));
8367 if (!Pack)
8368 return ExprError();
8369 }
8370
Chad Rosier4a9d7952012-08-08 18:46:20 +00008371
Douglas Gregoree8aff02011-01-04 17:33:58 +00008372 // We now know the length of the parameter pack, so build a new expression
8373 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008374 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8375 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008376 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008377}
8378
Douglas Gregorbe230c32011-01-03 17:17:50 +00008379template<typename Derived>
8380ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008381TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8382 SubstNonTypeTemplateParmPackExpr *E) {
8383 // Default behavior is to do nothing with this transformation.
8384 return SemaRef.Owned(E);
8385}
8386
8387template<typename Derived>
8388ExprResult
John McCall91a57552011-07-15 05:09:51 +00008389TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8390 SubstNonTypeTemplateParmExpr *E) {
8391 // Default behavior is to do nothing with this transformation.
8392 return SemaRef.Owned(E);
8393}
8394
8395template<typename Derived>
8396ExprResult
Richard Smith9a4db032012-09-12 00:56:43 +00008397TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
8398 // Default behavior is to do nothing with this transformation.
8399 return SemaRef.Owned(E);
8400}
8401
8402template<typename Derived>
8403ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008404TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8405 MaterializeTemporaryExpr *E) {
8406 return getDerived().TransformExpr(E->GetTemporaryExpr());
8407}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008408
Douglas Gregor03e80032011-06-21 17:03:29 +00008409template<typename Derived>
8410ExprResult
John McCall454feb92009-12-08 09:21:05 +00008411TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008412 return SemaRef.MaybeBindToTemporary(E);
8413}
8414
8415template<typename Derived>
8416ExprResult
8417TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008418 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008419}
8420
8421template<typename Derived>
8422ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008423TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8424 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8425 if (SubExpr.isInvalid())
8426 return ExprError();
8427
8428 if (!getDerived().AlwaysRebuild() &&
8429 SubExpr.get() == E->getSubExpr())
8430 return SemaRef.Owned(E);
8431
8432 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008433}
8434
8435template<typename Derived>
8436ExprResult
8437TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8438 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008439 SmallVector<Expr *, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008440 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008441 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008442 /*IsCall=*/false, Elements, &ArgChanged))
8443 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008444
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008445 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8446 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008447
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008448 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8449 Elements.data(),
8450 Elements.size());
8451}
8452
8453template<typename Derived>
8454ExprResult
8455TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008456 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 // Transform each of the elements.
Dmitri Gribenkocfa88f82013-01-12 19:30:44 +00008458 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008459 bool ArgChanged = false;
8460 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8461 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008462
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008463 if (OrigElement.isPackExpansion()) {
8464 // This key/value element is a pack expansion.
8465 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8466 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8467 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8468 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8469
8470 // Determine whether the set of unexpanded parameter packs can
8471 // and should be expanded.
8472 bool Expand = true;
8473 bool RetainExpansion = false;
David Blaikiedc84cd52013-02-20 22:23:23 +00008474 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8475 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008476 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8477 OrigElement.Value->getLocEnd());
8478 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8479 PatternRange,
8480 Unexpanded,
8481 Expand, RetainExpansion,
8482 NumExpansions))
8483 return ExprError();
8484
8485 if (!Expand) {
8486 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008487 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008488 // expansion.
8489 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8490 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8491 if (Key.isInvalid())
8492 return ExprError();
8493
8494 if (Key.get() != OrigElement.Key)
8495 ArgChanged = true;
8496
8497 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8498 if (Value.isInvalid())
8499 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008500
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008501 if (Value.get() != OrigElement.Value)
8502 ArgChanged = true;
8503
Chad Rosier4a9d7952012-08-08 18:46:20 +00008504 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008505 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8506 };
8507 Elements.push_back(Expansion);
8508 continue;
8509 }
8510
8511 // Record right away that the argument was changed. This needs
8512 // to happen even if the array expands to nothing.
8513 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008514
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008515 // The transform has determined that we should perform an elementwise
8516 // expansion of the pattern. Do so.
8517 for (unsigned I = 0; I != *NumExpansions; ++I) {
8518 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8519 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8520 if (Key.isInvalid())
8521 return ExprError();
8522
8523 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8524 if (Value.isInvalid())
8525 return ExprError();
8526
Chad Rosier4a9d7952012-08-08 18:46:20 +00008527 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008528 Key.get(), Value.get(), SourceLocation(), NumExpansions
8529 };
8530
8531 // If any unexpanded parameter packs remain, we still have a
8532 // pack expansion.
8533 if (Key.get()->containsUnexpandedParameterPack() ||
8534 Value.get()->containsUnexpandedParameterPack())
8535 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008536
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008537 Elements.push_back(Element);
8538 }
8539
8540 // We've finished with this pack expansion.
8541 continue;
8542 }
8543
8544 // Transform and check key.
8545 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8546 if (Key.isInvalid())
8547 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008548
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008549 if (Key.get() != OrigElement.Key)
8550 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008551
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008552 // Transform and check value.
8553 ExprResult Value
8554 = getDerived().TransformExpr(OrigElement.Value);
8555 if (Value.isInvalid())
8556 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008557
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008558 if (Value.get() != OrigElement.Value)
8559 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008560
8561 ObjCDictionaryElement Element = {
David Blaikie66874fb2013-02-21 01:47:18 +00008562 Key.get(), Value.get(), SourceLocation(), None
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008563 };
8564 Elements.push_back(Element);
8565 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008566
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008567 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8568 return SemaRef.MaybeBindToTemporary(E);
8569
8570 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8571 Elements.data(),
8572 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008573}
8574
Mike Stump1eb44332009-09-09 15:08:12 +00008575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008576ExprResult
John McCall454feb92009-12-08 09:21:05 +00008577TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008578 TypeSourceInfo *EncodedTypeInfo
8579 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8580 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008582
Douglas Gregorb98b1992009-08-11 05:31:07 +00008583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008584 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008585 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008586
8587 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008588 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008589 E->getRParenLoc());
8590}
Mike Stump1eb44332009-09-09 15:08:12 +00008591
Douglas Gregorb98b1992009-08-11 05:31:07 +00008592template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008593ExprResult TreeTransform<Derived>::
8594TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8595 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8596 if (result.isInvalid()) return ExprError();
8597 Expr *subExpr = result.take();
8598
8599 if (!getDerived().AlwaysRebuild() &&
8600 subExpr == E->getSubExpr())
8601 return SemaRef.Owned(E);
8602
8603 return SemaRef.Owned(new(SemaRef.Context)
8604 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8605}
8606
8607template<typename Derived>
8608ExprResult TreeTransform<Derived>::
8609TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008610 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008611 = getDerived().TransformType(E->getTypeInfoAsWritten());
8612 if (!TSInfo)
8613 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008614
John McCallf85e1932011-06-15 23:02:42 +00008615 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008616 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008617 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008618
John McCallf85e1932011-06-15 23:02:42 +00008619 if (!getDerived().AlwaysRebuild() &&
8620 TSInfo == E->getTypeInfoAsWritten() &&
8621 Result.get() == E->getSubExpr())
8622 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008623
John McCallf85e1932011-06-15 23:02:42 +00008624 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008625 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008626 Result.get());
8627}
8628
8629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008630ExprResult
John McCall454feb92009-12-08 09:21:05 +00008631TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008632 // Transform arguments.
8633 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008634 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008635 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008636 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008637 &ArgChanged))
8638 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008639
Douglas Gregor92e986e2010-04-22 16:44:27 +00008640 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8641 // Class message: transform the receiver type.
8642 TypeSourceInfo *ReceiverTypeInfo
8643 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8644 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008645 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008646
Douglas Gregor92e986e2010-04-22 16:44:27 +00008647 // If nothing changed, just retain the existing message send.
8648 if (!getDerived().AlwaysRebuild() &&
8649 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008650 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008651
8652 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008653 SmallVector<SourceLocation, 16> SelLocs;
8654 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008655 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8656 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008657 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008658 E->getMethodDecl(),
8659 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008660 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008661 E->getRightLoc());
8662 }
8663
8664 // Instance message: transform the receiver
8665 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8666 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008667 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008668 = getDerived().TransformExpr(E->getInstanceReceiver());
8669 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008670 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008671
8672 // If nothing changed, just retain the existing message send.
8673 if (!getDerived().AlwaysRebuild() &&
8674 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008675 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008676
Douglas Gregor92e986e2010-04-22 16:44:27 +00008677 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008678 SmallVector<SourceLocation, 16> SelLocs;
8679 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008680 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008681 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008682 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008683 E->getMethodDecl(),
8684 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008685 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008686 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008687}
8688
Mike Stump1eb44332009-09-09 15:08:12 +00008689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008690ExprResult
John McCall454feb92009-12-08 09:21:05 +00008691TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008692 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008693}
8694
Mike Stump1eb44332009-09-09 15:08:12 +00008695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008696ExprResult
John McCall454feb92009-12-08 09:21:05 +00008697TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008698 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008699}
8700
Mike Stump1eb44332009-09-09 15:08:12 +00008701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008702ExprResult
John McCall454feb92009-12-08 09:21:05 +00008703TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008704 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008705 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008706 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008707 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008708
8709 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008710
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008711 // If nothing changed, just retain the existing expression.
8712 if (!getDerived().AlwaysRebuild() &&
8713 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008714 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008715
John McCall9ae2f072010-08-23 23:25:46 +00008716 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008717 E->getLocation(),
8718 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008719}
8720
Mike Stump1eb44332009-09-09 15:08:12 +00008721template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008722ExprResult
John McCall454feb92009-12-08 09:21:05 +00008723TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008724 // 'super' and types never change. Property never changes. Just
8725 // retain the existing expression.
8726 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008727 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008728
Douglas Gregore3303542010-04-26 20:47:02 +00008729 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008731 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008732 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008733
Douglas Gregore3303542010-04-26 20:47:02 +00008734 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008735
Douglas Gregore3303542010-04-26 20:47:02 +00008736 // If nothing changed, just retain the existing expression.
8737 if (!getDerived().AlwaysRebuild() &&
8738 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008739 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008740
John McCall12f78a62010-12-02 01:19:52 +00008741 if (E->isExplicitProperty())
8742 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8743 E->getExplicitProperty(),
8744 E->getLocation());
8745
8746 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008747 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008748 E->getImplicitPropertyGetter(),
8749 E->getImplicitPropertySetter(),
8750 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008751}
8752
Mike Stump1eb44332009-09-09 15:08:12 +00008753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008754ExprResult
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008755TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8756 // Transform the base expression.
8757 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8758 if (Base.isInvalid())
8759 return ExprError();
8760
8761 // Transform the key expression.
8762 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8763 if (Key.isInvalid())
8764 return ExprError();
8765
8766 // If nothing changed, just retain the existing expression.
8767 if (!getDerived().AlwaysRebuild() &&
8768 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8769 return SemaRef.Owned(E);
8770
Chad Rosier4a9d7952012-08-08 18:46:20 +00008771 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008772 Base.get(), Key.get(),
8773 E->getAtIndexMethodDecl(),
8774 E->setAtIndexMethodDecl());
8775}
8776
8777template<typename Derived>
8778ExprResult
John McCall454feb92009-12-08 09:21:05 +00008779TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008780 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008781 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008782 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008783 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008784
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008785 // If nothing changed, just retain the existing expression.
8786 if (!getDerived().AlwaysRebuild() &&
8787 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008788 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008789
John McCall9ae2f072010-08-23 23:25:46 +00008790 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008791 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008792}
8793
Mike Stump1eb44332009-09-09 15:08:12 +00008794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008795ExprResult
John McCall454feb92009-12-08 09:21:05 +00008796TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008797 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008798 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008799 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008800 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008801 SubExprs, &ArgumentChanged))
8802 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008803
Douglas Gregorb98b1992009-08-11 05:31:07 +00008804 if (!getDerived().AlwaysRebuild() &&
8805 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008806 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008807
Douglas Gregorb98b1992009-08-11 05:31:07 +00008808 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008809 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008810 E->getRParenLoc());
8811}
8812
Mike Stump1eb44332009-09-09 15:08:12 +00008813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008814ExprResult
John McCall454feb92009-12-08 09:21:05 +00008815TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008816 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008817
John McCallc6ac9c32011-02-04 18:33:18 +00008818 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8819 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8820
8821 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008822 blockScope->TheDecl->setBlockMissingReturnType(
8823 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008824
Chris Lattner686775d2011-07-20 06:58:45 +00008825 SmallVector<ParmVarDecl*, 4> params;
8826 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008827
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008828 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008829 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8830 oldBlock->param_begin(),
8831 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008832 0, paramTypes, &params)) {
8833 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008834 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008835 }
John McCallc6ac9c32011-02-04 18:33:18 +00008836
8837 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008838 QualType exprResultType =
8839 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008840
8841 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008842 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008843 getSema().Diag(E->getCaretLocation(),
8844 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008845 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008846 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008847 return ExprError();
8848 }
John McCall711c52b2011-01-05 12:14:39 +00008849
Jordan Rosebea522f2013-03-08 21:51:21 +00008850 QualType functionType =
8851 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
8852 oldBlock->isVariadic(),
8853 false, 0, RQ_None,
8854 exprFunctionType->getExtInfo());
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,
9073 bool Variadic,
9074 bool HasTrailingReturn,
9075 unsigned Quals,
9076 RefQualifierKind RefQualifier,
9077 const FunctionType::ExtInfo &Info) {
9078 return SemaRef.BuildFunctionType(T, ParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009079 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009080 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009081 getDerived().getBaseEntity(),
9082 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009083}
Mike Stump1eb44332009-09-09 15:08:12 +00009084
Douglas Gregor577f75a2009-08-04 16:50:30 +00009085template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009086QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9087 return SemaRef.Context.getFunctionNoProtoType(T);
9088}
9089
9090template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009091QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9092 assert(D && "no decl found");
9093 if (D->isInvalidDecl()) return QualType();
9094
Douglas Gregor92e986e2010-04-22 16:44:27 +00009095 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009096 TypeDecl *Ty;
9097 if (isa<UsingDecl>(D)) {
9098 UsingDecl *Using = cast<UsingDecl>(D);
9099 assert(Using->isTypeName() &&
9100 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9101
9102 // A valid resolved using typename decl points to exactly one type decl.
9103 assert(++Using->shadow_begin() == Using->shadow_end());
9104 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009105
John McCalled976492009-12-04 22:46:56 +00009106 } else {
9107 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9108 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9109 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9110 }
9111
9112 return SemaRef.Context.getTypeDeclType(Ty);
9113}
9114
9115template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009116QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9117 SourceLocation Loc) {
9118 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009119}
9120
9121template<typename Derived>
9122QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9123 return SemaRef.Context.getTypeOfType(Underlying);
9124}
9125
9126template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009127QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9128 SourceLocation Loc) {
9129 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009130}
9131
9132template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009133QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9134 UnaryTransformType::UTTKind UKind,
9135 SourceLocation Loc) {
9136 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9137}
9138
9139template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009140QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009141 TemplateName Template,
9142 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009143 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009144 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009145}
Mike Stump1eb44332009-09-09 15:08:12 +00009146
Douglas Gregordcee1a12009-08-06 05:28:30 +00009147template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009148QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9149 SourceLocation KWLoc) {
9150 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9151}
9152
9153template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009154TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009155TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009156 bool TemplateKW,
9157 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009158 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009159 Template);
9160}
9161
9162template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009163TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009164TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9165 const IdentifierInfo &Name,
9166 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009167 QualType ObjectType,
9168 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009169 UnqualifiedId TemplateName;
9170 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009171 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009172 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009173 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009174 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009175 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009176 /*EnteringContext=*/false,
9177 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009178 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009179}
Mike Stump1eb44332009-09-09 15:08:12 +00009180
Douglas Gregorb98b1992009-08-11 05:31:07 +00009181template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009182TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009183TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009184 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009185 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009186 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009187 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009188 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009189 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009190 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009191 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009192 Sema::TemplateTy Template;
9193 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009194 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009195 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009196 /*EnteringContext=*/false,
9197 Template);
9198 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009199}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009200
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009202ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009203TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9204 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009205 Expr *OrigCallee,
9206 Expr *First,
9207 Expr *Second) {
9208 Expr *Callee = OrigCallee->IgnoreParenCasts();
9209 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009210
Douglas Gregorb98b1992009-08-11 05:31:07 +00009211 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009212 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009213 if (!First->getType()->isOverloadableType() &&
9214 !Second->getType()->isOverloadableType())
9215 return getSema().CreateBuiltinArraySubscriptExpr(First,
9216 Callee->getLocStart(),
9217 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009218 } else if (Op == OO_Arrow) {
9219 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009220 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9221 } else if (Second == 0 || isPostIncDec) {
9222 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009223 // The argument is not of overloadable type, so try to create a
9224 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009225 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009226 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009227
John McCall9ae2f072010-08-23 23:25:46 +00009228 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009229 }
9230 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009231 if (!First->getType()->isOverloadableType() &&
9232 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 // Neither of the arguments is an overloadable type, so try to
9234 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009235 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009236 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009237 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009238 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009240
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009241 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009242 }
9243 }
Mike Stump1eb44332009-09-09 15:08:12 +00009244
9245 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009246 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009247 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009248
John McCall9ae2f072010-08-23 23:25:46 +00009249 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009250 assert(ULE->requiresADL());
9251
9252 // FIXME: Do we have to check
9253 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009254 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009255 } else {
Richard Smithf6411662012-11-28 21:47:39 +00009256 // If we've resolved this to a particular non-member function, just call
9257 // that function. If we resolved it to a member function,
9258 // CreateOverloaded* will find that function for us.
9259 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
9260 if (!isa<CXXMethodDecl>(ND))
9261 Functions.addDecl(ND);
John McCallba135432009-11-21 08:51:07 +00009262 }
Mike Stump1eb44332009-09-09 15:08:12 +00009263
Douglas Gregorb98b1992009-08-11 05:31:07 +00009264 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009265 Expr *Args[2] = { First, Second };
9266 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009267
Douglas Gregorb98b1992009-08-11 05:31:07 +00009268 // Create the overloaded operator invocation for unary operators.
9269 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009270 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009271 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009272 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009273 }
Mike Stump1eb44332009-09-09 15:08:12 +00009274
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009275 if (Op == OO_Subscript) {
9276 SourceLocation LBrace;
9277 SourceLocation RBrace;
9278
9279 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9280 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9281 LBrace = SourceLocation::getFromRawEncoding(
9282 NameLoc.CXXOperatorName.BeginOpNameLoc);
9283 RBrace = SourceLocation::getFromRawEncoding(
9284 NameLoc.CXXOperatorName.EndOpNameLoc);
9285 } else {
9286 LBrace = Callee->getLocStart();
9287 RBrace = OpLoc;
9288 }
9289
9290 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9291 First, Second);
9292 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009293
Douglas Gregorb98b1992009-08-11 05:31:07 +00009294 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009295 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009296 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009297 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9298 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009299 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009300
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009301 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009302}
Mike Stump1eb44332009-09-09 15:08:12 +00009303
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009304template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009305ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009306TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009307 SourceLocation OperatorLoc,
9308 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009309 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009310 TypeSourceInfo *ScopeType,
9311 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009312 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009313 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009314 QualType BaseType = Base->getType();
9315 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009316 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009317 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009318 !BaseType->getAs<PointerType>()->getPointeeType()
9319 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009320 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009321 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009322 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009323 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009324 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009325 /*FIXME?*/true);
9326 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009327
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009328 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009329 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9330 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9331 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9332 NameInfo.setNamedTypeInfo(DestroyedType);
9333
Richard Smith6314db92012-05-15 06:15:11 +00009334 // The scope type is now known to be a valid nested name specifier
9335 // component. Tack it on to the end of the nested name specifier.
9336 if (ScopeType)
9337 SS.Extend(SemaRef.Context, SourceLocation(),
9338 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009339
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009340 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009341 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009342 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009343 SS, TemplateKWLoc,
9344 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009345 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009346 /*TemplateArgs*/ 0);
9347}
9348
Douglas Gregor577f75a2009-08-04 16:50:30 +00009349} // end namespace clang
9350
9351#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H