blob: 5b6c112804673165046742ab7732e0b855010bf1 [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
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000101
Douglas Gregord3731192011-01-10 07:32:04 +0000102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000106
Douglas Gregord3731192011-01-10 07:32:04 +0000107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
Chad Rosier4a9d7952012-08-08 18:46:20 +0000111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000114
Douglas Gregordfca6f52012-02-13 22:00:16 +0000115 /// \brief The set of local declarations that have been transformed, for
116 /// cases where we are forced to build new declarations within the transformer
117 /// rather than in the subclass (e.g., lambda closure types).
118 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000119
Mike Stump1eb44332009-09-09 15:08:12 +0000120public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000121 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000122 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 /// \brief Retrieves a reference to the derived class.
125 Derived &getDerived() { return static_cast<Derived&>(*this); }
126
127 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000128 const Derived &getDerived() const {
129 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 }
131
John McCall60d7b3a2010-08-24 06:29:42 +0000132 static inline ExprResult Owned(Expr *E) { return E; }
133 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000134
Douglas Gregor577f75a2009-08-04 16:50:30 +0000135 /// \brief Retrieves a reference to the semantic analysis object used for
136 /// this tree transform.
137 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Whether the transformation should always rebuild AST nodes, even
140 /// if none of the children have changed.
141 ///
142 /// Subclasses may override this function to specify when the transformation
143 /// should rebuild all AST nodes.
144 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the location of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000149 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000150 /// provide an alternative implementation that provides better location
151 /// information.
152 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor577f75a2009-08-04 16:50:30 +0000154 /// \brief Returns the name of the entity being transformed, if that
155 /// information was not available elsewhere in the AST.
156 ///
157 /// By default, returns an empty name. Subclasses can provide an alternative
158 /// implementation with a more precise name.
159 DeclarationName getBaseEntity() { return DeclarationName(); }
160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief Sets the "base" location and entity when that
162 /// information is known based on another transformation.
163 ///
164 /// By default, the source location and entity are ignored. Subclasses can
165 /// override this function to provide a customized implementation.
166 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 /// \brief RAII object that temporarily sets the base location and entity
169 /// used for reporting diagnostics in types.
170 class TemporaryBase {
171 TreeTransform &Self;
172 SourceLocation OldLocation;
173 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 public:
176 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000177 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 OldLocation = Self.getDerived().getBaseLocation();
179 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000180
Douglas Gregorae201f72011-01-25 17:51:48 +0000181 if (Location.isValid())
182 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Douglas Gregorb98b1992009-08-11 05:31:07 +0000185 ~TemporaryBase() {
186 Self.getDerived().setBase(OldLocation, OldEntity);
187 }
188 };
Mike Stump1eb44332009-09-09 15:08:12 +0000189
190 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000191 /// transformed.
192 ///
193 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000194 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000195 /// not change. For example, template instantiation need not traverse
196 /// non-dependent types.
197 bool AlreadyTransformed(QualType T) {
198 return T.isNull();
199 }
200
Douglas Gregor6eef5192009-12-14 19:27:10 +0000201 /// \brief Determine whether the given call argument should be dropped, e.g.,
202 /// because it is a default argument.
203 ///
204 /// Subclasses can provide an alternative implementation of this routine to
205 /// determine which kinds of call arguments get dropped. By default,
206 /// CXXDefaultArgument nodes are dropped (prior to transformation).
207 bool DropCallArgument(Expr *E) {
208 return E->isDefaultArgument();
209 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000210
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// \brief Determine whether we should expand a pack expansion with the
212 /// given set of parameter packs into separate arguments by repeatedly
213 /// transforming the pattern.
214 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000215 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000216 /// Subclasses can override this routine to provide different behavior.
217 ///
218 /// \param EllipsisLoc The location of the ellipsis that identifies the
219 /// pack expansion.
220 ///
221 /// \param PatternRange The source range that covers the entire pattern of
222 /// the pack expansion.
223 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000224 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000225 /// pattern.
226 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000227 /// \param ShouldExpand Will be set to \c true if the transformer should
228 /// expand the corresponding pack expansions into separate arguments. When
229 /// set, \c NumExpansions must also be set.
230 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000231 /// \param RetainExpansion Whether the caller should add an unexpanded
232 /// pack expansion after all of the expanded arguments. This is used
233 /// when extending explicitly-specified template argument packs per
234 /// C++0x [temp.arg.explicit]p9.
235 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000237 /// the expanded form of the corresponding pack expansion. This is both an
238 /// input and an output parameter, which can be set by the caller if the
239 /// number of expansions is known a priori (e.g., due to a prior substitution)
240 /// and will be set by the callee when the number of expansions is known.
241 /// The callee must set this value when \c ShouldExpand is \c true; it may
242 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000244 /// \returns true if an error occurred (e.g., because the parameter packs
245 /// are to be instantiated with arguments of different lengths), false
246 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000247 /// must be set.
248 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
249 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000250 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000252 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000253 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000254 ShouldExpand = false;
255 return false;
256 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000257
Douglas Gregord3731192011-01-10 07:32:04 +0000258 /// \brief "Forget" about the partially-substituted pack template argument,
259 /// when performing an instantiation that must preserve the parameter pack
260 /// use.
261 ///
262 /// This routine is meant to be overridden by the template instantiator.
263 TemplateArgument ForgetPartiallySubstitutedPack() {
264 return TemplateArgument();
265 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000266
Douglas Gregord3731192011-01-10 07:32:04 +0000267 /// \brief "Remember" the partially-substituted pack template argument
268 /// after performing an instantiation that must preserve the parameter pack
269 /// use.
270 ///
271 /// This routine is meant to be overridden by the template instantiator.
272 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000273
Douglas Gregor12c9c002011-01-07 16:43:16 +0000274 /// \brief Note to the derived class when a function parameter pack is
275 /// being expanded.
276 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000277
Douglas Gregor577f75a2009-08-04 16:50:30 +0000278 /// \brief Transforms the given type into another type.
279 ///
John McCalla2becad2009-10-21 00:40:46 +0000280 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000281 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000282 /// function. This is expensive, but we don't mind, because
283 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000284 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
286 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000287 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000288
John McCalla2becad2009-10-21 00:40:46 +0000289 /// \brief Transforms the given type-with-location into a new
290 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 ///
John McCalla2becad2009-10-21 00:40:46 +0000292 /// By default, this routine transforms a type by delegating to the
293 /// appropriate TransformXXXType to build a new type. Subclasses
294 /// may override this function (to take over all type
295 /// transformations) or some set of the TransformXXXType functions
296 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000297 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000298
299 /// \brief Transform the given type-with-location into a new
300 /// type, collecting location information in the given builder
301 /// as necessary.
302 ///
John McCall43fed0d2010-11-12 08:19:04 +0000303 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000305 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000306 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000307 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000308 /// appropriate TransformXXXStmt function to transform a specific kind of
309 /// statement or the TransformExpr() function to transform an expression.
310 /// Subclasses may override this function to transform statements using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000316 /// \brief Transform the given expression.
317 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000318 /// By default, this routine transforms an expression by delegating to the
319 /// appropriate TransformXXXExpr function to build a new expression.
320 /// Subclasses may override this function to transform expressions using some
321 /// other mechanism.
322 ///
323 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000324 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregoraa165f82011-01-03 19:04:46 +0000326 /// \brief Transform the given list of expressions.
327 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000328 /// This routine transforms a list of expressions by invoking
329 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregoraa165f82011-01-03 19:04:46 +0000330 /// support for variadic templates by expanding any pack expansions (if the
331 /// derived class permits such expansion) along the way. When pack expansions
332 /// are present, the number of outputs may not equal the number of inputs.
333 ///
334 /// \param Inputs The set of expressions to be transformed.
335 ///
336 /// \param NumInputs The number of expressions in \c Inputs.
337 ///
338 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier4a9d7952012-08-08 18:46:20 +0000339 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregoraa165f82011-01-03 19:04:46 +0000340 /// be.
341 ///
342 /// \param Outputs The transformed input expressions will be added to this
343 /// vector.
344 ///
345 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
346 /// due to transformation.
347 ///
348 /// \returns true if an error occurred, false otherwise.
349 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000350 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000351 bool *ArgChanged = 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000352
Douglas Gregor577f75a2009-08-04 16:50:30 +0000353 /// \brief Transform the given declaration, which is referenced from a type
354 /// or expression.
355 ///
Douglas Gregordfca6f52012-02-13 22:00:16 +0000356 /// By default, acts as the identity function on declarations, unless the
357 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregordcee1a12009-08-06 05:28:30 +0000358 /// may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000359 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregordfca6f52012-02-13 22:00:16 +0000360 llvm::DenseMap<Decl *, Decl *>::iterator Known
361 = TransformedLocalDecls.find(D);
362 if (Known != TransformedLocalDecls.end())
363 return Known->second;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000364
365 return D;
Douglas Gregordfca6f52012-02-13 22:00:16 +0000366 }
Douglas Gregor43959a92009-08-20 07:17:43 +0000367
Chad Rosier4a9d7952012-08-08 18:46:20 +0000368 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregordfca6f52012-02-13 22:00:16 +0000369 /// place them on the new declaration.
370 ///
371 /// By default, this operation does nothing. Subclasses may override this
372 /// behavior to transform attributes.
373 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000374
Douglas Gregordfca6f52012-02-13 22:00:16 +0000375 /// \brief Note that a local declaration has been transformed by this
376 /// transformer.
377 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000378 /// Local declarations are typically transformed via a call to
Douglas Gregordfca6f52012-02-13 22:00:16 +0000379 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
380 /// the transformer itself has to transform the declarations. This routine
381 /// can be overridden by a subclass that keeps track of such mappings.
382 void transformedLocalDecl(Decl *Old, Decl *New) {
383 TransformedLocalDecls[Old] = New;
384 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000385
Douglas Gregor43959a92009-08-20 07:17:43 +0000386 /// \brief Transform the definition of the given declaration.
387 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000388 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000389 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000390 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
391 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000392 }
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor6cd21982009-10-20 05:58:46 +0000394 /// \brief Transform the given declaration, which was the first part of a
395 /// nested-name-specifier in a member access expression.
396 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000397 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000398 /// identifier in a nested-name-specifier of a member access expression, e.g.,
399 /// the \c T in \c x->T::member
400 ///
401 /// By default, invokes TransformDecl() to transform the declaration.
402 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000403 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
404 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000405 }
Chad Rosier4a9d7952012-08-08 18:46:20 +0000406
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000407 /// \brief Transform the given nested-name-specifier with source-location
408 /// information.
409 ///
410 /// By default, transforms all of the types and declarations within the
411 /// nested-name-specifier. Subclasses may override this function to provide
412 /// alternate behavior.
413 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
414 NestedNameSpecifierLoc NNS,
415 QualType ObjectType = QualType(),
416 NamedDecl *FirstQualifierInScope = 0);
417
Douglas Gregor81499bb2009-09-03 22:13:48 +0000418 /// \brief Transform the given declaration name.
419 ///
420 /// By default, transforms the types of conversion function, constructor,
421 /// and destructor names and then (if needed) rebuilds the declaration name.
422 /// Identifiers and selectors are returned unmodified. Sublcasses may
423 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000424 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000425 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000426
Douglas Gregor577f75a2009-08-04 16:50:30 +0000427 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000428 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000429 /// \param SS The nested-name-specifier that qualifies the template
430 /// name. This nested-name-specifier must already have been transformed.
431 ///
432 /// \param Name The template name to transform.
433 ///
434 /// \param NameLoc The source location of the template name.
435 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000436 /// \param ObjectType If we're translating a template name within a member
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000437 /// access expression, this is the type of the object whose member template
438 /// is being referenced.
439 ///
440 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
441 /// also refers to a name within the current (lexical) scope, this is the
442 /// declaration it refers to.
443 ///
444 /// By default, transforms the template name by transforming the declarations
445 /// and nested-name-specifiers that occur within the template name.
446 /// Subclasses may override this function to provide alternate behavior.
447 TemplateName TransformTemplateName(CXXScopeSpec &SS,
448 TemplateName Name,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000449 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000450 QualType ObjectType = QualType(),
451 NamedDecl *FirstQualifierInScope = 0);
452
Douglas Gregor577f75a2009-08-04 16:50:30 +0000453 /// \brief Transform the given template argument.
454 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000455 /// By default, this operation transforms the type, expression, or
456 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000457 /// new template argument from the transformed result. Subclasses may
458 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000459 ///
460 /// Returns true if there was an error.
461 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
462 TemplateArgumentLoc &Output);
463
Douglas Gregorfcc12532010-12-20 17:31:10 +0000464 /// \brief Transform the given set of template arguments.
465 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000466 /// By default, this operation transforms all of the template arguments
Douglas Gregorfcc12532010-12-20 17:31:10 +0000467 /// in the input set using \c TransformTemplateArgument(), and appends
468 /// the transformed arguments to the output list.
469 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000470 /// Note that this overload of \c TransformTemplateArguments() is merely
471 /// a convenience function. Subclasses that wish to override this behavior
472 /// should override the iterator-based member template version.
473 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000474 /// \param Inputs The set of template arguments to be transformed.
475 ///
476 /// \param NumInputs The number of template arguments in \p Inputs.
477 ///
478 /// \param Outputs The set of transformed template arguments output by this
479 /// routine.
480 ///
481 /// Returns true if an error occurred.
482 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
483 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000484 TemplateArgumentListInfo &Outputs) {
485 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
486 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000487
488 /// \brief Transform the given set of template arguments.
489 ///
Chad Rosier4a9d7952012-08-08 18:46:20 +0000490 /// By default, this operation transforms all of the template arguments
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000491 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier4a9d7952012-08-08 18:46:20 +0000492 /// the transformed arguments to the output list.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000493 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000494 /// \param First An iterator to the first template argument.
495 ///
496 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000497 ///
498 /// \param Outputs The set of transformed template arguments output by this
499 /// routine.
500 ///
501 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000502 template<typename InputIterator>
503 bool TransformTemplateArguments(InputIterator First,
504 InputIterator Last,
505 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000506
John McCall833ca992009-10-29 08:12:44 +0000507 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
508 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
509 TemplateArgumentLoc &ArgLoc);
510
John McCalla93c9342009-12-07 02:54:59 +0000511 /// \brief Fakes up a TypeSourceInfo for a type.
512 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
513 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000514 getDerived().getBaseLocation());
515 }
Mike Stump1eb44332009-09-09 15:08:12 +0000516
John McCalla2becad2009-10-21 00:40:46 +0000517#define ABSTRACT_TYPELOC(CLASS, PARENT)
518#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000520#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
Douglas Gregorcefc3af2012-04-16 07:05:22 +0000522 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
523 FunctionProtoTypeLoc TL,
524 CXXRecordDecl *ThisContext,
525 unsigned ThisTypeQuals);
526
John Wiegley28bbe4b2011-04-28 01:08:34 +0000527 StmtResult
528 TransformSEHHandler(Stmt *Handler);
529
Chad Rosier4a9d7952012-08-08 18:46:20 +0000530 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000531 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
532 TemplateSpecializationTypeLoc TL,
533 TemplateName Template);
534
Chad Rosier4a9d7952012-08-08 18:46:20 +0000535 QualType
John McCall43fed0d2010-11-12 08:19:04 +0000536 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
537 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000538 TemplateName Template,
539 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000540
Chad Rosier4a9d7952012-08-08 18:46:20 +0000541 QualType
Douglas Gregora88f09f2011-02-28 17:23:35 +0000542 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000543 DependentTemplateSpecializationTypeLoc TL,
544 NestedNameSpecifierLoc QualifierLoc);
545
John McCall21ef0fa2010-03-11 09:03:00 +0000546 /// \brief Transforms the parameters of a function type into the
547 /// given vectors.
548 ///
549 /// The result vectors should be kept in sync; null entries in the
550 /// variables vector are acceptable.
551 ///
552 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000553 bool TransformFunctionTypeParams(SourceLocation Loc,
554 ParmVarDecl **Params, unsigned NumParams,
555 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000556 SmallVectorImpl<QualType> &PTypes,
557 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000558
559 /// \brief Transforms a single function-type parameter. Return null
560 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000561 ///
562 /// \param indexAdjustment - A number to add to the parameter's
563 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000564 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000565 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +0000566 llvm::Optional<unsigned> NumExpansions,
567 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000568
John McCall43fed0d2010-11-12 08:19:04 +0000569 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000570
John McCall60d7b3a2010-08-24 06:29:42 +0000571 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
572 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Richard Smith612409e2012-07-25 03:56:55 +0000574 /// \brief Transform the captures and body of a lambda expression.
575 ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator);
576
Douglas Gregor43959a92009-08-20 07:17:43 +0000577#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000578 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000579#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000580 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000581#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000582#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Douglas Gregor577f75a2009-08-04 16:50:30 +0000584 /// \brief Build a new pointer type given its pointee type.
585 ///
586 /// By default, performs semantic analysis when building the pointer type.
587 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000588 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589
590 /// \brief Build a new block pointer type given its pointee type.
591 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000594 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
John McCall85737a72009-10-30 00:06:24 +0000596 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597 ///
John McCall85737a72009-10-30 00:06:24 +0000598 /// By default, performs semantic analysis when building the
599 /// reference type. Subclasses may override this routine to provide
600 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000601 ///
John McCall85737a72009-10-30 00:06:24 +0000602 /// \param LValue whether the type was written with an lvalue sigil
603 /// or an rvalue sigil.
604 QualType RebuildReferenceType(QualType ReferentType,
605 bool LValue,
606 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000607
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608 /// \brief Build a new member pointer type given the pointee type and the
609 /// class type it refers into.
610 ///
611 /// By default, performs semantic analysis when building the member pointer
612 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000613 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
614 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000615
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// \brief Build a new array type given the element type, size
617 /// modifier, size of the array (if known), size expression, and index type
618 /// qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 QualType RebuildArrayType(QualType ElementType,
624 ArrayType::ArraySizeModifier SizeMod,
625 const llvm::APInt *Size,
626 Expr *SizeExpr,
627 unsigned IndexTypeQuals,
628 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000629
Douglas Gregor577f75a2009-08-04 16:50:30 +0000630 /// \brief Build a new constant array type given the element type, size
631 /// modifier, (known) size of the array, and index type 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 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 ArrayType::ArraySizeModifier SizeMod,
637 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000638 unsigned IndexTypeQuals,
639 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000640
Douglas Gregor577f75a2009-08-04 16:50:30 +0000641 /// \brief Build a new incomplete array type given the element type, size
642 /// modifier, and index type qualifiers.
643 ///
644 /// By default, performs semantic analysis when building the array type.
645 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000646 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000647 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000648 unsigned IndexTypeQuals,
649 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000650
Mike Stump1eb44332009-09-09 15:08:12 +0000651 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000652 /// size modifier, size expression, and index type qualifiers.
653 ///
654 /// By default, performs semantic analysis when building the array type.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000656 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000657 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned IndexTypeQuals,
660 SourceRange BracketsRange);
661
Mike Stump1eb44332009-09-09 15:08:12 +0000662 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// size modifier, size expression, and index type qualifiers.
664 ///
665 /// By default, performs semantic analysis when building the array type.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000669 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 unsigned IndexTypeQuals,
671 SourceRange BracketsRange);
672
673 /// \brief Build a new vector type given the element type and
674 /// number of elements.
675 ///
676 /// By default, performs semantic analysis when building the vector type.
677 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000678 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000679 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new extended vector type given the element type and
682 /// number of elements.
683 ///
684 /// By default, performs semantic analysis when building the vector type.
685 /// Subclasses may override this routine to provide different behavior.
686 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
687 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000688
689 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 /// given the element type and number of elements.
691 ///
692 /// By default, performs semantic analysis when building the vector type.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000694 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000695 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 /// \brief Build a new function type.
699 ///
700 /// By default, performs semantic analysis when building the function type.
701 /// Subclasses may override this routine to provide different behavior.
702 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000703 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000704 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000705 bool Variadic, bool HasTrailingReturn,
706 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000707 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000708 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000709
John McCalla2becad2009-10-21 00:40:46 +0000710 /// \brief Build a new unprototyped function type.
711 QualType RebuildFunctionNoProtoType(QualType ResultType);
712
John McCalled976492009-12-04 22:46:56 +0000713 /// \brief Rebuild an unresolved typename type, given the decl that
714 /// the UnresolvedUsingTypenameDecl was transformed to.
715 QualType RebuildUnresolvedUsingType(Decl *D);
716
Douglas Gregor577f75a2009-08-04 16:50:30 +0000717 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000718 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 return SemaRef.Context.getTypeDeclType(Typedef);
720 }
721
722 /// \brief Build a new class/struct/union type.
723 QualType RebuildRecordType(RecordDecl *Record) {
724 return SemaRef.Context.getTypeDeclType(Record);
725 }
726
727 /// \brief Build a new Enum type.
728 QualType RebuildEnumType(EnumDecl *Enum) {
729 return SemaRef.Context.getTypeDeclType(Enum);
730 }
John McCall7da24312009-09-05 00:15:47 +0000731
Mike Stump1eb44332009-09-09 15:08:12 +0000732 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733 ///
734 /// By default, performs semantic analysis when building the typeof type.
735 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000736 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000737
Mike Stump1eb44332009-09-09 15:08:12 +0000738 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000739 ///
740 /// By default, builds a new TypeOfType with the given underlying type.
741 QualType RebuildTypeOfType(QualType Underlying);
742
Sean Huntca63c202011-05-24 22:41:36 +0000743 /// \brief Build a new unary transform type.
744 QualType RebuildUnaryTransformType(QualType BaseType,
745 UnaryTransformType::UTTKind UKind,
746 SourceLocation Loc);
747
Mike Stump1eb44332009-09-09 15:08:12 +0000748 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000749 ///
750 /// By default, performs semantic analysis when building the decltype type.
751 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000752 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Richard Smith34b41d92011-02-20 03:19:35 +0000754 /// \brief Build a new C++0x auto type.
755 ///
756 /// By default, builds a new AutoType with the given deduced type.
757 QualType RebuildAutoType(QualType Deduced) {
758 return SemaRef.Context.getAutoType(Deduced);
759 }
760
Douglas Gregor577f75a2009-08-04 16:50:30 +0000761 /// \brief Build a new template specialization type.
762 ///
763 /// By default, performs semantic analysis when building the template
764 /// specialization type. Subclasses may override this routine to provide
765 /// different behavior.
766 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000767 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000768 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000769
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000770 /// \brief Build a new parenthesized type.
771 ///
772 /// By default, builds a new ParenType type from the inner type.
773 /// Subclasses may override this routine to provide different behavior.
774 QualType RebuildParenType(QualType InnerType) {
775 return SemaRef.Context.getParenType(InnerType);
776 }
777
Douglas Gregor577f75a2009-08-04 16:50:30 +0000778 /// \brief Build a new qualified name type.
779 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000780 /// By default, builds a new ElaboratedType type from the keyword,
781 /// the nested-name-specifier and the named type.
782 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000783 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
784 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000785 NestedNameSpecifierLoc QualifierLoc,
786 QualType Named) {
Chad Rosier4a9d7952012-08-08 18:46:20 +0000787 return SemaRef.Context.getElaboratedType(Keyword,
788 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor9e876872011-03-01 18:12:44 +0000789 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000790 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000791
792 /// \brief Build a new typename type that refers to a template-id.
793 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 /// By default, builds a new DependentNameType type from the
795 /// nested-name-specifier and the given type. Subclasses may override
796 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000797 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000798 ElaboratedTypeKeyword Keyword,
799 NestedNameSpecifierLoc QualifierLoc,
800 const IdentifierInfo *Name,
801 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000802 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000803 // Rebuild the template name.
804 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000805 CXXScopeSpec SS;
806 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000807 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000808 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000809
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000810 if (InstName.isNull())
811 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000812
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000813 // If it's still dependent, make a dependent specialization.
814 if (InstName.getAsDependentTemplateName())
Chad Rosier4a9d7952012-08-08 18:46:20 +0000815 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
816 QualifierLoc.getNestedNameSpecifier(),
817 Name,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000818 Args);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000819
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000820 // Otherwise, make an elaborated type wrapping a non-dependent
821 // specialization.
822 QualType T =
823 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
824 if (T.isNull()) return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +0000825
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000826 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
827 return T;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000828
829 return SemaRef.Context.getElaboratedType(Keyword,
830 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000831 T);
832 }
833
Douglas Gregor577f75a2009-08-04 16:50:30 +0000834 /// \brief Build a new typename type that refers to an identifier.
835 ///
836 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000837 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000838 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000839 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000840 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000841 NestedNameSpecifierLoc QualifierLoc,
842 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000843 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000844 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000845 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000846
Douglas Gregor2494dd02011-03-01 01:34:45 +0000847 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000848 // If the name is still dependent, just build a new dependent name type.
849 if (!SemaRef.computeDeclContext(SS))
Chad Rosier4a9d7952012-08-08 18:46:20 +0000850 return SemaRef.Context.getDependentNameType(Keyword,
851 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000852 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000853 }
854
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000855 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000856 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000857 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000858
859 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
860
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000861 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000862 // into a non-dependent elaborated-type-specifier. Find the tag we're
863 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000864 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000865 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
866 if (!DC)
867 return QualType();
868
John McCall56138762010-05-27 06:40:31 +0000869 if (SemaRef.RequireCompleteDeclContext(SS, DC))
870 return QualType();
871
Douglas Gregor40336422010-03-31 22:19:08 +0000872 TagDecl *Tag = 0;
873 SemaRef.LookupQualifiedName(Result, DC);
874 switch (Result.getResultKind()) {
875 case LookupResult::NotFound:
876 case LookupResult::NotFoundInCurrentInstantiation:
877 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000878
Douglas Gregor40336422010-03-31 22:19:08 +0000879 case LookupResult::Found:
880 Tag = Result.getAsSingle<TagDecl>();
881 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +0000882
Douglas Gregor40336422010-03-31 22:19:08 +0000883 case LookupResult::FoundOverloaded:
884 case LookupResult::FoundUnresolvedValue:
885 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier4a9d7952012-08-08 18:46:20 +0000886
Douglas Gregor40336422010-03-31 22:19:08 +0000887 case LookupResult::Ambiguous:
888 // Let the LookupResult structure handle ambiguities.
889 return QualType();
890 }
891
892 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000893 // Check where the name exists but isn't a tag type and use that to emit
894 // better diagnostics.
895 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
896 SemaRef.LookupQualifiedName(Result, DC);
897 switch (Result.getResultKind()) {
898 case LookupResult::Found:
899 case LookupResult::FoundOverloaded:
900 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000901 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000902 unsigned Kind = 0;
903 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000904 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
905 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000906 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
907 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
908 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000909 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000910 default:
911 // FIXME: Would be nice to highlight just the source range.
912 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
913 << Kind << Id << DC;
914 break;
915 }
Douglas Gregor40336422010-03-31 22:19:08 +0000916 return QualType();
917 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000918
Richard Trieubbf34c02011-06-10 03:11:26 +0000919 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
920 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000921 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000922 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
923 return QualType();
924 }
925
926 // Build the elaborated-type-specifier type.
927 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier4a9d7952012-08-08 18:46:20 +0000928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor2494dd02011-03-01 01:34:45 +0000930 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000931 }
Mike Stump1eb44332009-09-09 15:08:12 +0000932
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000933 /// \brief Build a new pack expansion type.
934 ///
935 /// By default, builds a new PackExpansionType type from the given pattern.
936 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +0000937 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000938 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000939 SourceLocation EllipsisLoc,
940 llvm::Optional<unsigned> NumExpansions) {
941 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
942 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000943 }
944
Eli Friedmanb001de72011-10-06 23:00:33 +0000945 /// \brief Build a new atomic type given its value type.
946 ///
947 /// By default, performs semantic analysis when building the atomic type.
948 /// Subclasses may override this routine to provide different behavior.
949 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
950
Douglas Gregord1067e52009-08-06 06:41:21 +0000951 /// \brief Build a new template name given a nested name specifier, a flag
952 /// indicating whether the "template" keyword was provided, and the template
953 /// that the template name refers to.
954 ///
955 /// By default, builds the new template name directly. Subclasses may override
956 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000957 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000958 bool TemplateKW,
959 TemplateDecl *Template);
960
Douglas Gregord1067e52009-08-06 06:41:21 +0000961 /// \brief Build a new template name given a nested name specifier and the
962 /// name that is referred to as a template.
963 ///
964 /// By default, performs semantic analysis to determine whether the name can
965 /// be resolved to a specific template, then builds the appropriate kind of
966 /// template name. Subclasses may override this routine to provide different
967 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000968 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
969 const IdentifierInfo &Name,
970 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000971 QualType ObjectType,
972 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000974 /// \brief Build a new template name given a nested name specifier and the
975 /// overloaded operator name that is referred to as a template.
976 ///
977 /// By default, performs semantic analysis to determine whether the name can
978 /// be resolved to a specific template, then builds the appropriate kind of
979 /// template name. Subclasses may override this routine to provide different
980 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000981 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000982 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000983 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000984 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000985
986 /// \brief Build a new template name given a template template parameter pack
Chad Rosier4a9d7952012-08-08 18:46:20 +0000987 /// and the
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000988 ///
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.
993 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
994 const TemplateArgument &ArgPack) {
995 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
996 }
997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new compound statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 MultiStmtArg Statements,
1004 SourceLocation RBraceLoc,
1005 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +00001006 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 IsStmtExpr);
1008 }
1009
1010 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001015 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001017 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001019 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 ColonLoc);
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 /// \brief Attach the body to a new case statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001027 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001028 getSema().ActOnCaseStmtBody(S, Body);
1029 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new default statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001038 Stmt *SubStmt) {
1039 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001040 /*CurScope=*/0);
1041 }
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Douglas Gregor43959a92009-08-20 07:17:43 +00001043 /// \brief Build a new label statement.
1044 ///
1045 /// By default, performs semantic analysis to build the new statement.
1046 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001047 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1048 SourceLocation ColonLoc, Stmt *SubStmt) {
1049 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Richard Smith534986f2012-04-14 00:33:13 +00001052 /// \brief Build a new label statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko49908902012-07-09 10:04:07 +00001056 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1057 ArrayRef<const Attr*> Attrs,
Richard Smith534986f2012-04-14 00:33:13 +00001058 Stmt *SubStmt) {
1059 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1060 }
1061
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 /// \brief Build a new "if" statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001066 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001067 VarDecl *CondVar, Stmt *Then,
Chris Lattner57ad3782011-02-17 20:34:02 +00001068 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001069 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 }
Mike Stump1eb44332009-09-09 15:08:12 +00001071
Douglas Gregor43959a92009-08-20 07:17:43 +00001072 /// \brief Start building a new switch statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001076 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001077 Expr *Cond, VarDecl *CondVar) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001078 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001079 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001080 }
Mike Stump1eb44332009-09-09 15:08:12 +00001081
Douglas Gregor43959a92009-08-20 07:17:43 +00001082 /// \brief Attach the body to the switch statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001086 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001087 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001088 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 }
1090
1091 /// \brief Build a new while statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001095 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1096 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001097 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 }
Mike Stump1eb44332009-09-09 15:08:12 +00001099
Douglas Gregor43959a92009-08-20 07:17:43 +00001100 /// \brief Build a new do-while statement.
1101 ///
1102 /// By default, performs semantic analysis to build the new statement.
1103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001104 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001105 SourceLocation WhileLoc, SourceLocation LParenLoc,
1106 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001107 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1108 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 }
1110
1111 /// \brief Build a new for statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001115 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier4a9d7952012-08-08 18:46:20 +00001116 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001117 VarDecl *CondVar, Sema::FullExprArg Inc,
1118 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001119 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001120 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001121 }
Mike Stump1eb44332009-09-09 15:08:12 +00001122
Douglas Gregor43959a92009-08-20 07:17:43 +00001123 /// \brief Build a new goto 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 RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1128 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001129 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001130 }
1131
1132 /// \brief Build a new indirect goto statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001137 SourceLocation StarLoc,
1138 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001139 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001140 }
Mike Stump1eb44332009-09-09 15:08:12 +00001141
Douglas Gregor43959a92009-08-20 07:17:43 +00001142 /// \brief Build a new return statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001146 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001147 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001148 }
Mike Stump1eb44332009-09-09 15:08:12 +00001149
Douglas Gregor43959a92009-08-20 07:17:43 +00001150 /// \brief Build a new declaration statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001155 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001156 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001157 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1158 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001159 }
Mike Stump1eb44332009-09-09 15:08:12 +00001160
Anders Carlsson703e3942010-01-24 05:50:09 +00001161 /// \brief Build a new inline asm statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001166 bool IsSimple,
1167 bool IsVolatile,
1168 unsigned NumOutputs,
1169 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001170 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001171 MultiExprArg Constraints,
1172 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001173 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001174 MultiExprArg Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00001175 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001176 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001177 NumInputs, Names, Constraints,
John McCall9ae2f072010-08-23 23:25:46 +00001178 Exprs, AsmString, Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00001179 RParenLoc);
Anders Carlsson703e3942010-01-24 05:50:09 +00001180 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181
Chad Rosier8cd64b42012-06-11 20:47:18 +00001182 /// \brief Build a new MS style inline asm statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
1186 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
Chad Rosier7bd092b2012-08-15 16:53:30 +00001187 SourceLocation LBraceLoc,
Chad Rosier79efe242012-08-07 00:29:06 +00001188 ArrayRef<Token> AsmToks,
Chad Rosier8cd64b42012-06-11 20:47:18 +00001189 SourceLocation EndLoc) {
Chad Rosier7bd092b2012-08-15 16:53:30 +00001190 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
Chad Rosier8cd64b42012-06-11 20:47:18 +00001191 }
1192
James Dennett699c9042012-06-15 07:13:21 +00001193 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001198 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001199 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001200 Stmt *Finally) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001201 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001202 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001203 }
1204
Douglas Gregorbe270a02010-04-26 17:57:08 +00001205 /// \brief Rebuild an Objective-C exception declaration.
1206 ///
1207 /// By default, performs semantic analysis to build the new declaration.
1208 /// Subclasses may override this routine to provide different behavior.
1209 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1210 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001211 return getSema().BuildObjCExceptionDecl(TInfo, T,
1212 ExceptionDecl->getInnerLocStart(),
1213 ExceptionDecl->getLocation(),
1214 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001215 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001216
James Dennett699c9042012-06-15 07:13:21 +00001217 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001221 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001222 SourceLocation RParenLoc,
1223 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001224 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001225 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001226 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001227 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001228
James Dennett699c9042012-06-15 07:13:21 +00001229 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001234 Stmt *Body) {
1235 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001237
James Dennett699c9042012-06-15 07:13:21 +00001238 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001242 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001243 Expr *Operand) {
1244 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001245 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001246
James Dennett699c9042012-06-15 07:13:21 +00001247 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCall07524032011-07-27 21:50:02 +00001248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
1251 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1252 Expr *object) {
1253 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1254 }
1255
James Dennett699c9042012-06-15 07:13:21 +00001256 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001257 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001258 /// By default, performs semantic analysis to build the new statement.
1259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001260 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001261 Expr *Object, Stmt *Body) {
1262 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001263 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001264
James Dennett699c9042012-06-15 07:13:21 +00001265 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCallf85e1932011-06-15 23:02:42 +00001266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
1269 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1270 Stmt *Body) {
1271 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1272 }
John McCall990567c2011-07-27 01:07:15 +00001273
Douglas Gregorc3203e72010-04-22 23:10:45 +00001274 /// \brief Build a new Objective-C fast enumeration statement.
1275 ///
1276 /// By default, performs semantic analysis to build the new statement.
1277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001278 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001279 Stmt *Element,
1280 Expr *Collection,
1281 SourceLocation RParenLoc,
1282 Stmt *Body) {
Sam Panzerbc20bbb2012-08-16 21:47:25 +00001283 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001284 Element,
John McCall9ae2f072010-08-23 23:25:46 +00001285 Collection,
Fariborz Jahaniana1eec4b2012-07-03 22:00:52 +00001286 RParenLoc);
1287 if (ForEachStmt.isInvalid())
1288 return StmtError();
1289
1290 return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001291 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001292
Douglas Gregor43959a92009-08-20 07:17:43 +00001293 /// \brief Build a new C++ exception declaration.
1294 ///
1295 /// By default, performs semantic analysis to build the new decaration.
1296 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001297 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001298 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001299 SourceLocation StartLoc,
1300 SourceLocation IdLoc,
1301 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001302 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1303 StartLoc, IdLoc, Id);
1304 if (Var)
1305 getSema().CurContext->addDecl(Var);
1306 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001307 }
1308
1309 /// \brief Build a new C++ catch statement.
1310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001313 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001314 VarDecl *ExceptionDecl,
1315 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001316 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1317 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001318 }
Mike Stump1eb44332009-09-09 15:08:12 +00001319
Douglas Gregor43959a92009-08-20 07:17:43 +00001320 /// \brief Build a new C++ try statement.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001324 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001325 Stmt *TryBlock,
1326 MultiStmtArg Handlers) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001327 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00001328 }
Mike Stump1eb44332009-09-09 15:08:12 +00001329
Richard Smithad762fc2011-04-14 22:09:26 +00001330 /// \brief Build a new C++0x range-based for statement.
1331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
1334 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1335 SourceLocation ColonLoc,
1336 Stmt *Range, Stmt *BeginEnd,
1337 Expr *Cond, Expr *Inc,
1338 Stmt *LoopVar,
1339 SourceLocation RParenLoc) {
1340 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Sam Panzere1715b62012-08-21 00:52:01 +00001341 Cond, Inc, LoopVar, RParenLoc, false);
Richard Smithad762fc2011-04-14 22:09:26 +00001342 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001343
1344 /// \brief Build a new C++0x range-based for statement.
1345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001348 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregorba0513d2011-10-25 01:33:02 +00001349 bool IsIfExists,
1350 NestedNameSpecifierLoc QualifierLoc,
1351 DeclarationNameInfo NameInfo,
1352 Stmt *Nested) {
1353 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1354 QualifierLoc, NameInfo, Nested);
1355 }
1356
Richard Smithad762fc2011-04-14 22:09:26 +00001357 /// \brief Attach body to a C++0x range-based for statement.
1358 ///
1359 /// By default, performs semantic analysis to finish the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1361 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1362 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1363 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001364
John Wiegley28bbe4b2011-04-28 01:08:34 +00001365 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1366 SourceLocation TryLoc,
1367 Stmt *TryBlock,
1368 Stmt *Handler) {
1369 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1370 }
1371
1372 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1373 Expr *FilterExpr,
1374 Stmt *Block) {
1375 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1376 }
1377
1378 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1379 Stmt *Block) {
1380 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1381 }
1382
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// \brief Build a new expression that references a declaration.
1384 ///
1385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001388 LookupResult &R,
1389 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001390 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1391 }
1392
1393
1394 /// \brief Build a new expression that references a declaration.
1395 ///
1396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001398 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001399 ValueDecl *VD,
1400 const DeclarationNameInfo &NameInfo,
1401 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001402 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001403 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001404
1405 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001406
1407 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 }
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001411 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001414 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001416 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 }
1418
Douglas Gregora71d8192009-09-04 17:36:40 +00001419 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001420 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001423 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001424 SourceLocation OperatorLoc,
1425 bool isArrow,
1426 CXXScopeSpec &SS,
1427 TypeSourceInfo *ScopeType,
1428 SourceLocation CCLoc,
1429 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001430 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001433 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001436 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001437 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001438 Expr *SubExpr) {
1439 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 }
Mike Stump1eb44332009-09-09 15:08:12 +00001441
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001442 /// \brief Build a new builtin offsetof expression.
1443 ///
1444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001446 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001447 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001448 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001449 unsigned NumComponents,
1450 SourceLocation RParenLoc) {
1451 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1452 NumComponents, RParenLoc);
1453 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00001454
1455 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001456 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001457 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001460 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1461 SourceLocation OpLoc,
1462 UnaryExprOrTypeTrait ExprKind,
1463 SourceRange R) {
1464 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 }
1466
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001467 /// \brief Build a new sizeof, alignof or vec step expression with an
1468 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001469 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001472 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1473 UnaryExprOrTypeTrait ExprKind,
1474 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001475 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001476 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001478 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001480 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001481 }
Mike Stump1eb44332009-09-09 15:08:12 +00001482
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001484 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001487 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001489 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001491 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1492 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 RBracketLoc);
1494 }
1495
1496 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001497 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001502 SourceLocation RParenLoc,
1503 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001504 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001505 Args, RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 }
1507
1508 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001509 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001512 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001513 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001514 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001515 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001516 const DeclarationNameInfo &MemberNameInfo,
1517 ValueDecl *Member,
1518 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001519 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001520 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001521 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1522 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001523 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001524 // We have a reference to an unnamed field. This is always the
1525 // base of an anonymous struct/union member access, i.e. the
1526 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001527 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001528 assert(Member->getType()->isRecordType() &&
1529 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001530
Richard Smith9138b4e2011-10-26 19:06:56 +00001531 BaseResult =
1532 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001533 QualifierLoc.getNestedNameSpecifier(),
1534 FoundDecl, Member);
1535 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001536 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001537 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001538 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001539 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001540 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001541 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001542 cast<FieldDecl>(Member)->getType(),
1543 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001544 return getSema().Owned(ME);
1545 }
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001547 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001548 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001549
John Wiegley429bb272011-04-08 18:41:53 +00001550 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001551 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001552
John McCall6bb80172010-03-30 21:47:33 +00001553 // FIXME: this involves duplicating earlier analysis in a lot of
1554 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001555 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001556 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001557 R.resolveKind();
1558
John McCall9ae2f072010-08-23 23:25:46 +00001559 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001560 SS, TemplateKWLoc,
1561 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001562 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 }
Mike Stump1eb44332009-09-09 15:08:12 +00001564
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001566 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001570 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001571 Expr *LHS, Expr *RHS) {
1572 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 }
1574
1575 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001576 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// By default, performs semantic analysis to build the new expression.
1578 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001580 SourceLocation QuestionLoc,
1581 Expr *LHS,
1582 SourceLocation ColonLoc,
1583 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001584 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1585 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 }
1587
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001589 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// By default, performs semantic analysis to build the new expression.
1591 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001592 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001593 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001596 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001597 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001601 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001604 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001605 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001607 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001608 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001609 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 }
Mike Stump1eb44332009-09-09 15:08:12 +00001611
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001613 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001616 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 SourceLocation OpLoc,
1618 SourceLocation AccessorLoc,
1619 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001620
John McCall129e2df2009-11-30 22:42:35 +00001621 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001622 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001623 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001624 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001625 SS, SourceLocation(),
1626 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001627 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001628 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 }
Mike Stump1eb44332009-09-09 15:08:12 +00001630
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001632 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001635 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001636 MultiExprArg Inits,
1637 SourceLocation RBraceLoc,
1638 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001639 ExprResult Result
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001640 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregore48319a2009-11-09 17:16:50 +00001641 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001642 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00001643
Douglas Gregore48319a2009-11-09 17:16:50 +00001644 // Patch in the result type we were given, which may have been computed
1645 // when the initial InitListExpr was built.
1646 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1647 ILE->setType(ResultTy);
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001648 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 }
Mike Stump1eb44332009-09-09 15:08:12 +00001650
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001652 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 MultiExprArg ArrayExprs,
1657 SourceLocation EqualOrColonLoc,
1658 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001659 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001660 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001662 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001666 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 }
Mike Stump1eb44332009-09-09 15:08:12 +00001668
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001670 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// By default, builds the implicit value initialization without performing
1672 /// any semantic analysis. Subclasses may override this routine to provide
1673 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1676 }
Mike Stump1eb44332009-09-09 15:08:12 +00001677
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001679 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// By default, performs semantic analysis to build the new expression.
1681 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001682 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001683 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001684 SourceLocation RParenLoc) {
1685 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001686 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001687 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 }
1689
1690 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001691 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// By default, performs semantic analysis to build the new expression.
1693 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001694 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001695 MultiExprArg SubExprs,
1696 SourceLocation RParenLoc) {
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001697 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 }
Mike Stump1eb44332009-09-09 15:08:12 +00001699
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001701 ///
1702 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// rather than attempting to map the label statement itself.
1704 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001705 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001706 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001707 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 }
Mike Stump1eb44332009-09-09 15:08:12 +00001709
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001711 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 /// By default, performs semantic analysis to build the new expression.
1713 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001714 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001715 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001717 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 }
Mike Stump1eb44332009-09-09 15:08:12 +00001719
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 /// \brief Build a new __builtin_choose_expr expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001724 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001725 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 SourceLocation RParenLoc) {
1727 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 RParenLoc);
1730 }
Mike Stump1eb44332009-09-09 15:08:12 +00001731
Peter Collingbournef111d932011-04-15 00:35:48 +00001732 /// \brief Build a new generic selection expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1737 SourceLocation DefaultLoc,
1738 SourceLocation RParenLoc,
1739 Expr *ControllingExpr,
1740 TypeSourceInfo **Types,
1741 Expr **Exprs,
1742 unsigned NumAssocs) {
1743 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1744 ControllingExpr, Types, Exprs,
1745 NumAssocs);
1746 }
1747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 /// \brief Build a new overloaded operator call expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// The semantic analysis provides the behavior of template instantiation,
1752 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001753 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 /// argument-dependent lookup, etc. Subclasses may override this routine to
1755 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001756 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001758 Expr *Callee,
1759 Expr *First,
1760 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001761
1762 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// reinterpret_cast.
1764 ///
1765 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001766 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001768 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 Stmt::StmtClass Class,
1770 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001771 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 SourceLocation RAngleLoc,
1773 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 SourceLocation RParenLoc) {
1776 switch (Class) {
1777 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001778 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001779 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781
1782 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001783 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001784 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001786
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001788 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001789 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001790 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001792
Douglas Gregorb98b1992009-08-11 05:31:07 +00001793 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001794 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001795 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001796 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001797
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001799 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 }
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// \brief Build a new C++ static_cast expression.
1804 ///
1805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001809 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RAngleLoc,
1811 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001812 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001814 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001815 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001816 SourceRange(LAngleLoc, RAngleLoc),
1817 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 }
1819
1820 /// \brief Build a new C++ dynamic_cast expression.
1821 ///
1822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001824 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001826 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 SourceLocation RAngleLoc,
1828 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001829 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001831 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001832 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001833 SourceRange(LAngleLoc, RAngleLoc),
1834 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 }
1836
1837 /// \brief Build a new C++ reinterpret_cast expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001841 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001843 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation RAngleLoc,
1845 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001846 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001848 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001849 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001850 SourceRange(LAngleLoc, RAngleLoc),
1851 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 }
1853
1854 /// \brief Build a new C++ const_cast expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001858 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001860 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation RAngleLoc,
1862 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001863 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001864 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001865 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001866 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001867 SourceRange(LAngleLoc, RAngleLoc),
1868 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 }
Mike Stump1eb44332009-09-09 15:08:12 +00001870
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 /// \brief Build a new C++ functional-style cast expression.
1872 ///
1873 /// By default, performs semantic analysis to build the new expression.
1874 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001875 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1876 SourceLocation LParenLoc,
1877 Expr *Sub,
1878 SourceLocation RParenLoc) {
1879 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001880 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 RParenLoc);
1882 }
Mike Stump1eb44332009-09-09 15:08:12 +00001883
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 /// \brief Build a new C++ typeid(type) expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001888 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001889 SourceLocation TypeidLoc,
1890 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001892 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001893 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 }
Mike Stump1eb44332009-09-09 15:08:12 +00001895
Francois Pichet01b7c302010-09-08 12:20:18 +00001896
Douglas Gregorb98b1992009-08-11 05:31:07 +00001897 /// \brief Build a new C++ typeid(expr) expression.
1898 ///
1899 /// By default, performs semantic analysis to build the new expression.
1900 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001901 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001902 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001903 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001905 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001906 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001907 }
1908
Francois Pichet01b7c302010-09-08 12:20:18 +00001909 /// \brief Build a new C++ __uuidof(type) expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
1913 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1914 SourceLocation TypeidLoc,
1915 TypeSourceInfo *Operand,
1916 SourceLocation RParenLoc) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00001917 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet01b7c302010-09-08 12:20:18 +00001918 RParenLoc);
1919 }
1920
1921 /// \brief Build a new C++ __uuidof(expr) expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
1925 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1926 SourceLocation TypeidLoc,
1927 Expr *Operand,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1930 RParenLoc);
1931 }
1932
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 /// \brief Build a new C++ "this" expression.
1934 ///
1935 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001936 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001938 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001939 QualType ThisType,
1940 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001941 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001943 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1944 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 }
1946
1947 /// \brief Build a new C++ throw expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001951 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1952 bool IsThrownVariableInScope) {
1953 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 }
1955
1956 /// \brief Build a new C++ default-argument expression.
1957 ///
1958 /// By default, builds a new default-argument expression, which does not
1959 /// require any semantic analysis. Subclasses may override this routine to
1960 /// provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00001961 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001962 ParmVarDecl *Param) {
1963 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1964 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 }
1966
1967 /// \brief Build a new C++ zero-initialization expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001971 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1972 SourceLocation LParenLoc,
1973 SourceLocation RParenLoc) {
1974 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001975 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001976 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 }
Mike Stump1eb44332009-09-09 15:08:12 +00001978
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 /// \brief Build a new C++ "new" expression.
1980 ///
1981 /// By default, performs semantic analysis to build the new expression.
1982 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001983 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001984 bool UseGlobal,
1985 SourceLocation PlacementLParen,
1986 MultiExprArg PlacementArgs,
1987 SourceLocation PlacementRParen,
1988 SourceRange TypeIdParens,
1989 QualType AllocatedType,
1990 TypeSourceInfo *AllocatedTypeInfo,
1991 Expr *ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00001992 SourceRange DirectInitRange,
1993 Expr *Initializer) {
Mike Stump1eb44332009-09-09 15:08:12 +00001994 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001995 PlacementLParen,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00001996 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001997 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001998 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001999 AllocatedType,
2000 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00002001 ArraySize,
Sebastian Redl2aed8b82012-02-16 12:22:20 +00002002 DirectInitRange,
2003 Initializer);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002004 }
Mike Stump1eb44332009-09-09 15:08:12 +00002005
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// \brief Build a new C++ "delete" expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002010 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 bool IsGlobalDelete,
2012 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002013 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00002015 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002016 }
Mike Stump1eb44332009-09-09 15:08:12 +00002017
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 /// \brief Build a new unary type trait expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002022 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00002023 SourceLocation StartLoc,
2024 TypeSourceInfo *T,
2025 SourceLocation RParenLoc) {
2026 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002027 }
2028
Francois Pichet6ad6f282010-12-07 00:08:36 +00002029 /// \brief Build a new binary type trait expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
2033 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
2034 SourceLocation StartLoc,
2035 TypeSourceInfo *LhsT,
2036 TypeSourceInfo *RhsT,
2037 SourceLocation RParenLoc) {
2038 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
2039 }
2040
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00002041 /// \brief Build a new type trait expression.
2042 ///
2043 /// By default, performs semantic analysis to build the new expression.
2044 /// Subclasses may override this routine to provide different behavior.
2045 ExprResult RebuildTypeTrait(TypeTrait Trait,
2046 SourceLocation StartLoc,
2047 ArrayRef<TypeSourceInfo *> Args,
2048 SourceLocation RParenLoc) {
2049 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2050 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002051
John Wiegley21ff2e52011-04-28 00:16:57 +00002052 /// \brief Build a new array type trait expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
2056 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2057 SourceLocation StartLoc,
2058 TypeSourceInfo *TSInfo,
2059 Expr *DimExpr,
2060 SourceLocation RParenLoc) {
2061 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2062 }
2063
John Wiegley55262202011-04-25 06:54:41 +00002064 /// \brief Build a new expression trait expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
2068 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2069 SourceLocation StartLoc,
2070 Expr *Queried,
2071 SourceLocation RParenLoc) {
2072 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2073 }
2074
Mike Stump1eb44332009-09-09 15:08:12 +00002075 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 /// expression.
2077 ///
2078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002080 ExprResult RebuildDependentScopeDeclRefExpr(
2081 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002082 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002083 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002084 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002085 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002086 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002087
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002088 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002089 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002090 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002091
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002092 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093 }
2094
2095 /// \brief Build a new template-id expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002099 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002100 SourceLocation TemplateKWLoc,
2101 LookupResult &R,
2102 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002103 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002104 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2105 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 }
2107
2108 /// \brief Build a new object-construction expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002112 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002113 SourceLocation Loc,
2114 CXXConstructorDecl *Constructor,
2115 bool IsElidable,
2116 MultiExprArg Args,
2117 bool HadMultipleCandidates,
2118 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002119 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002120 SourceRange ParenRange) {
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00002121 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002122 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002123 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002124 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002125
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002126 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002127 ConvertedArgs,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002128 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002129 RequiresZeroInit, ConstructKind,
2130 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002131 }
2132
2133 /// \brief Build a new object-construction expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002137 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2138 SourceLocation LParenLoc,
2139 MultiExprArg Args,
2140 SourceLocation RParenLoc) {
2141 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002142 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002143 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002144 RParenLoc);
2145 }
2146
2147 /// \brief Build a new object-construction expression.
2148 ///
2149 /// By default, performs semantic analysis to build the new expression.
2150 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002151 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2152 SourceLocation LParenLoc,
2153 MultiExprArg Args,
2154 SourceLocation RParenLoc) {
2155 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002156 LParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002157 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 RParenLoc);
2159 }
Mike Stump1eb44332009-09-09 15:08:12 +00002160
Douglas Gregorb98b1992009-08-11 05:31:07 +00002161 /// \brief Build a new member reference expression.
2162 ///
2163 /// By default, performs semantic analysis to build the new expression.
2164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002165 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002166 QualType BaseType,
2167 bool IsArrow,
2168 SourceLocation OperatorLoc,
2169 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002170 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002171 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002172 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002173 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002175 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002176
John McCall9ae2f072010-08-23 23:25:46 +00002177 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002178 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002179 SS, TemplateKWLoc,
2180 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002181 MemberNameInfo,
2182 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 }
2184
John McCall129e2df2009-11-30 22:42:35 +00002185 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002186 ///
2187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002189 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2190 SourceLocation OperatorLoc,
2191 bool IsArrow,
2192 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002193 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002194 NamedDecl *FirstQualifierInScope,
2195 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002196 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002197 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002198 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002199
John McCall9ae2f072010-08-23 23:25:46 +00002200 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002201 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002202 SS, TemplateKWLoc,
2203 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002204 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002205 }
Mike Stump1eb44332009-09-09 15:08:12 +00002206
Sebastian Redl2e156222010-09-10 20:55:43 +00002207 /// \brief Build a new noexcept expression.
2208 ///
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
2211 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2212 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2213 }
2214
Douglas Gregoree8aff02011-01-04 17:33:58 +00002215 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002216 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2217 SourceLocation PackLoc,
Douglas Gregoree8aff02011-01-04 17:33:58 +00002218 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002219 llvm::Optional<unsigned> Length) {
2220 if (Length)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002221 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2222 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002223 RParenLoc, *Length);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002224
2225 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2226 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002227 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002228 }
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002229
Patrick Beardeb382ec2012-04-19 00:25:12 +00002230 /// \brief Build a new Objective-C boxed expression.
2231 ///
2232 /// By default, performs semantic analysis to build the new expression.
2233 /// Subclasses may override this routine to provide different behavior.
2234 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2235 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2236 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002237
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002238 /// \brief Build a new Objective-C array literal.
2239 ///
2240 /// By default, performs semantic analysis to build the new expression.
2241 /// Subclasses may override this routine to provide different behavior.
2242 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2243 Expr **Elements, unsigned NumElements) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002244 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002245 MultiExprArg(Elements, NumElements));
2246 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002247
2248 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremenekebcb57a2012-03-06 20:05:56 +00002249 Expr *Base, Expr *Key,
2250 ObjCMethodDecl *getterMethod,
2251 ObjCMethodDecl *setterMethod) {
2252 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2253 getterMethod, setterMethod);
2254 }
2255
2256 /// \brief Build a new Objective-C dictionary literal.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
2260 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2261 ObjCDictionaryElement *Elements,
2262 unsigned NumElements) {
2263 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2264 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002265
James Dennett699c9042012-06-15 07:13:21 +00002266 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregorb98b1992009-08-11 05:31:07 +00002267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002270 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002271 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002273 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002274 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002275 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002276
Douglas Gregor92e986e2010-04-22 16:44:27 +00002277 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002279 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002280 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002281 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002282 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002283 MultiExprArg Args,
2284 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002285 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2286 ReceiverTypeInfo->getType(),
2287 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002288 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002289 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002290 }
2291
2292 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002293 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002294 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002295 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002296 ObjCMethodDecl *Method,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002297 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002298 MultiExprArg Args,
2299 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002300 return SemaRef.BuildInstanceMessage(Receiver,
2301 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002302 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002303 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002304 RBracLoc, Args);
Douglas Gregor92e986e2010-04-22 16:44:27 +00002305 }
2306
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002307 /// \brief Build a new Objective-C ivar reference expression.
2308 ///
2309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002311 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002312 SourceLocation IvarLoc,
2313 bool IsArrow, bool IsFreeIvar) {
2314 // FIXME: We lose track of the IsFreeIvar bit.
2315 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002316 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2318 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002319 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002320 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002321 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002322 false);
John Wiegley429bb272011-04-08 18:41:53 +00002323 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002324 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002325
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002326 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002327 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002328
John Wiegley429bb272011-04-08 18:41:53 +00002329 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002330 /*FIXME:*/IvarLoc, IsArrow,
2331 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002332 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002333 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002334 /*TemplateArgs=*/0);
2335 }
Douglas Gregore3303542010-04-26 20:47:02 +00002336
2337 /// \brief Build a new Objective-C property reference expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002341 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002342 ObjCPropertyDecl *Property,
2343 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002344 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002345 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002346 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2347 Sema::LookupMemberName);
2348 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002349 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002350 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002351 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002352 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002353 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002354
Douglas Gregore3303542010-04-26 20:47:02 +00002355 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002356 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002357
John Wiegley429bb272011-04-08 18:41:53 +00002358 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002359 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002360 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002361 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002362 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002363 /*TemplateArgs=*/0);
2364 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002365
John McCall12f78a62010-12-02 01:19:52 +00002366 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002367 ///
2368 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002369 /// Subclasses may override this routine to provide different behavior.
2370 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2371 ObjCMethodDecl *Getter,
2372 ObjCMethodDecl *Setter,
2373 SourceLocation PropertyLoc) {
2374 // Since these expressions can only be value-dependent, we do not
2375 // need to perform semantic analysis again.
2376 return Owned(
2377 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2378 VK_LValue, OK_ObjCProperty,
2379 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002380 }
2381
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002382 /// \brief Build a new Objective-C "isa" expression.
2383 ///
2384 /// By default, performs semantic analysis to build the new expression.
2385 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002386 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002387 bool IsArrow) {
2388 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002389 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002390 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2391 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002392 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002393 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002394 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002395 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002396 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002397
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002398 if (Result.get())
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002399 return Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002400
John Wiegley429bb272011-04-08 18:41:53 +00002401 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002402 /*FIXME:*/IsaLoc, IsArrow,
2403 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002404 /*FirstQualifierInScope=*/0,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002405 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002406 /*TemplateArgs=*/0);
2407 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002408
Douglas Gregorb98b1992009-08-11 05:31:07 +00002409 /// \brief Build a new shuffle vector expression.
2410 ///
2411 /// By default, performs semantic analysis to build the new expression.
2412 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002413 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002414 MultiExprArg SubExprs,
2415 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002416 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002417 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002418 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2419 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2420 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2421 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002422
Douglas Gregorb98b1992009-08-11 05:31:07 +00002423 // Build a reference to the __builtin_shufflevector builtin
2424 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002425 ExprResult Callee
John McCallf4b88a42012-03-10 09:33:50 +00002426 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false,
2427 Builtin->getType(),
John Wiegley429bb272011-04-08 18:41:53 +00002428 VK_LValue, BuiltinLoc));
2429 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2430 if (Callee.isInvalid())
2431 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002432
2433 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002434 unsigned NumSubExprs = SubExprs.size();
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002435 Expr **Subs = SubExprs.get();
John Wiegley429bb272011-04-08 18:41:53 +00002436 ExprResult TheCall = SemaRef.Owned(
2437 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002438 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002439 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002440 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002441 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002442
Douglas Gregorb98b1992009-08-11 05:31:07 +00002443 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002444 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002445 }
John McCall43fed0d2010-11-12 08:19:04 +00002446
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002447 /// \brief Build a new template argument pack expansion.
2448 ///
2449 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002450 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002451 /// different behavior.
2452 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002453 SourceLocation EllipsisLoc,
2454 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002455 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002456 case TemplateArgument::Expression: {
2457 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002458 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2459 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002460 if (Result.isInvalid())
2461 return TemplateArgumentLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002462
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002463 return TemplateArgumentLoc(Result.get(), Result.get());
2464 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002465
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002466 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002467 return TemplateArgumentLoc(TemplateArgument(
2468 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002469 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002470 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002471 Pattern.getTemplateNameLoc(),
2472 EllipsisLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002473
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002474 case TemplateArgument::Null:
2475 case TemplateArgument::Integral:
2476 case TemplateArgument::Declaration:
2477 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002478 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002479 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002480
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002481 case TemplateArgument::Type:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002482 if (TypeSourceInfo *Expansion
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002483 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002484 EllipsisLoc,
2485 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002486 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2487 Expansion);
2488 break;
2489 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002490
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002491 return TemplateArgumentLoc();
2492 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002493
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002494 /// \brief Build a new expression pack expansion.
2495 ///
2496 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier4a9d7952012-08-08 18:46:20 +00002497 /// for an expression. Subclasses may override this routine to provide
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002498 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002499 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2500 llvm::Optional<unsigned> NumExpansions) {
2501 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002502 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002503
2504 /// \brief Build a new atomic operation expression.
2505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
2508 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2509 MultiExprArg SubExprs,
2510 QualType RetTy,
2511 AtomicExpr::AtomicOp Op,
2512 SourceLocation RParenLoc) {
2513 // Just create the expression; there is not any interesting semantic
2514 // analysis here because we can't actually build an AtomicExpr until
2515 // we are sure it is semantically sound.
2516 unsigned NumSubExprs = SubExprs.size();
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00002517 Expr **Subs = SubExprs.get();
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002518 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2519 NumSubExprs, RetTy, Op,
2520 RParenLoc);
2521 }
2522
John McCall43fed0d2010-11-12 08:19:04 +00002523private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002524 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2525 QualType ObjectType,
2526 NamedDecl *FirstQualifierInScope,
2527 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002528
2529 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2530 QualType ObjectType,
2531 NamedDecl *FirstQualifierInScope,
2532 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002533};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002534
Douglas Gregor43959a92009-08-20 07:17:43 +00002535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002536StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002537 if (!S)
2538 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002539
Douglas Gregor43959a92009-08-20 07:17:43 +00002540 switch (S->getStmtClass()) {
2541 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002542
Douglas Gregor43959a92009-08-20 07:17:43 +00002543 // Transform individual statement nodes
2544#define STMT(Node, Parent) \
2545 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002546#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002547#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002548#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002549
Douglas Gregor43959a92009-08-20 07:17:43 +00002550 // Transform expressions by calling TransformExpr.
2551#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002552#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002553#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002554#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002555 {
John McCall60d7b3a2010-08-24 06:29:42 +00002556 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002557 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002558 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002559
John McCall9ae2f072010-08-23 23:25:46 +00002560 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002561 }
Mike Stump1eb44332009-09-09 15:08:12 +00002562 }
2563
John McCall3fa5cae2010-10-26 07:05:15 +00002564 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002565}
Mike Stump1eb44332009-09-09 15:08:12 +00002566
2567
Douglas Gregor670444e2009-08-04 22:27:00 +00002568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002569ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002570 if (!E)
2571 return SemaRef.Owned(E);
2572
2573 switch (E->getStmtClass()) {
2574 case Stmt::NoStmtClass: break;
2575#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002576#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002577#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002578 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002579#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002580 }
2581
John McCall3fa5cae2010-10-26 07:05:15 +00002582 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002583}
2584
2585template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00002586bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2587 unsigned NumInputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002588 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002589 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002590 bool *ArgChanged) {
2591 for (unsigned I = 0; I != NumInputs; ++I) {
2592 // If requested, drop call arguments that need to be dropped.
2593 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2594 if (ArgChanged)
2595 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002596
Douglas Gregoraa165f82011-01-03 19:04:46 +00002597 break;
2598 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002599
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002600 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2601 Expr *Pattern = Expansion->getPattern();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002602
Chris Lattner686775d2011-07-20 06:58:45 +00002603 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002604 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2605 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002606
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002607 // Determine whether the set of unexpanded parameter packs can and should
2608 // be expanded.
2609 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002610 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002611 llvm::Optional<unsigned> OrigNumExpansions
2612 = Expansion->getNumExpansions();
2613 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002614 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2615 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002616 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002617 Expand, RetainExpansion,
2618 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002619 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002620
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002621 if (!Expand) {
2622 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00002623 // transformation on the pack expansion, producing another pack
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002624 // expansion.
2625 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2626 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2627 if (OutPattern.isInvalid())
2628 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002629
2630 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002631 Expansion->getEllipsisLoc(),
2632 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002633 if (Out.isInvalid())
2634 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002635
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002636 if (ArgChanged)
2637 *ArgChanged = true;
2638 Outputs.push_back(Out.get());
2639 continue;
2640 }
John McCallc8fc90a2011-07-06 07:30:07 +00002641
2642 // Record right away that the argument was changed. This needs
2643 // to happen even if the array expands to nothing.
2644 if (ArgChanged) *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002645
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002646 // The transform has determined that we should perform an elementwise
2647 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002648 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002649 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2650 ExprResult Out = getDerived().TransformExpr(Pattern);
2651 if (Out.isInvalid())
2652 return true;
2653
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002654 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002655 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2656 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002657 if (Out.isInvalid())
2658 return true;
2659 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002660
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002661 Outputs.push_back(Out.get());
2662 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002663
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002664 continue;
2665 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002666
Douglas Gregoraa165f82011-01-03 19:04:46 +00002667 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2668 if (Result.isInvalid())
2669 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002670
Douglas Gregoraa165f82011-01-03 19:04:46 +00002671 if (Result.get() != Inputs[I] && ArgChanged)
2672 *ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002673
2674 Outputs.push_back(Result.get());
Douglas Gregoraa165f82011-01-03 19:04:46 +00002675 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002676
Douglas Gregoraa165f82011-01-03 19:04:46 +00002677 return false;
2678}
2679
2680template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002681NestedNameSpecifierLoc
2682TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2683 NestedNameSpecifierLoc NNS,
2684 QualType ObjectType,
2685 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002686 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002687 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002688 Qualifier = Qualifier.getPrefix())
2689 Qualifiers.push_back(Qualifier);
2690
2691 CXXScopeSpec SS;
2692 while (!Qualifiers.empty()) {
2693 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2694 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002695
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002696 switch (QNNS->getKind()) {
2697 case NestedNameSpecifier::Identifier:
Chad Rosier4a9d7952012-08-08 18:46:20 +00002698 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002699 *QNNS->getAsIdentifier(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002700 Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002701 Q.getLocalEndLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00002702 ObjectType, false, SS,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002703 FirstQualifierInScope, false))
2704 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002705
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002706 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002707
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002708 case NestedNameSpecifier::Namespace: {
2709 NamespaceDecl *NS
2710 = cast_or_null<NamespaceDecl>(
2711 getDerived().TransformDecl(
2712 Q.getLocalBeginLoc(),
2713 QNNS->getAsNamespace()));
2714 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2715 break;
2716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002717
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002718 case NestedNameSpecifier::NamespaceAlias: {
2719 NamespaceAliasDecl *Alias
2720 = cast_or_null<NamespaceAliasDecl>(
2721 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2722 QNNS->getAsNamespaceAlias()));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002723 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002724 Q.getLocalEndLoc());
2725 break;
2726 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002727
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002728 case NestedNameSpecifier::Global:
2729 // There is no meaningful transformation that one could perform on the
2730 // global scope.
2731 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2732 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002733
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002734 case NestedNameSpecifier::TypeSpecWithTemplate:
2735 case NestedNameSpecifier::TypeSpec: {
2736 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2737 FirstQualifierInScope, SS);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002738
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002739 if (!TL)
2740 return NestedNameSpecifierLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002741
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002742 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00002743 (SemaRef.getLangOpts().CPlusPlus0x &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002744 TL.getType()->isEnumeralType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002745 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002746 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002747 if (TL.getType()->isEnumeralType())
2748 SemaRef.Diag(TL.getBeginLoc(),
2749 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002750 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2751 Q.getLocalEndLoc());
2752 break;
2753 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002754 // If the nested-name-specifier is an invalid type def, don't emit an
2755 // error because a previous error should have already been emitted.
2756 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2757 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00002758 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieu00c93a12011-05-07 01:36:37 +00002759 << TL.getType() << SS.getRange();
2760 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002761 return NestedNameSpecifierLoc();
2762 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002763 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002764
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002765 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002766 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002767 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002768 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002769
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002770 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier4a9d7952012-08-08 18:46:20 +00002771 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002772 !getDerived().AlwaysRebuild())
2773 return NNS;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002774
2775 // If we can re-use the source-location data from the original
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002776 // nested-name-specifier, do so.
2777 if (SS.location_size() == NNS.getDataLength() &&
2778 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2779 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2780
2781 // Allocate new nested-name-specifier location information.
2782 return SS.getWithLocInContext(SemaRef.Context);
2783}
2784
2785template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002786DeclarationNameInfo
2787TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002788::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002789 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002790 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002791 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002792
2793 switch (Name.getNameKind()) {
2794 case DeclarationName::Identifier:
2795 case DeclarationName::ObjCZeroArgSelector:
2796 case DeclarationName::ObjCOneArgSelector:
2797 case DeclarationName::ObjCMultiArgSelector:
2798 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002799 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002800 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002801 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002802
Douglas Gregor81499bb2009-09-03 22:13:48 +00002803 case DeclarationName::CXXConstructorName:
2804 case DeclarationName::CXXDestructorName:
2805 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002806 TypeSourceInfo *NewTInfo;
2807 CanQualType NewCanTy;
2808 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002809 NewTInfo = getDerived().TransformType(OldTInfo);
2810 if (!NewTInfo)
2811 return DeclarationNameInfo();
2812 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002813 }
2814 else {
2815 NewTInfo = 0;
2816 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002817 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002818 if (NewT.isNull())
2819 return DeclarationNameInfo();
2820 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2821 }
Mike Stump1eb44332009-09-09 15:08:12 +00002822
Abramo Bagnara25777432010-08-11 22:01:17 +00002823 DeclarationName NewName
2824 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2825 NewCanTy);
2826 DeclarationNameInfo NewNameInfo(NameInfo);
2827 NewNameInfo.setName(NewName);
2828 NewNameInfo.setNamedTypeInfo(NewTInfo);
2829 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002830 }
Mike Stump1eb44332009-09-09 15:08:12 +00002831 }
2832
David Blaikieb219cfc2011-09-23 05:06:16 +00002833 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002834}
2835
2836template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002837TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002838TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2839 TemplateName Name,
2840 SourceLocation NameLoc,
2841 QualType ObjectType,
2842 NamedDecl *FirstQualifierInScope) {
2843 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2844 TemplateDecl *Template = QTN->getTemplateDecl();
2845 assert(Template && "qualified template name must refer to a template");
Chad Rosier4a9d7952012-08-08 18:46:20 +00002846
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002847 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002848 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002849 Template));
2850 if (!TransTemplate)
2851 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002852
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002853 if (!getDerived().AlwaysRebuild() &&
2854 SS.getScopeRep() == QTN->getQualifier() &&
2855 TransTemplate == Template)
2856 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002857
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002858 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2859 TransTemplate);
2860 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002861
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002862 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2863 if (SS.getScopeRep()) {
2864 // These apply to the scope specifier, not the template.
2865 ObjectType = QualType();
2866 FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002867 }
2868
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002869 if (!getDerived().AlwaysRebuild() &&
2870 SS.getScopeRep() == DTN->getQualifier() &&
2871 ObjectType.isNull())
2872 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002873
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002874 if (DTN->isIdentifier()) {
2875 return getDerived().RebuildTemplateName(SS,
Chad Rosier4a9d7952012-08-08 18:46:20 +00002876 *DTN->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002877 NameLoc,
2878 ObjectType,
2879 FirstQualifierInScope);
2880 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002881
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002882 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2883 ObjectType);
2884 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002885
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002886 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2887 TemplateDecl *TransTemplate
Chad Rosier4a9d7952012-08-08 18:46:20 +00002888 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002889 Template));
2890 if (!TransTemplate)
2891 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002892
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002893 if (!getDerived().AlwaysRebuild() &&
2894 TransTemplate == Template)
2895 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002896
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002897 return TemplateName(TransTemplate);
2898 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002899
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002900 if (SubstTemplateTemplateParmPackStorage *SubstPack
2901 = Name.getAsSubstTemplateTemplateParmPack()) {
2902 TemplateTemplateParmDecl *TransParam
2903 = cast_or_null<TemplateTemplateParmDecl>(
2904 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2905 if (!TransParam)
2906 return TemplateName();
Chad Rosier4a9d7952012-08-08 18:46:20 +00002907
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002908 if (!getDerived().AlwaysRebuild() &&
2909 TransParam == SubstPack->getParameterPack())
2910 return Name;
Chad Rosier4a9d7952012-08-08 18:46:20 +00002911
2912 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002913 SubstPack->getArgumentPack());
2914 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00002915
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002916 // These should be getting filtered out before they reach the AST.
2917 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002918}
2919
2920template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002921void TreeTransform<Derived>::InventTemplateArgumentLoc(
2922 const TemplateArgument &Arg,
2923 TemplateArgumentLoc &Output) {
2924 SourceLocation Loc = getDerived().getBaseLocation();
2925 switch (Arg.getKind()) {
2926 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002927 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002928 break;
2929
2930 case TemplateArgument::Type:
2931 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002932 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier4a9d7952012-08-08 18:46:20 +00002933
John McCall833ca992009-10-29 08:12:44 +00002934 break;
2935
Douglas Gregor788cd062009-11-11 01:00:40 +00002936 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002937 case TemplateArgument::TemplateExpansion: {
2938 NestedNameSpecifierLocBuilder Builder;
2939 TemplateName Template = Arg.getAsTemplate();
2940 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2941 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2942 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2943 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002944
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002945 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier4a9d7952012-08-08 18:46:20 +00002946 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002947 Builder.getWithLocInContext(SemaRef.Context),
2948 Loc);
2949 else
Chad Rosier4a9d7952012-08-08 18:46:20 +00002950 Output = TemplateArgumentLoc(Arg,
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002951 Builder.getWithLocInContext(SemaRef.Context),
2952 Loc, Loc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00002953
Douglas Gregor788cd062009-11-11 01:00:40 +00002954 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002955 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002956
John McCall833ca992009-10-29 08:12:44 +00002957 case TemplateArgument::Expression:
2958 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2959 break;
2960
2961 case TemplateArgument::Declaration:
2962 case TemplateArgument::Integral:
2963 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002964 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002965 break;
2966 }
2967}
2968
2969template<typename Derived>
2970bool TreeTransform<Derived>::TransformTemplateArgument(
2971 const TemplateArgumentLoc &Input,
2972 TemplateArgumentLoc &Output) {
2973 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002974 switch (Arg.getKind()) {
2975 case TemplateArgument::Null:
2976 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002977 Output = Input;
2978 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002979
Douglas Gregor670444e2009-08-04 22:27:00 +00002980 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002981 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002982 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002983 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002984
2985 DI = getDerived().TransformType(DI);
2986 if (!DI) return true;
2987
2988 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2989 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002990 }
Mike Stump1eb44332009-09-09 15:08:12 +00002991
Douglas Gregor670444e2009-08-04 22:27:00 +00002992 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002993 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002994 DeclarationName Name;
2995 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2996 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002997 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002998 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002999 if (!D) return true;
3000
John McCall828bff22009-10-29 18:45:58 +00003001 Expr *SourceExpr = Input.getSourceDeclExpression();
3002 if (SourceExpr) {
3003 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003004 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00003005 ExprResult E = getDerived().TransformExpr(SourceExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003006 E = SemaRef.ActOnConstantExpression(E);
John McCall9ae2f072010-08-23 23:25:46 +00003007 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00003008 }
3009
3010 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00003011 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003012 }
Mike Stump1eb44332009-09-09 15:08:12 +00003013
Douglas Gregor788cd062009-11-11 01:00:40 +00003014 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003015 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3016 if (QualifierLoc) {
3017 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3018 if (!QualifierLoc)
3019 return true;
3020 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003021
Douglas Gregor1d752d72011-03-02 18:46:51 +00003022 CXXScopeSpec SS;
3023 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00003024 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00003025 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3026 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00003027 if (Template.isNull())
3028 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003029
Douglas Gregorb6744ef2011-03-02 17:09:35 +00003030 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00003031 Input.getTemplateNameLoc());
3032 return false;
3033 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00003034
3035 case TemplateArgument::TemplateExpansion:
3036 llvm_unreachable("Caller should expand pack expansions");
3037
Douglas Gregor670444e2009-08-04 22:27:00 +00003038 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00003039 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00003040 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00003041 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003042
John McCall833ca992009-10-29 08:12:44 +00003043 Expr *InputExpr = Input.getSourceExpression();
3044 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3045
Chris Lattner223de242011-04-25 20:37:58 +00003046 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanac626012012-02-29 03:16:56 +00003047 E = SemaRef.ActOnConstantExpression(E);
John McCall833ca992009-10-29 08:12:44 +00003048 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00003049 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00003050 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003051 }
Mike Stump1eb44332009-09-09 15:08:12 +00003052
Douglas Gregor670444e2009-08-04 22:27:00 +00003053 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00003054 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00003055 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00003056 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00003057 AEnd = Arg.pack_end();
3058 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00003059
John McCall833ca992009-10-29 08:12:44 +00003060 // FIXME: preserve source information here when we start
3061 // caring about parameter packs.
3062
John McCall828bff22009-10-29 18:45:58 +00003063 TemplateArgumentLoc InputArg;
3064 TemplateArgumentLoc OutputArg;
3065 getDerived().InventTemplateArgumentLoc(*A, InputArg);
3066 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00003067 return true;
3068
John McCall828bff22009-10-29 18:45:58 +00003069 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00003070 }
Douglas Gregor910f8002010-11-07 23:05:16 +00003071
3072 TemplateArgument *TransformedArgsPtr
3073 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
3074 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
3075 TransformedArgsPtr);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003076 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
3077 TransformedArgs.size()),
Douglas Gregor910f8002010-11-07 23:05:16 +00003078 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00003079 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00003080 }
3081 }
Mike Stump1eb44332009-09-09 15:08:12 +00003082
Douglas Gregor670444e2009-08-04 22:27:00 +00003083 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00003084 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00003085}
3086
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003087/// \brief Iterator adaptor that invents template argument location information
3088/// for each of the template arguments in its underlying iterator.
3089template<typename Derived, typename InputIterator>
3090class TemplateArgumentLocInventIterator {
3091 TreeTransform<Derived> &Self;
3092 InputIterator Iter;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003093
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003094public:
3095 typedef TemplateArgumentLoc value_type;
3096 typedef TemplateArgumentLoc reference;
3097 typedef typename std::iterator_traits<InputIterator>::difference_type
3098 difference_type;
3099 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003100
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003101 class pointer {
3102 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003103
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003104 public:
3105 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003106
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003107 const TemplateArgumentLoc *operator->() const { return &Arg; }
3108 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00003109
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003110 TemplateArgumentLocInventIterator() { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003111
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003112 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3113 InputIterator Iter)
3114 : Self(Self), Iter(Iter) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003115
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003116 TemplateArgumentLocInventIterator &operator++() {
3117 ++Iter;
3118 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003119 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003120
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003121 TemplateArgumentLocInventIterator operator++(int) {
3122 TemplateArgumentLocInventIterator Old(*this);
3123 ++(*this);
3124 return Old;
3125 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003126
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003127 reference operator*() const {
3128 TemplateArgumentLoc Result;
3129 Self.InventTemplateArgumentLoc(*Iter, Result);
3130 return Result;
3131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003132
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003133 pointer operator->() const { return pointer(**this); }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003134
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003135 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3136 const TemplateArgumentLocInventIterator &Y) {
3137 return X.Iter == Y.Iter;
3138 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003139
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003140 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3141 const TemplateArgumentLocInventIterator &Y) {
3142 return X.Iter != Y.Iter;
3143 }
3144};
Chad Rosier4a9d7952012-08-08 18:46:20 +00003145
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003146template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003147template<typename InputIterator>
3148bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3149 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003150 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003151 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003152 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003153 TemplateArgumentLoc In = *First;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003154
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003155 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3156 // Unpack argument packs, which we translate them into separate
3157 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003158 // FIXME: We could do much better if we could guarantee that the
3159 // TemplateArgumentLocInfo for the pack expansion would be usable for
3160 // all of the template arguments in the argument pack.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003161 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003162 TemplateArgument::pack_iterator>
3163 PackLocIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003164 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003165 In.getArgument().pack_begin()),
3166 PackLocIterator(*this,
3167 In.getArgument().pack_end()),
3168 Outputs))
3169 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003170
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003171 continue;
3172 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003173
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003174 if (In.getArgument().isPackExpansion()) {
3175 // We have a pack expansion, for which we will be substituting into
3176 // the pattern.
3177 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003178 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003179 TemplateArgumentLoc Pattern
Chad Rosier4a9d7952012-08-08 18:46:20 +00003180 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
Douglas Gregorcded4f62011-01-14 17:04:44 +00003181 getSema().Context);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003182
Chris Lattner686775d2011-07-20 06:58:45 +00003183 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003184 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3185 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier4a9d7952012-08-08 18:46:20 +00003186
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003187 // Determine whether the set of unexpanded parameter packs can and should
3188 // be expanded.
3189 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003190 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003191 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003192 if (getDerived().TryExpandParameterPacks(Ellipsis,
3193 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003194 Unexpanded,
Chad Rosier4a9d7952012-08-08 18:46:20 +00003195 Expand,
Douglas Gregord3731192011-01-10 07:32:04 +00003196 RetainExpansion,
3197 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003198 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003199
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003200 if (!Expand) {
3201 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00003202 // transformation on the pack expansion, producing another pack
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003203 // expansion.
3204 TemplateArgumentLoc OutPattern;
3205 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3206 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3207 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003208
Douglas Gregorcded4f62011-01-14 17:04:44 +00003209 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3210 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003211 if (Out.getArgument().isNull())
3212 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003213
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003214 Outputs.addArgument(Out);
3215 continue;
3216 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003217
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003218 // The transform has determined that we should perform an elementwise
3219 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003220 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003221 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3222
3223 if (getDerived().TransformTemplateArgument(Pattern, Out))
3224 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003225
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003226 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003227 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3228 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003229 if (Out.getArgument().isNull())
3230 return true;
3231 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003232
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003233 Outputs.addArgument(Out);
3234 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003235
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003236 // If we're supposed to retain a pack expansion, do so by temporarily
3237 // forgetting the partially-substituted parameter pack.
3238 if (RetainExpansion) {
3239 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003240
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003241 if (getDerived().TransformTemplateArgument(Pattern, Out))
3242 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003243
Douglas Gregorcded4f62011-01-14 17:04:44 +00003244 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3245 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003246 if (Out.getArgument().isNull())
3247 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003248
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003249 Outputs.addArgument(Out);
3250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003251
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003252 continue;
3253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003254
3255 // The simple case:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003256 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003257 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003258
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003259 Outputs.addArgument(Out);
3260 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003261
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003262 return false;
3263
3264}
3265
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266//===----------------------------------------------------------------------===//
3267// Type transformation
3268//===----------------------------------------------------------------------===//
3269
3270template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003271QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003272 if (getDerived().AlreadyTransformed(T))
3273 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003274
John McCalla2becad2009-10-21 00:40:46 +00003275 // Temporary workaround. All of these transformations should
3276 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003277 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3278 getDerived().getBaseLocation());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003279
John McCall43fed0d2010-11-12 08:19:04 +00003280 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003281
John McCalla2becad2009-10-21 00:40:46 +00003282 if (!NewDI)
3283 return QualType();
3284
3285 return NewDI->getType();
3286}
3287
3288template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003289TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003290 // Refine the base location to the type's location.
3291 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3292 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003293 if (getDerived().AlreadyTransformed(DI->getType()))
3294 return DI;
3295
3296 TypeLocBuilder TLB;
3297
3298 TypeLoc TL = DI->getTypeLoc();
3299 TLB.reserve(TL.getFullDataSize());
3300
John McCall43fed0d2010-11-12 08:19:04 +00003301 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003302 if (Result.isNull())
3303 return 0;
3304
John McCalla93c9342009-12-07 02:54:59 +00003305 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003306}
3307
3308template<typename Derived>
3309QualType
John McCall43fed0d2010-11-12 08:19:04 +00003310TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003311 switch (T.getTypeLocClass()) {
3312#define ABSTRACT_TYPELOC(CLASS, PARENT)
3313#define TYPELOC(CLASS, PARENT) \
3314 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003315 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003316#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003317 }
Mike Stump1eb44332009-09-09 15:08:12 +00003318
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003319 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003320}
3321
3322/// FIXME: By default, this routine adds type qualifiers only to types
3323/// that can have qualifiers, and silently suppresses those qualifiers
3324/// that are not permitted (e.g., qualifiers on reference or function
3325/// types). This is the right thing for template instantiation, but
3326/// probably not for other clients.
3327template<typename Derived>
3328QualType
3329TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003330 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003331 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003332
John McCall43fed0d2010-11-12 08:19:04 +00003333 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003334 if (Result.isNull())
3335 return QualType();
3336
3337 // Silently suppress qualifiers if the result type can't be qualified.
3338 // FIXME: this is the right thing for template instantiation, but
3339 // probably not for other clients.
3340 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003341 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003342
John McCallf85e1932011-06-15 23:02:42 +00003343 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003344 // resulting type.
3345 if (Quals.hasObjCLifetime()) {
3346 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3347 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003348 else if (Result.getObjCLifetime()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003349 // Objective-C ARC:
Douglas Gregore559ca12011-06-17 22:11:49 +00003350 // A lifetime qualifier applied to a substituted template parameter
3351 // overrides the lifetime qualifier from the template argument.
Chad Rosier4a9d7952012-08-08 18:46:20 +00003352 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore559ca12011-06-17 22:11:49 +00003353 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3354 QualType Replacement = SubstTypeParam->getReplacementType();
3355 Qualifiers Qs = Replacement.getQualifiers();
3356 Qs.removeObjCLifetime();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003357 Replacement
Douglas Gregore559ca12011-06-17 22:11:49 +00003358 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3359 Qs);
3360 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier4a9d7952012-08-08 18:46:20 +00003361 SubstTypeParam->getReplacedParameter(),
Douglas Gregore559ca12011-06-17 22:11:49 +00003362 Replacement);
3363 TLB.TypeWasModifiedSafely(Result);
3364 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003365 // Otherwise, complain about the addition of a qualifier to an
3366 // already-qualified type.
3367 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003368 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003369 << Result << R;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003370
Douglas Gregore559ca12011-06-17 22:11:49 +00003371 Quals.removeObjCLifetime();
3372 }
3373 }
3374 }
John McCall28654742010-06-05 06:41:15 +00003375 if (!Quals.empty()) {
3376 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3377 TLB.push<QualifiedTypeLoc>(Result);
3378 // No location information to preserve.
3379 }
John McCalla2becad2009-10-21 00:40:46 +00003380
3381 return Result;
3382}
3383
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003384template<typename Derived>
3385TypeLoc
3386TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3387 QualType ObjectType,
3388 NamedDecl *UnqualLookup,
3389 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003390 QualType T = TL.getType();
3391 if (getDerived().AlreadyTransformed(T))
3392 return TL;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003393
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003394 TypeLocBuilder TLB;
3395 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003396
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003397 if (isa<TemplateSpecializationType>(T)) {
3398 TemplateSpecializationTypeLoc SpecTL
3399 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003400
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003401 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003402 getDerived().TransformTemplateName(SS,
3403 SpecTL.getTypePtr()->getTemplateName(),
3404 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003405 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003406 if (Template.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003407 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003408
3409 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003410 Template);
3411 } else if (isa<DependentTemplateSpecializationType>(T)) {
3412 DependentTemplateSpecializationTypeLoc SpecTL
3413 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003414
Douglas Gregora88f09f2011-02-28 17:23:35 +00003415 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003416 = getDerived().RebuildTemplateName(SS,
3417 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003418 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003419 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003420 if (Template.isNull())
3421 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003422
3423 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003424 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003425 Template,
3426 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003427 } else {
3428 // Nothing special needs to be done for these.
3429 Result = getDerived().TransformType(TLB, TL);
3430 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003431
3432 if (Result.isNull())
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003433 return TypeLoc();
Chad Rosier4a9d7952012-08-08 18:46:20 +00003434
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003435 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3436}
3437
Douglas Gregorb71d8212011-03-02 18:32:08 +00003438template<typename Derived>
3439TypeSourceInfo *
3440TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3441 QualType ObjectType,
3442 NamedDecl *UnqualLookup,
3443 CXXScopeSpec &SS) {
3444 // FIXME: Painfully copy-paste from the above!
Chad Rosier4a9d7952012-08-08 18:46:20 +00003445
Douglas Gregorb71d8212011-03-02 18:32:08 +00003446 QualType T = TSInfo->getType();
3447 if (getDerived().AlreadyTransformed(T))
3448 return TSInfo;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003449
Douglas Gregorb71d8212011-03-02 18:32:08 +00003450 TypeLocBuilder TLB;
3451 QualType Result;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003452
Douglas Gregorb71d8212011-03-02 18:32:08 +00003453 TypeLoc TL = TSInfo->getTypeLoc();
3454 if (isa<TemplateSpecializationType>(T)) {
3455 TemplateSpecializationTypeLoc SpecTL
3456 = cast<TemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003457
Douglas Gregorb71d8212011-03-02 18:32:08 +00003458 TemplateName Template
3459 = getDerived().TransformTemplateName(SS,
3460 SpecTL.getTypePtr()->getTemplateName(),
3461 SpecTL.getTemplateNameLoc(),
3462 ObjectType, UnqualLookup);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003463 if (Template.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003464 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003465
3466 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003467 Template);
3468 } else if (isa<DependentTemplateSpecializationType>(T)) {
3469 DependentTemplateSpecializationTypeLoc SpecTL
3470 = cast<DependentTemplateSpecializationTypeLoc>(TL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003471
Douglas Gregorb71d8212011-03-02 18:32:08 +00003472 TemplateName Template
Chad Rosier4a9d7952012-08-08 18:46:20 +00003473 = getDerived().RebuildTemplateName(SS,
3474 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003475 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003476 ObjectType, UnqualLookup);
3477 if (Template.isNull())
3478 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003479
3480 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregorb71d8212011-03-02 18:32:08 +00003481 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003482 Template,
3483 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003484 } else {
3485 // Nothing special needs to be done for these.
3486 Result = getDerived().TransformType(TLB, TL);
3487 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003488
3489 if (Result.isNull())
Douglas Gregorb71d8212011-03-02 18:32:08 +00003490 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003491
Douglas Gregorb71d8212011-03-02 18:32:08 +00003492 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3493}
3494
John McCalla2becad2009-10-21 00:40:46 +00003495template <class TyLoc> static inline
3496QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3497 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3498 NewT.setNameLoc(T.getNameLoc());
3499 return T.getType();
3500}
3501
John McCalla2becad2009-10-21 00:40:46 +00003502template<typename Derived>
3503QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003504 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003505 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3506 NewT.setBuiltinLoc(T.getBuiltinLoc());
3507 if (T.needsExtraLocalData())
3508 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3509 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003510}
Mike Stump1eb44332009-09-09 15:08:12 +00003511
Douglas Gregor577f75a2009-08-04 16:50:30 +00003512template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003513QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003514 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003515 // FIXME: recurse?
3516 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003517}
Mike Stump1eb44332009-09-09 15:08:12 +00003518
Douglas Gregor577f75a2009-08-04 16:50:30 +00003519template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003520QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003521 PointerTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003522 QualType PointeeType
3523 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003524 if (PointeeType.isNull())
3525 return QualType();
3526
3527 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003528 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003529 // A dependent pointer type 'T *' has is being transformed such
3530 // that an Objective-C class type is being replaced for 'T'. The
3531 // resulting pointer type is an ObjCObjectPointerType, not a
3532 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003533 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003534
John McCallc12c5bb2010-05-15 11:32:37 +00003535 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3536 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003537 return Result;
3538 }
John McCall43fed0d2010-11-12 08:19:04 +00003539
Douglas Gregor92e986e2010-04-22 16:44:27 +00003540 if (getDerived().AlwaysRebuild() ||
3541 PointeeType != TL.getPointeeLoc().getType()) {
3542 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3543 if (Result.isNull())
3544 return QualType();
3545 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003546
John McCallf85e1932011-06-15 23:02:42 +00003547 // Objective-C ARC can add lifetime qualifiers to the type that we're
3548 // pointing to.
3549 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003550
Douglas Gregor92e986e2010-04-22 16:44:27 +00003551 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3552 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003553 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003554}
Mike Stump1eb44332009-09-09 15:08:12 +00003555
3556template<typename Derived>
3557QualType
John McCalla2becad2009-10-21 00:40:46 +00003558TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003559 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003560 QualType PointeeType
Chad Rosier4a9d7952012-08-08 18:46:20 +00003561 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3562 if (PointeeType.isNull())
3563 return QualType();
3564
3565 QualType Result = TL.getType();
3566 if (getDerived().AlwaysRebuild() ||
3567 PointeeType != TL.getPointeeLoc().getType()) {
3568 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003569 TL.getSigilLoc());
3570 if (Result.isNull())
3571 return QualType();
3572 }
3573
Douglas Gregor39968ad2010-04-22 16:50:51 +00003574 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003575 NewT.setSigilLoc(TL.getSigilLoc());
3576 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577}
3578
John McCall85737a72009-10-30 00:06:24 +00003579/// Transforms a reference type. Note that somewhat paradoxically we
3580/// don't care whether the type itself is an l-value type or an r-value
3581/// type; we only care if the type was *written* as an l-value type
3582/// or an r-value type.
3583template<typename Derived>
3584QualType
3585TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003586 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003587 const ReferenceType *T = TL.getTypePtr();
3588
3589 // Note that this works with the pointee-as-written.
3590 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3591 if (PointeeType.isNull())
3592 return QualType();
3593
3594 QualType Result = TL.getType();
3595 if (getDerived().AlwaysRebuild() ||
3596 PointeeType != T->getPointeeTypeAsWritten()) {
3597 Result = getDerived().RebuildReferenceType(PointeeType,
3598 T->isSpelledAsLValue(),
3599 TL.getSigilLoc());
3600 if (Result.isNull())
3601 return QualType();
3602 }
3603
John McCallf85e1932011-06-15 23:02:42 +00003604 // Objective-C ARC can add lifetime qualifiers to the type that we're
3605 // referring to.
3606 TLB.TypeWasModifiedSafely(
3607 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3608
John McCall85737a72009-10-30 00:06:24 +00003609 // r-value references can be rebuilt as l-value references.
3610 ReferenceTypeLoc NewTL;
3611 if (isa<LValueReferenceType>(Result))
3612 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3613 else
3614 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3615 NewTL.setSigilLoc(TL.getSigilLoc());
3616
3617 return Result;
3618}
3619
Mike Stump1eb44332009-09-09 15:08:12 +00003620template<typename Derived>
3621QualType
John McCalla2becad2009-10-21 00:40:46 +00003622TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003623 LValueReferenceTypeLoc TL) {
3624 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003625}
3626
Mike Stump1eb44332009-09-09 15:08:12 +00003627template<typename Derived>
3628QualType
John McCalla2becad2009-10-21 00:40:46 +00003629TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003630 RValueReferenceTypeLoc TL) {
3631 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003632}
Mike Stump1eb44332009-09-09 15:08:12 +00003633
Douglas Gregor577f75a2009-08-04 16:50:30 +00003634template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003635QualType
John McCalla2becad2009-10-21 00:40:46 +00003636TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003637 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003638 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003639 if (PointeeType.isNull())
3640 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003641
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003642 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3643 TypeSourceInfo* NewClsTInfo = 0;
3644 if (OldClsTInfo) {
3645 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3646 if (!NewClsTInfo)
3647 return QualType();
3648 }
3649
3650 const MemberPointerType *T = TL.getTypePtr();
3651 QualType OldClsType = QualType(T->getClass(), 0);
3652 QualType NewClsType;
3653 if (NewClsTInfo)
3654 NewClsType = NewClsTInfo->getType();
3655 else {
3656 NewClsType = getDerived().TransformType(OldClsType);
3657 if (NewClsType.isNull())
3658 return QualType();
3659 }
Mike Stump1eb44332009-09-09 15:08:12 +00003660
John McCalla2becad2009-10-21 00:40:46 +00003661 QualType Result = TL.getType();
3662 if (getDerived().AlwaysRebuild() ||
3663 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003664 NewClsType != OldClsType) {
3665 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003666 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003667 if (Result.isNull())
3668 return QualType();
3669 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003670
John McCalla2becad2009-10-21 00:40:46 +00003671 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3672 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003673 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003674
3675 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003676}
3677
Mike Stump1eb44332009-09-09 15:08:12 +00003678template<typename Derived>
3679QualType
John McCalla2becad2009-10-21 00:40:46 +00003680TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003681 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003682 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003683 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003684 if (ElementType.isNull())
3685 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003686
John McCalla2becad2009-10-21 00:40:46 +00003687 QualType Result = TL.getType();
3688 if (getDerived().AlwaysRebuild() ||
3689 ElementType != T->getElementType()) {
3690 Result = getDerived().RebuildConstantArrayType(ElementType,
3691 T->getSizeModifier(),
3692 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003693 T->getIndexTypeCVRQualifiers(),
3694 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003695 if (Result.isNull())
3696 return QualType();
3697 }
Eli Friedman457a3772012-01-25 22:19:07 +00003698
3699 // We might have either a ConstantArrayType or a VariableArrayType now:
3700 // a ConstantArrayType is allowed to have an element type which is a
3701 // VariableArrayType if the type is dependent. Fortunately, all array
3702 // types have the same location layout.
3703 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003704 NewTL.setLBracketLoc(TL.getLBracketLoc());
3705 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003706
John McCalla2becad2009-10-21 00:40:46 +00003707 Expr *Size = TL.getSizeExpr();
3708 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003709 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3710 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003711 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
Eli Friedmanac626012012-02-29 03:16:56 +00003712 Size = SemaRef.ActOnConstantExpression(Size).take();
John McCalla2becad2009-10-21 00:40:46 +00003713 }
3714 NewTL.setSizeExpr(Size);
3715
3716 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717}
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregor577f75a2009-08-04 16:50:30 +00003719template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003721 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003722 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003723 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003724 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003725 if (ElementType.isNull())
3726 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003727
John McCalla2becad2009-10-21 00:40:46 +00003728 QualType Result = TL.getType();
3729 if (getDerived().AlwaysRebuild() ||
3730 ElementType != T->getElementType()) {
3731 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003732 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003733 T->getIndexTypeCVRQualifiers(),
3734 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003735 if (Result.isNull())
3736 return QualType();
3737 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003738
John McCalla2becad2009-10-21 00:40:46 +00003739 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3740 NewTL.setLBracketLoc(TL.getLBracketLoc());
3741 NewTL.setRBracketLoc(TL.getRBracketLoc());
3742 NewTL.setSizeExpr(0);
3743
3744 return Result;
3745}
3746
3747template<typename Derived>
3748QualType
3749TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003750 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003751 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003752 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3753 if (ElementType.isNull())
3754 return QualType();
3755
John McCall60d7b3a2010-08-24 06:29:42 +00003756 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003757 = getDerived().TransformExpr(T->getSizeExpr());
3758 if (SizeResult.isInvalid())
3759 return QualType();
3760
John McCall9ae2f072010-08-23 23:25:46 +00003761 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003762
3763 QualType Result = TL.getType();
3764 if (getDerived().AlwaysRebuild() ||
3765 ElementType != T->getElementType() ||
3766 Size != T->getSizeExpr()) {
3767 Result = getDerived().RebuildVariableArrayType(ElementType,
3768 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003769 Size,
John McCalla2becad2009-10-21 00:40:46 +00003770 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003771 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003772 if (Result.isNull())
3773 return QualType();
3774 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003775
John McCalla2becad2009-10-21 00:40:46 +00003776 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3777 NewTL.setLBracketLoc(TL.getLBracketLoc());
3778 NewTL.setRBracketLoc(TL.getRBracketLoc());
3779 NewTL.setSizeExpr(Size);
3780
3781 return Result;
3782}
3783
3784template<typename Derived>
3785QualType
3786TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003787 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003788 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003789 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3790 if (ElementType.isNull())
3791 return QualType();
3792
Richard Smithf6702a32011-12-20 02:08:33 +00003793 // Array bounds are constant expressions.
3794 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3795 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003796
John McCall3b657512011-01-19 10:06:00 +00003797 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3798 Expr *origSize = TL.getSizeExpr();
3799 if (!origSize) origSize = T->getSizeExpr();
3800
3801 ExprResult sizeResult
3802 = getDerived().TransformExpr(origSize);
Eli Friedmanac626012012-02-29 03:16:56 +00003803 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall3b657512011-01-19 10:06:00 +00003804 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003805 return QualType();
3806
John McCall3b657512011-01-19 10:06:00 +00003807 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003808
3809 QualType Result = TL.getType();
3810 if (getDerived().AlwaysRebuild() ||
3811 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003812 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003813 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3814 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003815 size,
John McCalla2becad2009-10-21 00:40:46 +00003816 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003817 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003818 if (Result.isNull())
3819 return QualType();
3820 }
John McCalla2becad2009-10-21 00:40:46 +00003821
3822 // We might have any sort of array type now, but fortunately they
3823 // all have the same location layout.
3824 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3825 NewTL.setLBracketLoc(TL.getLBracketLoc());
3826 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003827 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003828
3829 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003830}
Mike Stump1eb44332009-09-09 15:08:12 +00003831
3832template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003833QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003834 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003835 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003836 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003837
3838 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003839 QualType ElementType = getDerived().TransformType(T->getElementType());
3840 if (ElementType.isNull())
3841 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003842
Richard Smithf6702a32011-12-20 02:08:33 +00003843 // Vector sizes are constant expressions.
3844 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3845 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003846
John McCall60d7b3a2010-08-24 06:29:42 +00003847 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanac626012012-02-29 03:16:56 +00003848 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003849 if (Size.isInvalid())
3850 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003851
John McCalla2becad2009-10-21 00:40:46 +00003852 QualType Result = TL.getType();
3853 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003854 ElementType != T->getElementType() ||
3855 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003856 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003857 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003859 if (Result.isNull())
3860 return QualType();
3861 }
John McCalla2becad2009-10-21 00:40:46 +00003862
3863 // Result might be dependent or not.
3864 if (isa<DependentSizedExtVectorType>(Result)) {
3865 DependentSizedExtVectorTypeLoc NewTL
3866 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3867 NewTL.setNameLoc(TL.getNameLoc());
3868 } else {
3869 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3870 NewTL.setNameLoc(TL.getNameLoc());
3871 }
3872
3873 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003874}
Mike Stump1eb44332009-09-09 15:08:12 +00003875
3876template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003877QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003878 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003879 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003880 QualType ElementType = getDerived().TransformType(T->getElementType());
3881 if (ElementType.isNull())
3882 return QualType();
3883
John McCalla2becad2009-10-21 00:40:46 +00003884 QualType Result = TL.getType();
3885 if (getDerived().AlwaysRebuild() ||
3886 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003887 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003888 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003889 if (Result.isNull())
3890 return QualType();
3891 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003892
John McCalla2becad2009-10-21 00:40:46 +00003893 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3894 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003895
John McCalla2becad2009-10-21 00:40:46 +00003896 return Result;
3897}
3898
3899template<typename Derived>
3900QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003901 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003902 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003903 QualType ElementType = getDerived().TransformType(T->getElementType());
3904 if (ElementType.isNull())
3905 return QualType();
3906
3907 QualType Result = TL.getType();
3908 if (getDerived().AlwaysRebuild() ||
3909 ElementType != T->getElementType()) {
3910 Result = getDerived().RebuildExtVectorType(ElementType,
3911 T->getNumElements(),
3912 /*FIXME*/ SourceLocation());
3913 if (Result.isNull())
3914 return QualType();
3915 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00003916
John McCalla2becad2009-10-21 00:40:46 +00003917 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3918 NewTL.setNameLoc(TL.getNameLoc());
3919
3920 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003921}
Mike Stump1eb44332009-09-09 15:08:12 +00003922
3923template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003924ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003925TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003926 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003927 llvm::Optional<unsigned> NumExpansions,
3928 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003929 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003930 TypeSourceInfo *NewDI = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003931
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003932 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00003933 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003934 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003935 TypeLoc OldTL = OldDI->getTypeLoc();
3936 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
Chad Rosier4a9d7952012-08-08 18:46:20 +00003937
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003938 TypeLocBuilder TLB;
3939 TypeLoc NewTL = OldDI->getTypeLoc();
3940 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00003941
3942 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003943 OldExpansionTL.getPatternLoc());
3944 if (Result.isNull())
3945 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003946
3947 Result = RebuildPackExpansionType(Result,
3948 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003949 OldExpansionTL.getEllipsisLoc(),
3950 NumExpansions);
3951 if (Result.isNull())
3952 return 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00003953
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 PackExpansionTypeLoc NewExpansionTL
3955 = TLB.push<PackExpansionTypeLoc>(Result);
3956 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3957 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3958 } else
3959 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003960 if (!NewDI)
3961 return 0;
3962
John McCallfb44de92011-05-01 22:35:37 +00003963 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003964 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003965
3966 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3967 OldParm->getDeclContext(),
3968 OldParm->getInnerLocStart(),
3969 OldParm->getLocation(),
3970 OldParm->getIdentifier(),
3971 NewDI->getType(),
3972 NewDI,
3973 OldParm->getStorageClass(),
3974 OldParm->getStorageClassAsWritten(),
3975 /* DefArg */ NULL);
3976 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3977 OldParm->getFunctionScopeIndex() + indexAdjustment);
3978 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003979}
3980
3981template<typename Derived>
3982bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003983 TransformFunctionTypeParams(SourceLocation Loc,
3984 ParmVarDecl **Params, unsigned NumParams,
3985 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003986 SmallVectorImpl<QualType> &OutParamTypes,
3987 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003988 int indexAdjustment = 0;
3989
Douglas Gregora009b592011-01-07 00:20:55 +00003990 for (unsigned i = 0; i != NumParams; ++i) {
3991 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003992 assert(OldParm->getFunctionScopeIndex() == i);
3993
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003994 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003995 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 if (OldParm->isParameterPack()) {
3997 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003998 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003999
Douglas Gregor603cfb42011-01-05 23:12:31 +00004000 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004001 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
4002 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
4003 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4004 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004005 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4006
Douglas Gregor603cfb42011-01-05 23:12:31 +00004007 // Determine whether we should expand the parameter packs.
4008 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004009 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004010 llvm::Optional<unsigned> OrigNumExpansions
4011 = ExpansionTL.getTypePtr()->getNumExpansions();
4012 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00004013 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4014 Pattern.getSourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004015 Unexpanded,
4016 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004017 RetainExpansion,
4018 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004019 return true;
4020 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004021
Douglas Gregor603cfb42011-01-05 23:12:31 +00004022 if (ShouldExpand) {
4023 // Expand the function parameter pack into multiple, separate
4024 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00004025 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00004026 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004028 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004029 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004030 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004031 OrigNumExpansions,
4032 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004033 if (!NewParm)
4034 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004035
Douglas Gregora009b592011-01-07 00:20:55 +00004036 OutParamTypes.push_back(NewParm->getType());
4037 if (PVars)
4038 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 }
Douglas Gregord3731192011-01-10 07:32:04 +00004040
4041 // If we're supposed to retain a pack expansion, do so by temporarily
4042 // forgetting the partially-substituted parameter pack.
4043 if (RetainExpansion) {
4044 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004045 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00004046 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004047 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004048 OrigNumExpansions,
4049 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00004050 if (!NewParm)
4051 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004052
Douglas Gregord3731192011-01-10 07:32:04 +00004053 OutParamTypes.push_back(NewParm->getType());
4054 if (PVars)
4055 PVars->push_back(NewParm);
4056 }
4057
John McCallfb44de92011-05-01 22:35:37 +00004058 // The next parameter should have the same adjustment as the
4059 // last thing we pushed, but we post-incremented indexAdjustment
4060 // on every push. Also, if we push nothing, the adjustment should
4061 // go down by one.
4062 indexAdjustment--;
4063
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 // We're done with the pack expansion.
4065 continue;
4066 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004067
4068 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00004070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4071 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004072 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004073 NumExpansions,
4074 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00004075 } else {
4076 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00004077 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00004078 llvm::Optional<unsigned>(),
4079 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00004081
John McCall21ef0fa2010-03-11 09:03:00 +00004082 if (!NewParm)
4083 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004084
Douglas Gregora009b592011-01-07 00:20:55 +00004085 OutParamTypes.push_back(NewParm->getType());
4086 if (PVars)
4087 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004088 continue;
4089 }
John McCall21ef0fa2010-03-11 09:03:00 +00004090
4091 // Deal with the possibility that we don't have a parameter
4092 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004093 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004094 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004095 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004096 QualType NewType;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004097 if (const PackExpansionType *Expansion
Douglas Gregor603cfb42011-01-05 23:12:31 +00004098 = dyn_cast<PackExpansionType>(OldType)) {
4099 // We have a function parameter pack that may need to be expanded.
4100 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004101 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004102 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004103
Douglas Gregor603cfb42011-01-05 23:12:31 +00004104 // Determine whether we should expand the parameter packs.
4105 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004106 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004107 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004108 Unexpanded,
4109 ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +00004110 RetainExpansion,
4111 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004112 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004113 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004114
Douglas Gregor603cfb42011-01-05 23:12:31 +00004115 if (ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004116 // Expand the function parameter pack into multiple, separate
Douglas Gregor603cfb42011-01-05 23:12:31 +00004117 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004118 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004119 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4120 QualType NewType = getDerived().TransformType(Pattern);
4121 if (NewType.isNull())
4122 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004123
Douglas Gregora009b592011-01-07 00:20:55 +00004124 OutParamTypes.push_back(NewType);
4125 if (PVars)
4126 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004127 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004128
Douglas Gregor603cfb42011-01-05 23:12:31 +00004129 // We're done with the pack expansion.
4130 continue;
4131 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004132
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004133 // If we're supposed to retain a pack expansion, do so by temporarily
4134 // forgetting the partially-substituted parameter pack.
4135 if (RetainExpansion) {
4136 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4137 QualType NewType = getDerived().TransformType(Pattern);
4138 if (NewType.isNull())
4139 return true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004140
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004141 OutParamTypes.push_back(NewType);
4142 if (PVars)
4143 PVars->push_back(0);
4144 }
Douglas Gregord3731192011-01-10 07:32:04 +00004145
Chad Rosier4a9d7952012-08-08 18:46:20 +00004146 // We'll substitute the parameter now without expanding the pack
Douglas Gregor603cfb42011-01-05 23:12:31 +00004147 // expansion.
4148 OldType = Expansion->getPattern();
4149 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004150 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4151 NewType = getDerived().TransformType(OldType);
4152 } else {
4153 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004154 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004155
Douglas Gregor603cfb42011-01-05 23:12:31 +00004156 if (NewType.isNull())
4157 return true;
4158
4159 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004160 NewType = getSema().Context.getPackExpansionType(NewType,
4161 NumExpansions);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004162
Douglas Gregora009b592011-01-07 00:20:55 +00004163 OutParamTypes.push_back(NewType);
4164 if (PVars)
4165 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004166 }
4167
John McCallfb44de92011-05-01 22:35:37 +00004168#ifndef NDEBUG
4169 if (PVars) {
4170 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4171 if (ParmVarDecl *parm = (*PVars)[i])
4172 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004173 }
John McCallfb44de92011-05-01 22:35:37 +00004174#endif
4175
4176 return false;
4177}
John McCall21ef0fa2010-03-11 09:03:00 +00004178
4179template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004180QualType
John McCalla2becad2009-10-21 00:40:46 +00004181TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004182 FunctionProtoTypeLoc TL) {
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004183 return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0);
4184}
4185
4186template<typename Derived>
4187QualType
4188TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
4189 FunctionProtoTypeLoc TL,
4190 CXXRecordDecl *ThisContext,
4191 unsigned ThisTypeQuals) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004192 // Transform the parameters and return type.
4193 //
Richard Smithe6975e92012-04-17 00:58:00 +00004194 // We are required to instantiate the params and return type in source order.
Douglas Gregordab60ad2010-10-01 18:44:50 +00004195 // When the function has a trailing return type, we instantiate the
4196 // parameters before the return type, since the return type can then refer
4197 // to the parameters themselves (via decltype, sizeof, etc.).
4198 //
Chris Lattner686775d2011-07-20 06:58:45 +00004199 SmallVector<QualType, 4> ParamTypes;
4200 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004201 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004202
Douglas Gregordab60ad2010-10-01 18:44:50 +00004203 QualType ResultType;
4204
Richard Smith9fbf3272012-08-14 22:51:13 +00004205 if (T->hasTrailingReturn()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004206 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004207 TL.getParmArray(),
4208 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004209 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004210 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004211 return QualType();
4212
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004213 {
4214 // C++11 [expr.prim.general]p3:
Chad Rosier4a9d7952012-08-08 18:46:20 +00004215 // If a declaration declares a member function or member function
4216 // template of a class X, the expression this is a prvalue of type
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004217 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier4a9d7952012-08-08 18:46:20 +00004218 // and the end of the function-definition, member-declarator, or
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004219 // declarator.
4220 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004221
Douglas Gregorcefc3af2012-04-16 07:05:22 +00004222 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4223 if (ResultType.isNull())
4224 return QualType();
4225 }
Douglas Gregordab60ad2010-10-01 18:44:50 +00004226 }
4227 else {
4228 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4229 if (ResultType.isNull())
4230 return QualType();
4231
Chad Rosier4a9d7952012-08-08 18:46:20 +00004232 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
Douglas Gregora009b592011-01-07 00:20:55 +00004233 TL.getParmArray(),
4234 TL.getNumArgs(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004235 TL.getTypePtr()->arg_type_begin(),
Douglas Gregora009b592011-01-07 00:20:55 +00004236 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004237 return QualType();
4238 }
4239
Richard Smithe6975e92012-04-17 00:58:00 +00004240 // FIXME: Need to transform the exception-specification too.
4241
John McCalla2becad2009-10-21 00:40:46 +00004242 QualType Result = TL.getType();
4243 if (getDerived().AlwaysRebuild() ||
4244 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004245 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004246 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4247 Result = getDerived().RebuildFunctionProtoType(ResultType,
4248 ParamTypes.data(),
4249 ParamTypes.size(),
4250 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004251 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004252 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004253 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004254 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004255 if (Result.isNull())
4256 return QualType();
4257 }
Mike Stump1eb44332009-09-09 15:08:12 +00004258
John McCalla2becad2009-10-21 00:40:46 +00004259 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004260 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4261 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004262 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4263 NewTL.setArg(i, ParamDecls[i]);
4264
4265 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266}
Mike Stump1eb44332009-09-09 15:08:12 +00004267
Douglas Gregor577f75a2009-08-04 16:50:30 +00004268template<typename Derived>
4269QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004270 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004271 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004272 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004273 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4274 if (ResultType.isNull())
4275 return QualType();
4276
4277 QualType Result = TL.getType();
4278 if (getDerived().AlwaysRebuild() ||
4279 ResultType != T->getResultType())
4280 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4281
4282 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004283 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4284 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCalla2becad2009-10-21 00:40:46 +00004285
4286 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287}
Mike Stump1eb44332009-09-09 15:08:12 +00004288
John McCalled976492009-12-04 22:46:56 +00004289template<typename Derived> QualType
4290TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004291 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004292 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004293 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004294 if (!D)
4295 return QualType();
4296
4297 QualType Result = TL.getType();
4298 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4299 Result = getDerived().RebuildUnresolvedUsingType(D);
4300 if (Result.isNull())
4301 return QualType();
4302 }
4303
4304 // We might get an arbitrary type spec type back. We should at
4305 // least always get a type spec type, though.
4306 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4307 NewTL.setNameLoc(TL.getNameLoc());
4308
4309 return Result;
4310}
4311
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004313QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004314 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004315 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004316 TypedefNameDecl *Typedef
4317 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4318 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004319 if (!Typedef)
4320 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004321
John McCalla2becad2009-10-21 00:40:46 +00004322 QualType Result = TL.getType();
4323 if (getDerived().AlwaysRebuild() ||
4324 Typedef != T->getDecl()) {
4325 Result = getDerived().RebuildTypedefType(Typedef);
4326 if (Result.isNull())
4327 return QualType();
4328 }
Mike Stump1eb44332009-09-09 15:08:12 +00004329
John McCalla2becad2009-10-21 00:40:46 +00004330 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4331 NewTL.setNameLoc(TL.getNameLoc());
4332
4333 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004334}
Mike Stump1eb44332009-09-09 15:08:12 +00004335
Douglas Gregor577f75a2009-08-04 16:50:30 +00004336template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004337QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004338 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004339 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004340 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004341
John McCall60d7b3a2010-08-24 06:29:42 +00004342 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004343 if (E.isInvalid())
4344 return QualType();
4345
Eli Friedman72b8b1e2012-02-29 04:03:55 +00004346 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4347 if (E.isInvalid())
4348 return QualType();
4349
John McCalla2becad2009-10-21 00:40:46 +00004350 QualType Result = TL.getType();
4351 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004352 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004353 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004354 if (Result.isNull())
4355 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004356 }
John McCalla2becad2009-10-21 00:40:46 +00004357 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCalla2becad2009-10-21 00:40:46 +00004359 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004360 NewTL.setTypeofLoc(TL.getTypeofLoc());
4361 NewTL.setLParenLoc(TL.getLParenLoc());
4362 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004363
4364 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365}
Mike Stump1eb44332009-09-09 15:08:12 +00004366
4367template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004368QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004369 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004370 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4371 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4372 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004373 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004374
John McCalla2becad2009-10-21 00:40:46 +00004375 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004376 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4377 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004378 if (Result.isNull())
4379 return QualType();
4380 }
Mike Stump1eb44332009-09-09 15:08:12 +00004381
John McCalla2becad2009-10-21 00:40:46 +00004382 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004383 NewTL.setTypeofLoc(TL.getTypeofLoc());
4384 NewTL.setLParenLoc(TL.getLParenLoc());
4385 NewTL.setRParenLoc(TL.getRParenLoc());
4386 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004393 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004394 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004395
Douglas Gregor670444e2009-08-04 22:27:00 +00004396 // decltype expressions are not potentially evaluated contexts
Richard Smith76f3f692012-02-22 02:04:18 +00004397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0,
4398 /*IsDecltype=*/ true);
Mike Stump1eb44332009-09-09 15:08:12 +00004399
John McCall60d7b3a2010-08-24 06:29:42 +00004400 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004401 if (E.isInvalid())
4402 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004403
Richard Smith76f3f692012-02-22 02:04:18 +00004404 E = getSema().ActOnDecltypeExpression(E.take());
4405 if (E.isInvalid())
4406 return QualType();
4407
John McCalla2becad2009-10-21 00:40:46 +00004408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
4410 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004411 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004412 if (Result.isNull())
4413 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414 }
John McCalla2becad2009-10-21 00:40:46 +00004415 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004416
John McCalla2becad2009-10-21 00:40:46 +00004417 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4418 NewTL.setNameLoc(TL.getNameLoc());
4419
4420 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004421}
4422
4423template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004424QualType TreeTransform<Derived>::TransformUnaryTransformType(
4425 TypeLocBuilder &TLB,
4426 UnaryTransformTypeLoc TL) {
4427 QualType Result = TL.getType();
4428 if (Result->isDependentType()) {
4429 const UnaryTransformType *T = TL.getTypePtr();
4430 QualType NewBase =
4431 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4432 Result = getDerived().RebuildUnaryTransformType(NewBase,
4433 T->getUTTKind(),
4434 TL.getKWLoc());
4435 if (Result.isNull())
4436 return QualType();
4437 }
4438
4439 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4440 NewTL.setKWLoc(TL.getKWLoc());
4441 NewTL.setParensRange(TL.getParensRange());
4442 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4443 return Result;
4444}
4445
4446template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004447QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4448 AutoTypeLoc TL) {
4449 const AutoType *T = TL.getTypePtr();
4450 QualType OldDeduced = T->getDeducedType();
4451 QualType NewDeduced;
4452 if (!OldDeduced.isNull()) {
4453 NewDeduced = getDerived().TransformType(OldDeduced);
4454 if (NewDeduced.isNull())
4455 return QualType();
4456 }
4457
4458 QualType Result = TL.getType();
4459 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4460 Result = getDerived().RebuildAutoType(NewDeduced);
4461 if (Result.isNull())
4462 return QualType();
4463 }
4464
4465 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4466 NewTL.setNameLoc(TL.getNameLoc());
4467
4468 return Result;
4469}
4470
4471template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004472QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004473 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004474 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004475 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004476 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4477 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004478 if (!Record)
4479 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004480
John McCalla2becad2009-10-21 00:40:46 +00004481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 Record != T->getDecl()) {
4484 Result = getDerived().RebuildRecordType(Record);
4485 if (Result.isNull())
4486 return QualType();
4487 }
Mike Stump1eb44332009-09-09 15:08:12 +00004488
John McCalla2becad2009-10-21 00:40:46 +00004489 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4490 NewTL.setNameLoc(TL.getNameLoc());
4491
4492 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004493}
Mike Stump1eb44332009-09-09 15:08:12 +00004494
4495template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004496QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004497 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004498 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004499 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004500 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4501 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004502 if (!Enum)
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 Enum != T->getDecl()) {
4508 Result = getDerived().RebuildEnumType(Enum);
4509 if (Result.isNull())
4510 return QualType();
4511 }
Mike Stump1eb44332009-09-09 15:08:12 +00004512
John McCalla2becad2009-10-21 00:40:46 +00004513 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4514 NewTL.setNameLoc(TL.getNameLoc());
4515
4516 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004517}
John McCall7da24312009-09-05 00:15:47 +00004518
John McCall3cb0ebd2010-03-10 03:28:59 +00004519template<typename Derived>
4520QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4521 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004522 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004523 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4524 TL.getTypePtr()->getDecl());
4525 if (!D) return QualType();
4526
4527 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4528 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4529 return T;
4530}
4531
Douglas Gregor577f75a2009-08-04 16:50:30 +00004532template<typename Derived>
4533QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004534 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004535 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004536 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004537}
4538
Mike Stump1eb44332009-09-09 15:08:12 +00004539template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004540QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004541 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004542 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004543 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004544
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004545 // Substitute into the replacement type, which itself might involve something
4546 // that needs to be transformed. This only tends to occur with default
4547 // template arguments of template template parameters.
4548 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4549 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4550 if (Replacement.isNull())
4551 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004552
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004553 // Always canonicalize the replacement type.
4554 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4555 QualType Result
Chad Rosier4a9d7952012-08-08 18:46:20 +00004556 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004557 Replacement);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004558
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004559 // Propagate type-source information.
4560 SubstTemplateTypeParmTypeLoc NewTL
4561 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4562 NewTL.setNameLoc(TL.getNameLoc());
4563 return Result;
4564
John McCall49a832b2009-10-18 09:09:24 +00004565}
4566
4567template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004568QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4569 TypeLocBuilder &TLB,
4570 SubstTemplateTypeParmPackTypeLoc TL) {
4571 return TransformTypeSpecType(TLB, TL);
4572}
4573
4574template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004575QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004576 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004577 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004578 const TemplateSpecializationType *T = TL.getTypePtr();
4579
Douglas Gregor1d752d72011-03-02 18:46:51 +00004580 // The nested-name-specifier never matters in a TemplateSpecializationType,
4581 // because we can't have a dependent nested-name-specifier anyway.
4582 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004583 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004584 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4585 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004586 if (Template.isNull())
4587 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004588
John McCall43fed0d2010-11-12 08:19:04 +00004589 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4590}
4591
Eli Friedmanb001de72011-10-06 23:00:33 +00004592template<typename Derived>
4593QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4594 AtomicTypeLoc TL) {
4595 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4596 if (ValueType.isNull())
4597 return QualType();
4598
4599 QualType Result = TL.getType();
4600 if (getDerived().AlwaysRebuild() ||
4601 ValueType != TL.getValueLoc().getType()) {
4602 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4603 if (Result.isNull())
4604 return QualType();
4605 }
4606
4607 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4608 NewTL.setKWLoc(TL.getKWLoc());
4609 NewTL.setLParenLoc(TL.getLParenLoc());
4610 NewTL.setRParenLoc(TL.getRParenLoc());
4611
4612 return Result;
4613}
4614
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004615namespace {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004616 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004617 /// container that provides a \c getArgLoc() member function.
4618 ///
4619 /// This iterator is intended to be used with the iterator form of
4620 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4621 template<typename ArgLocContainer>
4622 class TemplateArgumentLocContainerIterator {
4623 ArgLocContainer *Container;
4624 unsigned Index;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004625
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004626 public:
4627 typedef TemplateArgumentLoc value_type;
4628 typedef TemplateArgumentLoc reference;
4629 typedef int difference_type;
4630 typedef std::input_iterator_tag iterator_category;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004631
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004632 class pointer {
4633 TemplateArgumentLoc Arg;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004634
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004635 public:
4636 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004637
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004638 const TemplateArgumentLoc *operator->() const {
4639 return &Arg;
4640 }
4641 };
Chad Rosier4a9d7952012-08-08 18:46:20 +00004642
4643
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004644 TemplateArgumentLocContainerIterator() {}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004645
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004646 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4647 unsigned Index)
4648 : Container(&Container), Index(Index) { }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004649
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004650 TemplateArgumentLocContainerIterator &operator++() {
4651 ++Index;
4652 return *this;
4653 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004654
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004655 TemplateArgumentLocContainerIterator operator++(int) {
4656 TemplateArgumentLocContainerIterator Old(*this);
4657 ++(*this);
4658 return Old;
4659 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004660
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004661 TemplateArgumentLoc operator*() const {
4662 return Container->getArgLoc(Index);
4663 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004664
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004665 pointer operator->() const {
4666 return pointer(Container->getArgLoc(Index));
4667 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004668
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004669 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004670 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004671 return X.Container == Y.Container && X.Index == Y.Index;
4672 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004673
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004674 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004675 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004676 return !(X == Y);
4677 }
4678 };
4679}
Chad Rosier4a9d7952012-08-08 18:46:20 +00004680
4681
John McCall43fed0d2010-11-12 08:19:04 +00004682template <typename Derived>
4683QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4684 TypeLocBuilder &TLB,
4685 TemplateSpecializationTypeLoc TL,
4686 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004687 TemplateArgumentListInfo NewTemplateArgs;
4688 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4689 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004690 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4691 ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004692 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004693 ArgIterator(TL, TL.getNumArgs()),
4694 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004695 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004696
John McCall833ca992009-10-29 08:12:44 +00004697 // FIXME: maybe don't rebuild if all the template arguments are the same.
4698
4699 QualType Result =
4700 getDerived().RebuildTemplateSpecializationType(Template,
4701 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004702 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004703
4704 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004705 // Specializations of template template parameters are represented as
4706 // TemplateSpecializationTypes, and substitution of type alias templates
4707 // within a dependent context can transform them into
4708 // DependentTemplateSpecializationTypes.
4709 if (isa<DependentTemplateSpecializationType>(Result)) {
4710 DependentTemplateSpecializationTypeLoc NewTL
4711 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004712 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004713 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004714 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004715 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004716 NewTL.setLAngleLoc(TL.getLAngleLoc());
4717 NewTL.setRAngleLoc(TL.getRAngleLoc());
4718 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4719 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4720 return Result;
4721 }
4722
John McCall833ca992009-10-29 08:12:44 +00004723 TemplateSpecializationTypeLoc NewTL
4724 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004725 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004726 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4727 NewTL.setLAngleLoc(TL.getLAngleLoc());
4728 NewTL.setRAngleLoc(TL.getRAngleLoc());
4729 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4730 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004731 }
Mike Stump1eb44332009-09-09 15:08:12 +00004732
John McCall833ca992009-10-29 08:12:44 +00004733 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004734}
Mike Stump1eb44332009-09-09 15:08:12 +00004735
Douglas Gregora88f09f2011-02-28 17:23:35 +00004736template <typename Derived>
4737QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4738 TypeLocBuilder &TLB,
4739 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004740 TemplateName Template,
4741 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004742 TemplateArgumentListInfo NewTemplateArgs;
4743 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4744 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4745 typedef TemplateArgumentLocContainerIterator<
4746 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier4a9d7952012-08-08 18:46:20 +00004747 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004748 ArgIterator(TL, TL.getNumArgs()),
4749 NewTemplateArgs))
4750 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004751
Douglas Gregora88f09f2011-02-28 17:23:35 +00004752 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier4a9d7952012-08-08 18:46:20 +00004753
Douglas Gregora88f09f2011-02-28 17:23:35 +00004754 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4755 QualType Result
4756 = getSema().Context.getDependentTemplateSpecializationType(
4757 TL.getTypePtr()->getKeyword(),
4758 DTN->getQualifier(),
4759 DTN->getIdentifier(),
4760 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004761
Douglas Gregora88f09f2011-02-28 17:23:35 +00004762 DependentTemplateSpecializationTypeLoc NewTL
4763 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004764 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004765 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004766 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004767 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004768 NewTL.setLAngleLoc(TL.getLAngleLoc());
4769 NewTL.setRAngleLoc(TL.getRAngleLoc());
4770 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4771 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4772 return Result;
4773 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004774
4775 QualType Result
Douglas Gregora88f09f2011-02-28 17:23:35 +00004776 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004777 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004778 NewTemplateArgs);
Chad Rosier4a9d7952012-08-08 18:46:20 +00004779
Douglas Gregora88f09f2011-02-28 17:23:35 +00004780 if (!Result.isNull()) {
4781 /// FIXME: Wrap this in an elaborated-type-specifier?
4782 TemplateSpecializationTypeLoc NewTL
4783 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004784 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004785 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004786 NewTL.setLAngleLoc(TL.getLAngleLoc());
4787 NewTL.setRAngleLoc(TL.getRAngleLoc());
4788 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4789 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4790 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004791
Douglas Gregora88f09f2011-02-28 17:23:35 +00004792 return Result;
4793}
4794
Mike Stump1eb44332009-09-09 15:08:12 +00004795template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004796QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004797TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004798 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004799 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004800
Douglas Gregor9e876872011-03-01 18:12:44 +00004801 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004802 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004803 if (TL.getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00004804 QualifierLoc
Douglas Gregor9e876872011-03-01 18:12:44 +00004805 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4806 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004807 return QualType();
4808 }
Mike Stump1eb44332009-09-09 15:08:12 +00004809
John McCall43fed0d2010-11-12 08:19:04 +00004810 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4811 if (NamedT.isNull())
4812 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004813
Richard Smith3e4c6c42011-05-05 21:57:07 +00004814 // C++0x [dcl.type.elab]p2:
4815 // If the identifier resolves to a typedef-name or the simple-template-id
4816 // resolves to an alias template specialization, the
4817 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004818 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4819 if (const TemplateSpecializationType *TST =
4820 NamedT->getAs<TemplateSpecializationType>()) {
4821 TemplateName Template = TST->getTemplateName();
4822 if (TypeAliasTemplateDecl *TAT =
4823 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4824 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4825 diag::err_tag_reference_non_tag) << 4;
4826 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4827 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004828 }
4829 }
4830
John McCalla2becad2009-10-21 00:40:46 +00004831 QualType Result = TL.getType();
4832 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004833 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004834 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004835 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00004836 T->getKeyword(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004837 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004838 if (Result.isNull())
4839 return QualType();
4840 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004841
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004842 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004843 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004844 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004845 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004846}
Mike Stump1eb44332009-09-09 15:08:12 +00004847
4848template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004849QualType TreeTransform<Derived>::TransformAttributedType(
4850 TypeLocBuilder &TLB,
4851 AttributedTypeLoc TL) {
4852 const AttributedType *oldType = TL.getTypePtr();
4853 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4854 if (modifiedType.isNull())
4855 return QualType();
4856
4857 QualType result = TL.getType();
4858
4859 // FIXME: dependent operand expressions?
4860 if (getDerived().AlwaysRebuild() ||
4861 modifiedType != oldType->getModifiedType()) {
4862 // TODO: this is really lame; we should really be rebuilding the
4863 // equivalent type from first principles.
4864 QualType equivalentType
4865 = getDerived().TransformType(oldType->getEquivalentType());
4866 if (equivalentType.isNull())
4867 return QualType();
4868 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4869 modifiedType,
4870 equivalentType);
4871 }
4872
4873 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4874 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4875 if (TL.hasAttrOperand())
4876 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4877 if (TL.hasAttrExprOperand())
4878 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4879 else if (TL.hasAttrEnumOperand())
4880 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4881
4882 return result;
4883}
4884
4885template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004886QualType
4887TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4888 ParenTypeLoc TL) {
4889 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4890 if (Inner.isNull())
4891 return QualType();
4892
4893 QualType Result = TL.getType();
4894 if (getDerived().AlwaysRebuild() ||
4895 Inner != TL.getInnerLoc().getType()) {
4896 Result = getDerived().RebuildParenType(Inner);
4897 if (Result.isNull())
4898 return QualType();
4899 }
4900
4901 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4902 NewTL.setLParenLoc(TL.getLParenLoc());
4903 NewTL.setRParenLoc(TL.getRParenLoc());
4904 return Result;
4905}
4906
4907template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004908QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004909 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004910 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004911
Douglas Gregor2494dd02011-03-01 01:34:45 +00004912 NestedNameSpecifierLoc QualifierLoc
4913 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4914 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004915 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004916
John McCall33500952010-06-11 00:33:02 +00004917 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004918 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004919 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004920 QualifierLoc,
4921 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004922 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004923 if (Result.isNull())
4924 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004926 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4927 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004928 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4929
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004930 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004931 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004932 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004933 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004934 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004935 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004936 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004937 NewTL.setNameLoc(TL.getNameLoc());
4938 }
John McCalla2becad2009-10-21 00:40:46 +00004939 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004940}
Mike Stump1eb44332009-09-09 15:08:12 +00004941
Douglas Gregor577f75a2009-08-04 16:50:30 +00004942template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004943QualType TreeTransform<Derived>::
4944 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004945 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004946 NestedNameSpecifierLoc QualifierLoc;
4947 if (TL.getQualifierLoc()) {
4948 QualifierLoc
4949 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4950 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004951 return QualType();
4952 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00004953
John McCall43fed0d2010-11-12 08:19:04 +00004954 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004955 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004956}
4957
4958template<typename Derived>
4959QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004960TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4961 DependentTemplateSpecializationTypeLoc TL,
4962 NestedNameSpecifierLoc QualifierLoc) {
4963 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004964
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004965 TemplateArgumentListInfo NewTemplateArgs;
4966 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4967 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004968
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004969 typedef TemplateArgumentLocContainerIterator<
4970 DependentTemplateSpecializationTypeLoc> ArgIterator;
4971 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4972 ArgIterator(TL, TL.getNumArgs()),
4973 NewTemplateArgs))
4974 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004975
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004976 QualType Result
4977 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4978 QualifierLoc,
4979 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004980 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004981 NewTemplateArgs);
4982 if (Result.isNull())
4983 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004984
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004985 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4986 QualType NamedT = ElabT->getNamedType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00004987
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004988 // Copy information relevant to the template specialization.
4989 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004990 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004991 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004992 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004993 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4994 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004995 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004996 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier4a9d7952012-08-08 18:46:20 +00004997
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004998 // Copy information relevant to the elaborated type.
4999 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00005000 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005001 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005002 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5003 DependentTemplateSpecializationTypeLoc SpecTL
5004 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005005 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005006 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005007 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005008 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005009 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5010 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005011 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005012 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005013 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005014 TemplateSpecializationTypeLoc SpecTL
5015 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00005016 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00005017 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005018 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5019 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00005020 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00005021 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00005022 }
5023 return Result;
5024}
5025
5026template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00005027QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5028 PackExpansionTypeLoc TL) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005029 QualType Pattern
5030 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005031 if (Pattern.isNull())
5032 return QualType();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005033
5034 QualType Result = TL.getType();
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005035 if (getDerived().AlwaysRebuild() ||
5036 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005037 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005038 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00005039 TL.getEllipsisLoc(),
5040 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005041 if (Result.isNull())
5042 return QualType();
5043 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005044
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00005045 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5046 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5047 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00005048}
5049
5050template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005051QualType
5052TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005053 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005054 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005055 TLB.pushFullCopy(TL);
5056 return TL.getType();
5057}
5058
5059template<typename Derived>
5060QualType
5061TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005062 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00005063 // ObjCObjectType is never dependent.
5064 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005065 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00005066}
Mike Stump1eb44332009-09-09 15:08:12 +00005067
5068template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005069QualType
5070TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00005071 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00005072 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00005073 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00005074 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00005075}
5076
Douglas Gregor577f75a2009-08-04 16:50:30 +00005077//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00005078// Statement transformation
5079//===----------------------------------------------------------------------===//
5080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005082TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005084}
5085
5086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005088TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5089 return getDerived().TransformCompoundStmt(S, false);
5090}
5091
5092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005094TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 bool IsStmtExpr) {
Dmitri Gribenko625bb562012-02-14 22:14:32 +00005096 Sema::CompoundScopeRAII CompoundScope(getSema());
5097
John McCall7114cba2010-08-27 19:56:05 +00005098 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00005099 bool SubStmtChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005100 SmallVector<Stmt*, 8> Statements;
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
5102 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00005103 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00005104 if (Result.isInvalid()) {
5105 // Immediately fail if this was a DeclStmt, since it's very
5106 // likely that this will cause problems for future statements.
5107 if (isa<DeclStmt>(*B))
5108 return StmtError();
5109
5110 // Otherwise, just keep processing substatements and fail later.
5111 SubStmtInvalid = true;
5112 continue;
5113 }
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 SubStmtChanged = SubStmtChanged || Result.get() != *B;
5116 Statements.push_back(Result.takeAs<Stmt>());
5117 }
Mike Stump1eb44332009-09-09 15:08:12 +00005118
John McCall7114cba2010-08-27 19:56:05 +00005119 if (SubStmtInvalid)
5120 return StmtError();
5121
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 if (!getDerived().AlwaysRebuild() &&
5123 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005124 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005125
5126 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005127 Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 S->getRBracLoc(),
5129 IsStmtExpr);
5130}
Mike Stump1eb44332009-09-09 15:08:12 +00005131
Douglas Gregor43959a92009-08-20 07:17:43 +00005132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005133StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005134TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005135 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005136 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005137 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5138 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005139
Eli Friedman264c1f82009-11-19 03:14:00 +00005140 // Transform the left-hand case value.
5141 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005142 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005143 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005145
Eli Friedman264c1f82009-11-19 03:14:00 +00005146 // Transform the right-hand case value (for the GNU case-range extension).
5147 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanac626012012-02-29 03:16:56 +00005148 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman264c1f82009-11-19 03:14:00 +00005149 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005150 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005151 }
Mike Stump1eb44332009-09-09 15:08:12 +00005152
Douglas Gregor43959a92009-08-20 07:17:43 +00005153 // Build the case statement.
5154 // Case statements are always rebuilt so that they will attached to their
5155 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005156 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005157 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005158 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005159 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005160 S->getColonLoc());
5161 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005165 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005170 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171}
5172
5173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005174StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005175TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005177 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005179 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Default statements are always rebuilt
5182 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005183 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005184}
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005187StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005188TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005189 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005191 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Chris Lattner57ad3782011-02-17 20:34:02 +00005193 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5194 S->getDecl());
5195 if (!LD)
5196 return StmtError();
Richard Smith534986f2012-04-14 00:33:13 +00005197
5198
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005200 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005201 cast<LabelDecl>(LD), SourceLocation(),
5202 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005203}
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregor43959a92009-08-20 07:17:43 +00005205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005206StmtResult
Richard Smith534986f2012-04-14 00:33:13 +00005207TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5208 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5209 if (SubStmt.isInvalid())
5210 return StmtError();
5211
5212 // TODO: transform attributes
5213 if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */)
5214 return S;
5215
5216 return getDerived().RebuildAttributedStmt(S->getAttrLoc(),
5217 S->getAttrs(),
5218 SubStmt.get());
5219}
5220
5221template<typename Derived>
5222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005228 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005236 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005240
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005241 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005242 if (S->getCond()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005243 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005244 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005245 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005247
John McCall9ae2f072010-08-23 23:25:46 +00005248 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005249 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005250 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005251
John McCall9ae2f072010-08-23 23:25:46 +00005252 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5253 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005254 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005255
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005257 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005260
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005262 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005264 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregor43959a92009-08-20 07:17:43 +00005266 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005267 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005268 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005269 Then.get() == S->getThen() &&
5270 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005271 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005273 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005274 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005275 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005276}
5277
5278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005281 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005282 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005283 VarDecl *ConditionVar = 0;
5284 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005285 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005286 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005287 getDerived().TransformDefinition(
5288 S->getConditionVariable()->getLocation(),
5289 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005290 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005291 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005292 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005293 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005294
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005295 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005296 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005297 }
Mike Stump1eb44332009-09-09 15:08:12 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005300 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005301 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005302 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005303 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor43959a92009-08-20 07:17:43 +00005306 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005307 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005309 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005312 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5313 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005319 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005320 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005321 VarDecl *ConditionVar = 0;
5322 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005323 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005324 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005325 getDerived().TransformDefinition(
5326 S->getConditionVariable()->getLocation(),
5327 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005328 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005330 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005331 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005332
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005333 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005335
5336 if (S->getCond()) {
5337 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005338 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005339 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005340 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005341 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005342 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005343 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005344 }
Mike Stump1eb44332009-09-09 15:08:12 +00005345
John McCall9ae2f072010-08-23 23:25:46 +00005346 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5347 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005348 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005349
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005351 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005353 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005356 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005357 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005358 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005359 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005361 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005362 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005363}
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor43959a92009-08-20 07:17:43 +00005365template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005366StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005367TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005368 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005369 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005370 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005373 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005374 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005375 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005377
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (!getDerived().AlwaysRebuild() &&
5379 Cond.get() == S->getCond() &&
5380 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005381 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005382
John McCall9ae2f072010-08-23 23:25:46 +00005383 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5384 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 S->getRParenLoc());
5386}
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005389StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005390TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005391 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005392 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005394 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005395
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005398 VarDecl *ConditionVar = 0;
5399 if (S->getConditionVariable()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005400 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005401 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005402 getDerived().TransformDefinition(
5403 S->getConditionVariable()->getLocation(),
5404 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005405 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005406 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005407 } else {
5408 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005409
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005410 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005412
5413 if (S->getCond()) {
5414 // Convert the condition to a boolean value.
Chad Rosier4a9d7952012-08-08 18:46:20 +00005415 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005416 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005417 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005419
John McCall9ae2f072010-08-23 23:25:46 +00005420 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005421 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005422 }
Mike Stump1eb44332009-09-09 15:08:12 +00005423
Chad Rosier4a9d7952012-08-08 18:46:20 +00005424 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
John McCall9ae2f072010-08-23 23:25:46 +00005425 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005427
Douglas Gregor43959a92009-08-20 07:17:43 +00005428 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005429 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005430 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005431 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005432
John McCall9ae2f072010-08-23 23:25:46 +00005433 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5434 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005435 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005436
Douglas Gregor43959a92009-08-20 07:17:43 +00005437 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005438 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005439 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregor43959a92009-08-20 07:17:43 +00005442 if (!getDerived().AlwaysRebuild() &&
5443 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005444 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005445 Inc.get() == S->getInc() &&
5446 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005447 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Douglas Gregor43959a92009-08-20 07:17:43 +00005449 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 Init.get(), FullCond, ConditionVar,
5451 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005452}
5453
5454template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005455StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005456TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005457 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5458 S->getLabel());
5459 if (!LD)
5460 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005463 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005464 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
5466
5467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005470 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005471 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005473 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005474
Douglas Gregor43959a92009-08-20 07:17:43 +00005475 if (!getDerived().AlwaysRebuild() &&
5476 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005477 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005478
5479 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005480 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005481}
5482
5483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005484StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005485TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005486 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005487}
Mike Stump1eb44332009-09-09 15:08:12 +00005488
Douglas Gregor43959a92009-08-20 07:17:43 +00005489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005490StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005491TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005492 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005493}
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005496StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005497TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005498 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005499 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005500 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005501
Mike Stump1eb44332009-09-09 15:08:12 +00005502 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005503 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005504 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005505}
Mike Stump1eb44332009-09-09 15:08:12 +00005506
Douglas Gregor43959a92009-08-20 07:17:43 +00005507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005509TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005510 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005511 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005512 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5513 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005514 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5515 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005516 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005517 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregor43959a92009-08-20 07:17:43 +00005519 if (Transformed != *D)
5520 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005521
Douglas Gregor43959a92009-08-20 07:17:43 +00005522 Decls.push_back(Transformed);
5523 }
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005527
5528 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005529 S->getStartLoc(), S->getEndLoc());
5530}
Mike Stump1eb44332009-09-09 15:08:12 +00005531
Douglas Gregor43959a92009-08-20 07:17:43 +00005532template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005533StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005534TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005535
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005536 SmallVector<Expr*, 8> Constraints;
5537 SmallVector<Expr*, 8> Exprs;
Chris Lattner686775d2011-07-20 06:58:45 +00005538 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005539
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult AsmString;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005541 SmallVector<Expr*, 8> Clobbers;
Anders Carlsson703e3942010-01-24 05:50:09 +00005542
5543 bool ExprsChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005544
Anders Carlsson703e3942010-01-24 05:50:09 +00005545 // Go through the outputs.
5546 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005547 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005548
Anders Carlsson703e3942010-01-24 05:50:09 +00005549 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005550 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005551
Anders Carlsson703e3942010-01-24 05:50:09 +00005552 // Transform the output expr.
5553 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005554 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005555 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005556 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005557
Anders Carlsson703e3942010-01-24 05:50:09 +00005558 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005559
John McCall9ae2f072010-08-23 23:25:46 +00005560 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005561 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005562
Anders Carlsson703e3942010-01-24 05:50:09 +00005563 // Go through the inputs.
5564 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005565 Names.push_back(S->getInputIdentifier(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005566
Anders Carlsson703e3942010-01-24 05:50:09 +00005567 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005568 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier4a9d7952012-08-08 18:46:20 +00005569
Anders Carlsson703e3942010-01-24 05:50:09 +00005570 // Transform the input expr.
5571 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005572 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005573 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005574 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005575
Anders Carlsson703e3942010-01-24 05:50:09 +00005576 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005577
John McCall9ae2f072010-08-23 23:25:46 +00005578 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005579 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005580
Anders Carlsson703e3942010-01-24 05:50:09 +00005581 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005582 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005583
5584 // Go through the clobbers.
5585 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005586 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005587
5588 // No need to transform the asm string literal.
5589 AsmString = SemaRef.Owned(S->getAsmString());
5590
5591 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5592 S->isSimple(),
5593 S->isVolatile(),
5594 S->getNumOutputs(),
5595 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005596 Names.data(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005597 Constraints,
5598 Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00005599 AsmString.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005600 Clobbers,
Chad Rosierdf4ee102012-08-20 17:11:53 +00005601 S->getRParenLoc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005602}
5603
Chad Rosier8cd64b42012-06-11 20:47:18 +00005604template<typename Derived>
5605StmtResult
5606TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier79efe242012-08-07 00:29:06 +00005607 ArrayRef<Token> AsmToks =
5608 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier62f22b82012-08-08 19:48:07 +00005609
Chad Rosier7bd092b2012-08-15 16:53:30 +00005610 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
5611 AsmToks, S->getEndLoc());
Chad Rosier8cd64b42012-06-11 20:47:18 +00005612}
Douglas Gregor43959a92009-08-20 07:17:43 +00005613
5614template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005615StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005616TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005617 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005618 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005619 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005620 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005621
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005622 // Transform the @catch statements (if present).
5623 bool AnyCatchChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005624 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005625 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005626 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005627 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005628 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005629 if (Catch.get() != S->getCatchStmt(I))
5630 AnyCatchChanged = true;
5631 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005632 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005633
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005634 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005635 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005636 if (S->getFinallyStmt()) {
5637 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5638 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005639 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005640 }
5641
5642 // If nothing changed, just retain this statement.
5643 if (!getDerived().AlwaysRebuild() &&
5644 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005645 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005646 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005647 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005648
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005649 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005650 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005651 CatchStmts, Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005652}
Mike Stump1eb44332009-09-09 15:08:12 +00005653
Douglas Gregor43959a92009-08-20 07:17:43 +00005654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005655StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005656TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005657 // Transform the @catch parameter, if there is one.
5658 VarDecl *Var = 0;
5659 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5660 TypeSourceInfo *TSInfo = 0;
5661 if (FromVar->getTypeSourceInfo()) {
5662 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5663 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005664 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005665 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005666
Douglas Gregorbe270a02010-04-26 17:57:08 +00005667 QualType T;
5668 if (TSInfo)
5669 T = TSInfo->getType();
5670 else {
5671 T = getDerived().TransformType(FromVar->getType());
5672 if (T.isNull())
Chad Rosier4a9d7952012-08-08 18:46:20 +00005673 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005674 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005675
Douglas Gregorbe270a02010-04-26 17:57:08 +00005676 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5677 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005679 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005680
John McCall60d7b3a2010-08-24 06:29:42 +00005681 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005682 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005683 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005684
5685 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005686 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005687 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005688}
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregor43959a92009-08-20 07:17:43 +00005690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005691StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005692TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005693 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005694 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005695 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005696 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005697
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005698 // If nothing changed, just retain this statement.
5699 if (!getDerived().AlwaysRebuild() &&
5700 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005701 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005702
5703 // Build a new statement.
5704 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005705 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005706}
Mike Stump1eb44332009-09-09 15:08:12 +00005707
Douglas Gregor43959a92009-08-20 07:17:43 +00005708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005709StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005710TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005711 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005712 if (S->getThrowExpr()) {
5713 Operand = getDerived().TransformExpr(S->getThrowExpr());
5714 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005715 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005716 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005717
Douglas Gregord1377b22010-04-22 21:44:01 +00005718 if (!getDerived().AlwaysRebuild() &&
5719 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005720 return getSema().Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005721
John McCall9ae2f072010-08-23 23:25:46 +00005722 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005723}
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregor43959a92009-08-20 07:17:43 +00005725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005726StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005727TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005728 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005729 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005730 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005731 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005732 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005733 Object =
5734 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5735 Object.get());
5736 if (Object.isInvalid())
5737 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005738
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005739 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005740 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005741 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005742 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005743
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005744 // If nothing change, just retain the current statement.
5745 if (!getDerived().AlwaysRebuild() &&
5746 Object.get() == S->getSynchExpr() &&
5747 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005748 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005749
5750 // Build a new statement.
5751 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005752 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005753}
5754
5755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005756StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005757TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5758 ObjCAutoreleasePoolStmt *S) {
5759 // Transform the body.
5760 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5761 if (Body.isInvalid())
5762 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005763
John McCallf85e1932011-06-15 23:02:42 +00005764 // If nothing changed, just retain this statement.
5765 if (!getDerived().AlwaysRebuild() &&
5766 Body.get() == S->getSubStmt())
5767 return SemaRef.Owned(S);
5768
5769 // Build a new statement.
5770 return getDerived().RebuildObjCAutoreleasePoolStmt(
5771 S->getAtLoc(), Body.get());
5772}
5773
5774template<typename Derived>
5775StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005776TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005777 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005778 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005779 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005780 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005781 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005782
Douglas Gregorc3203e72010-04-22 23:10:45 +00005783 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005784 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005785 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005786 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005787
Douglas Gregorc3203e72010-04-22 23:10:45 +00005788 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005789 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005790 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005792
Douglas Gregorc3203e72010-04-22 23:10:45 +00005793 // If nothing changed, just retain this statement.
5794 if (!getDerived().AlwaysRebuild() &&
5795 Element.get() == S->getElement() &&
5796 Collection.get() == S->getCollection() &&
5797 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005798 return SemaRef.Owned(S);
Chad Rosier4a9d7952012-08-08 18:46:20 +00005799
Douglas Gregorc3203e72010-04-22 23:10:45 +00005800 // Build a new statement.
5801 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005802 Element.get(),
5803 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005804 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005805 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005806}
5807
5808
5809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005810StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005811TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5812 // Transform the exception declaration, if any.
5813 VarDecl *Var = 0;
5814 if (S->getExceptionDecl()) {
5815 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005816 TypeSourceInfo *T = getDerived().TransformType(
5817 ExceptionDecl->getTypeSourceInfo());
5818 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005819 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005820
Douglas Gregor83cb9422010-09-09 17:09:21 +00005821 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005822 ExceptionDecl->getInnerLocStart(),
5823 ExceptionDecl->getLocation(),
5824 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005825 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005826 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005827 }
Mike Stump1eb44332009-09-09 15:08:12 +00005828
Douglas Gregor43959a92009-08-20 07:17:43 +00005829 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005830 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005831 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005832 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005833
Douglas Gregor43959a92009-08-20 07:17:43 +00005834 if (!getDerived().AlwaysRebuild() &&
5835 !Var &&
5836 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005837 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005838
5839 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5840 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005841 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005842}
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregor43959a92009-08-20 07:17:43 +00005844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005845StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005846TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5847 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005848 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005849 = getDerived().TransformCompoundStmt(S->getTryBlock());
5850 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005851 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005852
Douglas Gregor43959a92009-08-20 07:17:43 +00005853 // Transform the handlers.
5854 bool HandlerChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00005855 SmallVector<Stmt*, 8> Handlers;
Douglas Gregor43959a92009-08-20 07:17:43 +00005856 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005857 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005858 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5859 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005860 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005861
Douglas Gregor43959a92009-08-20 07:17:43 +00005862 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5863 Handlers.push_back(Handler.takeAs<Stmt>());
5864 }
Mike Stump1eb44332009-09-09 15:08:12 +00005865
Douglas Gregor43959a92009-08-20 07:17:43 +00005866 if (!getDerived().AlwaysRebuild() &&
5867 TryBlock.get() == S->getTryBlock() &&
5868 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005869 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005870
John McCall9ae2f072010-08-23 23:25:46 +00005871 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00005872 Handlers);
Douglas Gregor43959a92009-08-20 07:17:43 +00005873}
Mike Stump1eb44332009-09-09 15:08:12 +00005874
Richard Smithad762fc2011-04-14 22:09:26 +00005875template<typename Derived>
5876StmtResult
5877TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5878 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5879 if (Range.isInvalid())
5880 return StmtError();
5881
5882 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5883 if (BeginEnd.isInvalid())
5884 return StmtError();
5885
5886 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5887 if (Cond.isInvalid())
5888 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005889 if (Cond.get())
5890 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5891 if (Cond.isInvalid())
5892 return StmtError();
5893 if (Cond.get())
5894 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005895
5896 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5897 if (Inc.isInvalid())
5898 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005899 if (Inc.get())
5900 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005901
5902 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5903 if (LoopVar.isInvalid())
5904 return StmtError();
5905
5906 StmtResult NewStmt = S;
5907 if (getDerived().AlwaysRebuild() ||
5908 Range.get() != S->getRangeStmt() ||
5909 BeginEnd.get() != S->getBeginEndStmt() ||
5910 Cond.get() != S->getCond() ||
5911 Inc.get() != S->getInc() ||
5912 LoopVar.get() != S->getLoopVarStmt())
5913 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5914 S->getColonLoc(), Range.get(),
5915 BeginEnd.get(), Cond.get(),
5916 Inc.get(), LoopVar.get(),
5917 S->getRParenLoc());
5918
5919 StmtResult Body = getDerived().TransformStmt(S->getBody());
5920 if (Body.isInvalid())
5921 return StmtError();
5922
5923 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5924 // it now so we have a new statement to attach the body to.
5925 if (Body.get() != S->getBody() && NewStmt.get() == S)
5926 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5927 S->getColonLoc(), Range.get(),
5928 BeginEnd.get(), Cond.get(),
5929 Inc.get(), LoopVar.get(),
5930 S->getRParenLoc());
5931
5932 if (NewStmt.get() == S)
5933 return SemaRef.Owned(S);
5934
5935 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5936}
5937
John Wiegley28bbe4b2011-04-28 01:08:34 +00005938template<typename Derived>
5939StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005940TreeTransform<Derived>::TransformMSDependentExistsStmt(
5941 MSDependentExistsStmt *S) {
5942 // Transform the nested-name-specifier, if any.
5943 NestedNameSpecifierLoc QualifierLoc;
5944 if (S->getQualifierLoc()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00005945 QualifierLoc
Douglas Gregorba0513d2011-10-25 01:33:02 +00005946 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5947 if (!QualifierLoc)
5948 return StmtError();
5949 }
5950
5951 // Transform the declaration name.
5952 DeclarationNameInfo NameInfo = S->getNameInfo();
5953 if (NameInfo.getName()) {
5954 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5955 if (!NameInfo.getName())
5956 return StmtError();
5957 }
5958
5959 // Check whether anything changed.
5960 if (!getDerived().AlwaysRebuild() &&
5961 QualifierLoc == S->getQualifierLoc() &&
5962 NameInfo.getName() == S->getNameInfo().getName())
5963 return S;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005964
Douglas Gregorba0513d2011-10-25 01:33:02 +00005965 // Determine whether this name exists, if we can.
5966 CXXScopeSpec SS;
5967 SS.Adopt(QualifierLoc);
5968 bool Dependent = false;
5969 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5970 case Sema::IER_Exists:
5971 if (S->isIfExists())
5972 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005973
Douglas Gregorba0513d2011-10-25 01:33:02 +00005974 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5975
5976 case Sema::IER_DoesNotExist:
5977 if (S->isIfNotExists())
5978 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005979
Douglas Gregorba0513d2011-10-25 01:33:02 +00005980 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00005981
Douglas Gregorba0513d2011-10-25 01:33:02 +00005982 case Sema::IER_Dependent:
5983 Dependent = true;
5984 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005985
Douglas Gregor65019ac2011-10-25 03:44:56 +00005986 case Sema::IER_Error:
5987 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005988 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00005989
Douglas Gregorba0513d2011-10-25 01:33:02 +00005990 // We need to continue with the instantiation, so do so now.
5991 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5992 if (SubStmt.isInvalid())
5993 return StmtError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00005994
Douglas Gregorba0513d2011-10-25 01:33:02 +00005995 // If we have resolved the name, just transform to the substatement.
5996 if (!Dependent)
5997 return SubStmt;
Chad Rosier4a9d7952012-08-08 18:46:20 +00005998
Douglas Gregorba0513d2011-10-25 01:33:02 +00005999 // The name is still dependent, so build a dependent expression again.
6000 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6001 S->isIfExists(),
6002 QualifierLoc,
6003 NameInfo,
6004 SubStmt.get());
6005}
6006
6007template<typename Derived>
6008StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00006009TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
6010 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
6011 if(TryBlock.isInvalid()) return StmtError();
6012
6013 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
6014 if(!getDerived().AlwaysRebuild() &&
6015 TryBlock.get() == S->getTryBlock() &&
6016 Handler.get() == S->getHandler())
6017 return SemaRef.Owned(S);
6018
6019 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
6020 S->getTryLoc(),
6021 TryBlock.take(),
6022 Handler.take());
6023}
6024
6025template<typename Derived>
6026StmtResult
6027TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
6028 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6029 if(Block.isInvalid()) return StmtError();
6030
6031 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
6032 Block.take());
6033}
6034
6035template<typename Derived>
6036StmtResult
6037TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
6038 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
6039 if(FilterExpr.isInvalid()) return StmtError();
6040
6041 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
6042 if(Block.isInvalid()) return StmtError();
6043
6044 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
6045 FilterExpr.take(),
6046 Block.take());
6047}
6048
6049template<typename Derived>
6050StmtResult
6051TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6052 if(isa<SEHFinallyStmt>(Handler))
6053 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6054 else
6055 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6056}
6057
Douglas Gregor43959a92009-08-20 07:17:43 +00006058//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059// Expression transformation
6060//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00006061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006062ExprResult
John McCall454feb92009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006064 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065}
Mike Stump1eb44332009-09-09 15:08:12 +00006066
6067template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006068ExprResult
John McCall454feb92009-12-08 09:21:05 +00006069TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006070 NestedNameSpecifierLoc QualifierLoc;
6071 if (E->getQualifierLoc()) {
6072 QualifierLoc
6073 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6074 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006075 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00006076 }
John McCalldbd872f2009-12-08 09:08:17 +00006077
6078 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006079 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6080 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00006082 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006083
John McCallec8045d2010-08-17 21:27:17 +00006084 DeclarationNameInfo NameInfo = E->getNameInfo();
6085 if (NameInfo.getName()) {
6086 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6087 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006088 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00006089 }
Abramo Bagnara25777432010-08-11 22:01:17 +00006090
6091 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006092 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00006093 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006094 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00006095 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006096
6097 // Mark it referenced in the new context regardless.
6098 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006099 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00006100
John McCall3fa5cae2010-10-26 07:05:15 +00006101 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00006102 }
John McCalldbd872f2009-12-08 09:08:17 +00006103
6104 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00006105 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00006106 TemplateArgs = &TransArgs;
6107 TransArgs.setLAngleLoc(E->getLAngleLoc());
6108 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006109 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6110 E->getNumTemplateArgs(),
6111 TransArgs))
6112 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00006113 }
6114
Chad Rosier4a9d7952012-08-08 18:46:20 +00006115 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregor40d96a62011-02-28 21:54:11 +00006116 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117}
Mike Stump1eb44332009-09-09 15:08:12 +00006118
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006120ExprResult
John McCall454feb92009-12-08 09:21:05 +00006121TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006122 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006123}
Mike Stump1eb44332009-09-09 15:08:12 +00006124
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006126ExprResult
John McCall454feb92009-12-08 09:21:05 +00006127TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006128 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129}
Mike Stump1eb44332009-09-09 15:08:12 +00006130
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006132ExprResult
John McCall454feb92009-12-08 09:21:05 +00006133TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006134 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135}
Mike Stump1eb44332009-09-09 15:08:12 +00006136
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006138ExprResult
John McCall454feb92009-12-08 09:21:05 +00006139TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006140 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141}
Mike Stump1eb44332009-09-09 15:08:12 +00006142
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006144ExprResult
John McCall454feb92009-12-08 09:21:05 +00006145TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006146 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006147}
6148
6149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006150ExprResult
Richard Smith9fcce652012-03-07 08:35:16 +00006151TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
6152 return SemaRef.MaybeBindToTemporary(E);
6153}
6154
6155template<typename Derived>
6156ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006157TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6158 ExprResult ControllingExpr =
6159 getDerived().TransformExpr(E->getControllingExpr());
6160 if (ControllingExpr.isInvalid())
6161 return ExprError();
6162
Chris Lattner686775d2011-07-20 06:58:45 +00006163 SmallVector<Expr *, 4> AssocExprs;
6164 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006165 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6166 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6167 if (TS) {
6168 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6169 if (!AssocType)
6170 return ExprError();
6171 AssocTypes.push_back(AssocType);
6172 } else {
6173 AssocTypes.push_back(0);
6174 }
6175
6176 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6177 if (AssocExpr.isInvalid())
6178 return ExprError();
6179 AssocExprs.push_back(AssocExpr.release());
6180 }
6181
6182 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6183 E->getDefaultLoc(),
6184 E->getRParenLoc(),
6185 ControllingExpr.release(),
6186 AssocTypes.data(),
6187 AssocExprs.data(),
6188 E->getNumAssocs());
6189}
6190
6191template<typename Derived>
6192ExprResult
John McCall454feb92009-12-08 09:21:05 +00006193TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006194 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006197
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006200
John McCall9ae2f072010-08-23 23:25:46 +00006201 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 E->getRParen());
6203}
6204
Mike Stump1eb44332009-09-09 15:08:12 +00006205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006206ExprResult
John McCall454feb92009-12-08 09:21:05 +00006207TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006208 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006210 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006213 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6216 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006217 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218}
Mike Stump1eb44332009-09-09 15:08:12 +00006219
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006221ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006222TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6223 // Transform the type.
6224 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6225 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006226 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006227
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006228 // Transform all of the components into components similar to what the
6229 // parser uses.
Chad Rosier4a9d7952012-08-08 18:46:20 +00006230 // FIXME: It would be slightly more efficient in the non-dependent case to
6231 // just map FieldDecls, rather than requiring the rebuilder to look for
6232 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006233 // template code that we don't care.
6234 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006235 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006236 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006237 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006238 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6239 const Node &ON = E->getComponent(I);
6240 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006241 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006242 Comp.LocStart = ON.getSourceRange().getBegin();
6243 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006244 switch (ON.getKind()) {
6245 case Node::Array: {
6246 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006247 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006248 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006249 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006250
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006251 ExprChanged = ExprChanged || Index.get() != FromIndex;
6252 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006253 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006254 break;
6255 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006256
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006257 case Node::Field:
6258 case Node::Identifier:
6259 Comp.isBrackets = false;
6260 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006261 if (!Comp.U.IdentInfo)
6262 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006263
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006264 break;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006265
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006266 case Node::Base:
6267 // Will be recomputed during the rebuild.
6268 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006269 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006270
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006271 Components.push_back(Comp);
6272 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006273
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006274 // If nothing changed, retain the existing expression.
6275 if (!getDerived().AlwaysRebuild() &&
6276 Type == E->getTypeSourceInfo() &&
6277 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006278 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00006279
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006280 // Build a new offsetof expression.
6281 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6282 Components.data(), Components.size(),
6283 E->getRParenLoc());
6284}
6285
6286template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006287ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006288TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6289 assert(getDerived().AlreadyTransformed(E->getType()) &&
6290 "opaque value expression requires transformation");
6291 return SemaRef.Owned(E);
6292}
6293
6294template<typename Derived>
6295ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006296TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006297 // Rebuild the syntactic form. The original syntactic form has
6298 // opaque-value expressions in it, so strip those away and rebuild
6299 // the result. This is a really awful way of doing this, but the
6300 // better solution (rebuilding the semantic expressions and
6301 // rebinding OVEs as necessary) doesn't work; we'd need
6302 // TreeTransform to not strip away implicit conversions.
6303 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6304 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006305 if (result.isInvalid()) return ExprError();
6306
6307 // If that gives us a pseudo-object result back, the pseudo-object
6308 // expression must have been an lvalue-to-rvalue conversion which we
6309 // should reapply.
6310 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6311 result = SemaRef.checkPseudoObjectRValue(result.take());
6312
6313 return result;
6314}
6315
6316template<typename Derived>
6317ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006318TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6319 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006321 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006322
John McCalla93c9342009-12-07 02:54:59 +00006323 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006324 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006326
John McCall5ab75172009-11-04 07:28:41 +00006327 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006328 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006329
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006330 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6331 E->getKind(),
6332 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333 }
Mike Stump1eb44332009-09-09 15:08:12 +00006334
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006335 // C++0x [expr.sizeof]p1:
6336 // The operand is either an expression, which is an unevaluated operand
6337 // [...]
6338 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006339
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006340 ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6341 if (SubExpr.isInvalid())
6342 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Eli Friedman72b8b1e2012-02-29 04:03:55 +00006344 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
6345 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006346
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006347 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6348 E->getOperatorLoc(),
6349 E->getKind(),
6350 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351}
Mike Stump1eb44332009-09-09 15:08:12 +00006352
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006354ExprResult
John McCall454feb92009-12-08 09:21:05 +00006355TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006356 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006359
John McCall60d7b3a2010-08-24 06:29:42 +00006360 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006363
6364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 if (!getDerived().AlwaysRebuild() &&
6366 LHS.get() == E->getLHS() &&
6367 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006369
John McCall9ae2f072010-08-23 23:25:46 +00006370 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006372 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 E->getRBracketLoc());
6374}
Mike Stump1eb44332009-09-09 15:08:12 +00006375
6376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006377ExprResult
John McCall454feb92009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006380 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006382 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383
6384 // Transform arguments.
6385 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006386 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006387 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006388 &ArgChanged))
6389 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006390
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391 if (!getDerived().AlwaysRebuild() &&
6392 Callee.get() == E->getCallee() &&
6393 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006394 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006395
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006397 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006399 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006400 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 E->getRParenLoc());
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>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006407 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Douglas Gregor40d96a62011-02-28 21:54:11 +00006411 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006412 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006413 QualifierLoc
6414 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006415
Douglas Gregor40d96a62011-02-28 21:54:11 +00006416 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006417 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006418 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006419 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006420
Eli Friedmanf595cc42009-12-04 06:40:45 +00006421 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006422 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6423 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006426
John McCall6bb80172010-03-30 21:47:33 +00006427 NamedDecl *FoundDecl = E->getFoundDecl();
6428 if (FoundDecl == E->getMemberDecl()) {
6429 FoundDecl = Member;
6430 } else {
6431 FoundDecl = cast_or_null<NamedDecl>(
6432 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6433 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006434 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006435 }
6436
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 if (!getDerived().AlwaysRebuild() &&
6438 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006439 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006440 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006441 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006442 !E->hasExplicitTemplateArgs()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00006443
Anders Carlsson1f240322009-12-22 05:24:09 +00006444 // Mark it referenced in the new context regardless.
6445 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006446 SemaRef.MarkMemberReferenced(E);
6447
John McCall3fa5cae2010-10-26 07:05:15 +00006448 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006449 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450
John McCalld5532b62009-11-23 01:53:49 +00006451 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006452 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006453 TransArgs.setLAngleLoc(E->getLAngleLoc());
6454 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006455 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6456 E->getNumTemplateArgs(),
6457 TransArgs))
6458 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006459 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 // FIXME: Bogus source location for the operator
6462 SourceLocation FakeOperatorLoc
6463 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6464
John McCallc2233c52010-01-15 08:34:02 +00006465 // FIXME: to do this check properly, we will need to preserve the
6466 // first-qualifier-in-scope here, just in case we had a dependent
6467 // base (and therefore couldn't do the check) and a
6468 // nested-name-qualifier (and therefore could do the lookup).
6469 NamedDecl *FirstQualifierInScope = 0;
6470
John McCall9ae2f072010-08-23 23:25:46 +00006471 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006473 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006474 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006475 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006476 Member,
John McCall6bb80172010-03-30 21:47:33 +00006477 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006478 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006479 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006480 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481}
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006484ExprResult
John McCall454feb92009-12-08 09:21:05 +00006485TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006486 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006488 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006489
John McCall60d7b3a2010-08-24 06:29:42 +00006490 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006493
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 if (!getDerived().AlwaysRebuild() &&
6495 LHS.get() == E->getLHS() &&
6496 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006497 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006500 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501}
6502
Mike Stump1eb44332009-09-09 15:08:12 +00006503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006504ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006506 CompoundAssignOperator *E) {
6507 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508}
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006511ExprResult TreeTransform<Derived>::
6512TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6513 // Just rebuild the common and RHS expressions and see whether we
6514 // get any changes.
6515
6516 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6517 if (commonExpr.isInvalid())
6518 return ExprError();
6519
6520 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6521 if (rhs.isInvalid())
6522 return ExprError();
6523
6524 if (!getDerived().AlwaysRebuild() &&
6525 commonExpr.get() == e->getCommon() &&
6526 rhs.get() == e->getFalseExpr())
6527 return SemaRef.Owned(e);
6528
6529 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6530 e->getQuestionLoc(),
6531 0,
6532 e->getColonLoc(),
6533 rhs.get());
6534}
6535
6536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006537ExprResult
John McCall454feb92009-12-08 09:21:05 +00006538TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006539 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006541 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006542
John McCall60d7b3a2010-08-24 06:29:42 +00006543 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006546
John McCall60d7b3a2010-08-24 06:29:42 +00006547 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006549 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006550
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 if (!getDerived().AlwaysRebuild() &&
6552 Cond.get() == E->getCond() &&
6553 LHS.get() == E->getLHS() &&
6554 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006555 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006556
John McCall9ae2f072010-08-23 23:25:46 +00006557 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006558 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006559 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006560 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006561 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006562}
Mike Stump1eb44332009-09-09 15:08:12 +00006563
6564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006565ExprResult
John McCall454feb92009-12-08 09:21:05 +00006566TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006567 // Implicit casts are eliminated during transformation, since they
6568 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006569 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570}
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006573ExprResult
John McCall454feb92009-12-08 09:21:05 +00006574TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006575 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6576 if (!Type)
6577 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006578
John McCall60d7b3a2010-08-24 06:29:42 +00006579 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006580 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006582 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006583
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006585 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006587 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006588
John McCall9d125032010-01-15 18:39:57 +00006589 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006590 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006592 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593}
Mike Stump1eb44332009-09-09 15:08:12 +00006594
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006596ExprResult
John McCall454feb92009-12-08 09:21:05 +00006597TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006598 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6599 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6600 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006601 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006602
John McCall60d7b3a2010-08-24 06:29:42 +00006603 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006606
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006608 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006610 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611
John McCall1d7d8d62010-01-19 22:33:45 +00006612 // Note: the expression type doesn't necessarily match the
6613 // type-as-written, but that's okay, because it should always be
6614 // derivable from the initializer.
6615
John McCall42f56b52010-01-18 19:35:47 +00006616 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006618 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619}
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006622ExprResult
John McCall454feb92009-12-08 09:21:05 +00006623TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006624 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006626 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (!getDerived().AlwaysRebuild() &&
6629 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006630 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006631
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006633 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006635 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636 E->getAccessorLoc(),
6637 E->getAccessor());
6638}
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006641ExprResult
John McCall454feb92009-12-08 09:21:05 +00006642TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006644
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006645 SmallVector<Expr*, 4> Inits;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006646 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006647 Inits, &InitChanged))
6648 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006649
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006652
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006653 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00006654 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655}
Mike Stump1eb44332009-09-09 15:08:12 +00006656
Douglas Gregorb98b1992009-08-11 05:31:07 +00006657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006658ExprResult
John McCall454feb92009-12-08 09:21:05 +00006659TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006661
Douglas Gregor43959a92009-08-20 07:17:43 +00006662 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006663 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006664 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregor43959a92009-08-20 07:17:43 +00006667 // transform the designators.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006668 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 bool ExprChanged = false;
6670 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6671 DEnd = E->designators_end();
6672 D != DEnd; ++D) {
6673 if (D->isFieldDesignator()) {
6674 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6675 D->getDotLoc(),
6676 D->getFieldLoc()));
6677 continue;
6678 }
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006681 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
6685 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006687
Douglas Gregorb98b1992009-08-11 05:31:07 +00006688 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6689 ArrayExprs.push_back(Index.release());
6690 continue;
6691 }
Mike Stump1eb44332009-09-09 15:08:12 +00006692
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006694 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6696 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006697 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006698
John McCall60d7b3a2010-08-24 06:29:42 +00006699 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006701 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006702
6703 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 End.get(),
6705 D->getLBracketLoc(),
6706 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6709 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 ArrayExprs.push_back(Start.release());
6712 ArrayExprs.push_back(End.release());
6713 }
Mike Stump1eb44332009-09-09 15:08:12 +00006714
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 if (!getDerived().AlwaysRebuild() &&
6716 Init.get() == E->getInit() &&
6717 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006718 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006719
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006720 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006722 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723}
Mike Stump1eb44332009-09-09 15:08:12 +00006724
Douglas Gregorb98b1992009-08-11 05:31:07 +00006725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006726ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006728 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006729 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier4a9d7952012-08-08 18:46:20 +00006730
Douglas Gregor5557b252009-10-28 00:29:27 +00006731 // FIXME: Will we ever have proper type location here? Will we actually
6732 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006733 QualType T = getDerived().TransformType(E->getType());
6734 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737 if (!getDerived().AlwaysRebuild() &&
6738 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006739 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006740
Douglas Gregorb98b1992009-08-11 05:31:07 +00006741 return getDerived().RebuildImplicitValueInitExpr(T);
6742}
Mike Stump1eb44332009-09-09 15:08:12 +00006743
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006745ExprResult
John McCall454feb92009-12-08 09:21:05 +00006746TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006747 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6748 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006750
John McCall60d7b3a2010-08-24 06:29:42 +00006751 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006756 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006758 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006759
John McCall9ae2f072010-08-23 23:25:46 +00006760 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006761 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762}
6763
6764template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006765ExprResult
John McCall454feb92009-12-08 09:21:05 +00006766TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006768 SmallVector<Expr*, 4> Inits;
Douglas Gregoraa165f82011-01-03 19:04:46 +00006769 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6770 &ArgumentChanged))
6771 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006772
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006774 Inits,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 E->getRParenLoc());
6776}
Mike Stump1eb44332009-09-09 15:08:12 +00006777
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778/// \brief Transform an address-of-label expression.
6779///
6780/// By default, the transformation of an address-of-label expression always
6781/// rebuilds the expression, so that the label identifier can be resolved to
6782/// the corresponding label statement by semantic analysis.
6783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006784ExprResult
John McCall454feb92009-12-08 09:21:05 +00006785TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006786 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6787 E->getLabel());
6788 if (!LD)
6789 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006790
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006792 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793}
Mike Stump1eb44332009-09-09 15:08:12 +00006794
6795template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00006796ExprResult
John McCall454feb92009-12-08 09:21:05 +00006797TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall7f39d512012-04-06 18:20:53 +00006798 SemaRef.ActOnStartStmtExpr();
John McCall60d7b3a2010-08-24 06:29:42 +00006799 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCall7f39d512012-04-06 18:20:53 +00006801 if (SubStmt.isInvalid()) {
6802 SemaRef.ActOnStmtExprError();
John McCallf312b1e2010-08-26 23:41:50 +00006803 return ExprError();
John McCall7f39d512012-04-06 18:20:53 +00006804 }
Mike Stump1eb44332009-09-09 15:08:12 +00006805
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 if (!getDerived().AlwaysRebuild() &&
John McCall7f39d512012-04-06 18:20:53 +00006807 SubStmt.get() == E->getSubStmt()) {
6808 // Calling this an 'error' is unintuitive, but it does the right thing.
6809 SemaRef.ActOnStmtExprError();
Douglas Gregor92be2a52011-12-10 00:23:21 +00006810 return SemaRef.MaybeBindToTemporary(E);
John McCall7f39d512012-04-06 18:20:53 +00006811 }
Mike Stump1eb44332009-09-09 15:08:12 +00006812
6813 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006814 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815 E->getRParenLoc());
6816}
Mike Stump1eb44332009-09-09 15:08:12 +00006817
Douglas Gregorb98b1992009-08-11 05:31:07 +00006818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006819ExprResult
John McCall454feb92009-12-08 09:21:05 +00006820TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006821 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
John McCall60d7b3a2010-08-24 06:29:42 +00006825 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006828
John McCall60d7b3a2010-08-24 06:29:42 +00006829 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006831 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 if (!getDerived().AlwaysRebuild() &&
6834 Cond.get() == E->getCond() &&
6835 LHS.get() == E->getLHS() &&
6836 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006837 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006840 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 E->getRParenLoc());
6842}
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006845ExprResult
John McCall454feb92009-12-08 09:21:05 +00006846TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006847 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848}
6849
6850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006851ExprResult
John McCall454feb92009-12-08 09:21:05 +00006852TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006853 switch (E->getOperator()) {
6854 case OO_New:
6855 case OO_Delete:
6856 case OO_Array_New:
6857 case OO_Array_Delete:
6858 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier4a9d7952012-08-08 18:46:20 +00006859
Douglas Gregor668d6d92009-12-13 20:44:55 +00006860 case OO_Call: {
6861 // This is a call to an object's operator().
6862 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6863
6864 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006865 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006866 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006867 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006868
6869 // FIXME: Poor location information
6870 SourceLocation FakeLParenLoc
6871 = SemaRef.PP.getLocForEndOfToken(
6872 static_cast<Expr *>(Object.get())->getLocEnd());
6873
6874 // Transform the call arguments.
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006875 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006876 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006877 Args))
6878 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006879
John McCall9ae2f072010-08-23 23:25:46 +00006880 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006881 Args,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006882 E->getLocEnd());
6883 }
6884
6885#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6886 case OO_##Name:
6887#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6888#include "clang/Basic/OperatorKinds.def"
6889 case OO_Subscript:
6890 // Handled below.
6891 break;
6892
6893 case OO_Conditional:
6894 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006895
6896 case OO_None:
6897 case NUM_OVERLOADED_OPERATORS:
6898 llvm_unreachable("not an overloaded operator?");
Douglas Gregor668d6d92009-12-13 20:44:55 +00006899 }
6900
John McCall60d7b3a2010-08-24 06:29:42 +00006901 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006903 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006904
John McCall60d7b3a2010-08-24 06:29:42 +00006905 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006907 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908
John McCall60d7b3a2010-08-24 06:29:42 +00006909 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910 if (E->getNumArgs() == 2) {
6911 Second = getDerived().TransformExpr(E->getArg(1));
6912 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006913 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 }
Mike Stump1eb44332009-09-09 15:08:12 +00006915
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916 if (!getDerived().AlwaysRebuild() &&
6917 Callee.get() == E->getCallee() &&
6918 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006919 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006920 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006921
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6923 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006924 Callee.get(),
6925 First.get(),
6926 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927}
Mike Stump1eb44332009-09-09 15:08:12 +00006928
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006930ExprResult
John McCall454feb92009-12-08 09:21:05 +00006931TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6932 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933}
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006936ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006937TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6938 // Transform the callee.
6939 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6940 if (Callee.isInvalid())
6941 return ExprError();
6942
6943 // Transform exec config.
6944 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6945 if (EC.isInvalid())
6946 return ExprError();
6947
6948 // Transform arguments.
6949 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00006950 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00006951 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006952 &ArgChanged))
6953 return ExprError();
6954
6955 if (!getDerived().AlwaysRebuild() &&
6956 Callee.get() == E->getCallee() &&
6957 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006958 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006959
6960 // FIXME: Wrong source location information for the '('.
6961 SourceLocation FakeLParenLoc
6962 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6963 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00006964 Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00006965 E->getRParenLoc(), EC.get());
6966}
6967
6968template<typename Derived>
6969ExprResult
John McCall454feb92009-12-08 09:21:05 +00006970TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006971 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6972 if (!Type)
6973 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00006974
John McCall60d7b3a2010-08-24 06:29:42 +00006975 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006976 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006978 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006981 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006983 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006986 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6988 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6989 SourceLocation FakeRParenLoc
6990 = SemaRef.PP.getLocForEndOfToken(
6991 E->getSubExpr()->getSourceRange().getEnd());
6992 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006993 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006995 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996 FakeRAngleLoc,
6997 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006998 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006999 FakeRParenLoc);
7000}
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007003ExprResult
John McCall454feb92009-12-08 09:21:05 +00007004TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
7005 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006}
Mike Stump1eb44332009-09-09 15:08:12 +00007007
7008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007009ExprResult
John McCall454feb92009-12-08 09:21:05 +00007010TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
7011 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007012}
7013
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007015ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007017 CXXReinterpretCastExpr *E) {
7018 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019}
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007022ExprResult
John McCall454feb92009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
7024 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025}
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007028ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00007030 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007031 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
7032 if (!Type)
7033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007034
John McCall60d7b3a2010-08-24 06:29:42 +00007035 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00007036 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007039
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007041 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007043 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007044
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007045 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007047 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 E->getRParenLoc());
7049}
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007052ExprResult
John McCall454feb92009-12-08 09:21:05 +00007053TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007055 TypeSourceInfo *TInfo
7056 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7057 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007058 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007059
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007061 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007062 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007064 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7065 E->getLocStart(),
7066 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067 E->getLocEnd());
7068 }
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Eli Friedmanef331b72012-01-20 01:26:23 +00007070 // We don't know whether the subexpression is potentially evaluated until
7071 // after we perform semantic analysis. We speculatively assume it is
7072 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00007074 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00007075
John McCall60d7b3a2010-08-24 06:29:42 +00007076 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007078 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007079
Douglas Gregorb98b1992009-08-11 05:31:07 +00007080 if (!getDerived().AlwaysRebuild() &&
7081 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007083
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00007084 return getDerived().RebuildCXXTypeidExpr(E->getType(),
7085 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00007086 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 E->getLocEnd());
7088}
7089
7090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007091ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00007092TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
7093 if (E->isTypeOperand()) {
7094 TypeSourceInfo *TInfo
7095 = getDerived().TransformType(E->getTypeOperandSourceInfo());
7096 if (!TInfo)
7097 return ExprError();
7098
7099 if (!getDerived().AlwaysRebuild() &&
7100 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007101 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007102
Douglas Gregor3c52a212011-03-06 17:40:41 +00007103 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00007104 E->getLocStart(),
7105 TInfo,
7106 E->getLocEnd());
7107 }
7108
Francois Pichet01b7c302010-09-08 12:20:18 +00007109 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7110
7111 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
7112 if (SubExpr.isInvalid())
7113 return ExprError();
7114
7115 if (!getDerived().AlwaysRebuild() &&
7116 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007117 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00007118
7119 return getDerived().RebuildCXXUuidofExpr(E->getType(),
7120 E->getLocStart(),
7121 SubExpr.get(),
7122 E->getLocEnd());
7123}
7124
7125template<typename Derived>
7126ExprResult
John McCall454feb92009-12-08 09:21:05 +00007127TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007128 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007129}
Mike Stump1eb44332009-09-09 15:08:12 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007132ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007133TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00007134 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007135 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136}
Mike Stump1eb44332009-09-09 15:08:12 +00007137
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007139ExprResult
John McCall454feb92009-12-08 09:21:05 +00007140TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007141 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00007142 QualType T;
7143 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
7144 T = MD->getThisType(getSema().Context);
7145 else
7146 T = getSema().Context.getPointerType(
7147 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Douglas Gregorec79d872012-02-24 17:41:38 +00007149 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
7150 // Make sure that we capture 'this'.
7151 getSema().CheckCXXThisCapture(E->getLocStart());
John McCall3fa5cae2010-10-26 07:05:15 +00007152 return SemaRef.Owned(E);
Douglas Gregorec79d872012-02-24 17:41:38 +00007153 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007154
Douglas Gregor828a1972010-01-07 23:12:05 +00007155 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156}
Mike Stump1eb44332009-09-09 15:08:12 +00007157
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007159ExprResult
John McCall454feb92009-12-08 09:21:05 +00007160TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007161 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007163 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007164
Douglas Gregorb98b1992009-08-11 05:31:07 +00007165 if (!getDerived().AlwaysRebuild() &&
7166 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007167 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007168
Douglas Gregorbca01b42011-07-06 22:04:06 +00007169 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7170 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007171}
Mike Stump1eb44332009-09-09 15:08:12 +00007172
Douglas Gregorb98b1992009-08-11 05:31:07 +00007173template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007174ExprResult
John McCall454feb92009-12-08 09:21:05 +00007175TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007176 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007177 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7178 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007180 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007181
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007182 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007183 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007184 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregor036aed12009-12-23 23:03:06 +00007186 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187}
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007190ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007191TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7192 CXXScalarValueInitExpr *E) {
7193 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7194 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007196
Douglas Gregorb98b1992009-08-11 05:31:07 +00007197 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007198 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007199 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007200
Chad Rosier4a9d7952012-08-08 18:46:20 +00007201 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregorab6677e2010-09-08 00:15:04 +00007202 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007203 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007204}
Mike Stump1eb44332009-09-09 15:08:12 +00007205
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007207ExprResult
John McCall454feb92009-12-08 09:21:05 +00007208TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007209 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007210 TypeSourceInfo *AllocTypeInfo
7211 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7212 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007213 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Douglas Gregorb98b1992009-08-11 05:31:07 +00007215 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007216 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007217 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007218 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007219
Douglas Gregorb98b1992009-08-11 05:31:07 +00007220 // Transform the placement arguments (if any).
7221 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007222 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007223 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregoraa165f82011-01-03 19:04:46 +00007224 E->getNumPlacementArgs(), true,
7225 PlacementArgs, &ArgumentChanged))
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007226 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007227
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007228 // Transform the initializer (if any).
7229 Expr *OldInit = E->getInitializer();
7230 ExprResult NewInit;
7231 if (OldInit)
7232 NewInit = getDerived().TransformExpr(OldInit);
7233 if (NewInit.isInvalid())
7234 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007235
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007236 // Transform new operator and delete operator.
Douglas Gregor1af74512010-02-26 00:38:10 +00007237 FunctionDecl *OperatorNew = 0;
7238 if (E->getOperatorNew()) {
7239 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007240 getDerived().TransformDecl(E->getLocStart(),
7241 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007242 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007243 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007244 }
7245
7246 FunctionDecl *OperatorDelete = 0;
7247 if (E->getOperatorDelete()) {
7248 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007249 getDerived().TransformDecl(E->getLocStart(),
7250 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007251 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007252 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007253 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007254
Douglas Gregorb98b1992009-08-11 05:31:07 +00007255 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007256 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 ArraySize.get() == E->getArraySize() &&
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007258 NewInit.get() == OldInit &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007259 OperatorNew == E->getOperatorNew() &&
7260 OperatorDelete == E->getOperatorDelete() &&
7261 !ArgumentChanged) {
7262 // Mark any declarations we need as referenced.
7263 // FIXME: instantiation-specific.
Douglas Gregor1af74512010-02-26 00:38:10 +00007264 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007265 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007266 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007267 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007268
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007269 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007270 QualType ElementType
7271 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7272 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7273 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7274 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007275 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007276 }
7277 }
7278 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007279
John McCall3fa5cae2010-10-26 07:05:15 +00007280 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007281 }
Mike Stump1eb44332009-09-09 15:08:12 +00007282
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007283 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007284 if (!ArraySize.get()) {
7285 // If no array size was specified, but the new expression was
7286 // instantiated with an array type (e.g., "new T" where T is
7287 // instantiated with "int[4]"), extract the outer bound from the
7288 // array type as our array size. We do this with constant and
7289 // dependently-sized array types.
7290 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7291 if (!ArrayT) {
7292 // Do nothing
7293 } else if (const ConstantArrayType *ConsArrayT
7294 = dyn_cast<ConstantArrayType>(ArrayT)) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00007295 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007296 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
Chad Rosier4a9d7952012-08-08 18:46:20 +00007297 ConsArrayT->getSize(),
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007298 SemaRef.Context.getSizeType(),
7299 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007300 AllocType = ConsArrayT->getElementType();
7301 } else if (const DependentSizedArrayType *DepArrayT
7302 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7303 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007304 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007305 AllocType = DepArrayT->getElementType();
7306 }
7307 }
7308 }
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007309
Douglas Gregorb98b1992009-08-11 05:31:07 +00007310 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7311 E->isGlobalNew(),
7312 /*FIXME:*/E->getLocStart(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007313 PlacementArgs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007314 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007315 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007316 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007317 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007318 ArraySize.get(),
Sebastian Redl2aed8b82012-02-16 12:22:20 +00007319 E->getDirectInitRange(),
7320 NewInit.take());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007321}
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Douglas Gregorb98b1992009-08-11 05:31:07 +00007323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007324ExprResult
John McCall454feb92009-12-08 09:21:05 +00007325TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007326 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007327 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007329
Douglas Gregor1af74512010-02-26 00:38:10 +00007330 // Transform the delete operator, if known.
7331 FunctionDecl *OperatorDelete = 0;
7332 if (E->getOperatorDelete()) {
7333 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007334 getDerived().TransformDecl(E->getLocStart(),
7335 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007336 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007337 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007338 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007339
Douglas Gregorb98b1992009-08-11 05:31:07 +00007340 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007341 Operand.get() == E->getArgument() &&
7342 OperatorDelete == E->getOperatorDelete()) {
7343 // Mark any declarations we need as referenced.
7344 // FIXME: instantiation-specific.
7345 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007346 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007347
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007348 if (!E->getArgument()->isTypeDependent()) {
7349 QualType Destroyed = SemaRef.Context.getBaseElementType(
7350 E->getDestroyedType());
7351 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7352 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007353 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedman5f2987c2012-02-02 03:46:19 +00007354 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007355 }
7356 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007357
John McCall3fa5cae2010-10-26 07:05:15 +00007358 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007359 }
Mike Stump1eb44332009-09-09 15:08:12 +00007360
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7362 E->isGlobalDelete(),
7363 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007364 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365}
Mike Stump1eb44332009-09-09 15:08:12 +00007366
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007368ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007369TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007370 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007371 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007372 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007374
John McCallb3d87482010-08-24 05:47:05 +00007375 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007376 bool MayBePseudoDestructor = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007377 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007378 E->getOperatorLoc(),
7379 E->isArrow()? tok::arrow : tok::period,
7380 ObjectTypePtr,
7381 MayBePseudoDestructor);
7382 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007384
John McCallb3d87482010-08-24 05:47:05 +00007385 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007386 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7387 if (QualifierLoc) {
7388 QualifierLoc
7389 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7390 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007391 return ExprError();
7392 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007393 CXXScopeSpec SS;
7394 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007395
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007396 PseudoDestructorTypeStorage Destroyed;
7397 if (E->getDestroyedTypeInfo()) {
7398 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007399 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007400 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007401 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007402 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007403 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007404 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007405 // We aren't likely to be able to resolve the identifier down to a type
7406 // now anyway, so just retain the identifier.
7407 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7408 E->getDestroyedTypeLoc());
7409 } else {
7410 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007411 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007412 *E->getDestroyedTypeIdentifier(),
7413 E->getDestroyedTypeLoc(),
7414 /*Scope=*/0,
7415 SS, ObjectTypePtr,
7416 false);
7417 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007418 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007419
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007420 Destroyed
7421 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7422 E->getDestroyedTypeLoc());
7423 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007424
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007425 TypeSourceInfo *ScopeTypeInfo = 0;
7426 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007427 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007428 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007429 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007430 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007431
John McCall9ae2f072010-08-23 23:25:46 +00007432 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007433 E->getOperatorLoc(),
7434 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007435 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007436 ScopeTypeInfo,
7437 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007438 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007439 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007440}
Mike Stump1eb44332009-09-09 15:08:12 +00007441
Douglas Gregora71d8192009-09-04 17:36:40 +00007442template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007443ExprResult
John McCallba135432009-11-21 08:51:07 +00007444TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007445 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007446 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7447 Sema::LookupOrdinaryName);
7448
7449 // Transform all the decls.
7450 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7451 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007452 NamedDecl *InstD = static_cast<NamedDecl*>(
7453 getDerived().TransformDecl(Old->getNameLoc(),
7454 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007455 if (!InstD) {
7456 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7457 // This can happen because of dependent hiding.
7458 if (isa<UsingShadowDecl>(*I))
7459 continue;
7460 else
John McCallf312b1e2010-08-26 23:41:50 +00007461 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007462 }
John McCallf7a1a742009-11-24 19:00:30 +00007463
7464 // Expand using declarations.
7465 if (isa<UsingDecl>(InstD)) {
7466 UsingDecl *UD = cast<UsingDecl>(InstD);
7467 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7468 E = UD->shadow_end(); I != E; ++I)
7469 R.addDecl(*I);
7470 continue;
7471 }
7472
7473 R.addDecl(InstD);
7474 }
7475
7476 // Resolve a kind, but don't do any further analysis. If it's
7477 // ambiguous, the callee needs to deal with it.
7478 R.resolveKind();
7479
7480 // Rebuild the nested-name qualifier, if present.
7481 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007482 if (Old->getQualifierLoc()) {
7483 NestedNameSpecifierLoc QualifierLoc
7484 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7485 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007486 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007487
Douglas Gregor4c9be892011-02-28 20:01:57 +00007488 SS.Adopt(QualifierLoc);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007489 }
7490
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007491 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007492 CXXRecordDecl *NamingClass
7493 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7494 Old->getNameLoc(),
7495 Old->getNamingClass()));
7496 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007497 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007498
Douglas Gregor66c45152010-04-27 16:10:10 +00007499 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007500 }
7501
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007502 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7503
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007504 // If we have neither explicit template arguments, nor the template keyword,
7505 // it's a normal declaration name.
7506 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007507 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7508
7509 // If we have template arguments, rebuild them, then rebuild the
7510 // templateid expression.
7511 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007512 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7513 Old->getNumTemplateArgs(),
7514 TransArgs))
7515 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007516
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007517 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007518 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519}
Mike Stump1eb44332009-09-09 15:08:12 +00007520
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007522ExprResult
John McCall454feb92009-12-08 09:21:05 +00007523TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007524 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7525 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007527
Douglas Gregorb98b1992009-08-11 05:31:07 +00007528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007529 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007530 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Mike Stump1eb44332009-09-09 15:08:12 +00007532 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007533 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007534 T,
7535 E->getLocEnd());
7536}
Mike Stump1eb44332009-09-09 15:08:12 +00007537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007539ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007540TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7541 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7542 if (!LhsT)
7543 return ExprError();
7544
7545 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7546 if (!RhsT)
7547 return ExprError();
7548
7549 if (!getDerived().AlwaysRebuild() &&
7550 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7551 return SemaRef.Owned(E);
7552
7553 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7554 E->getLocStart(),
7555 LhsT, RhsT,
7556 E->getLocEnd());
7557}
7558
7559template<typename Derived>
7560ExprResult
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007561TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
7562 bool ArgChanged = false;
7563 llvm::SmallVector<TypeSourceInfo *, 4> Args;
7564 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
7565 TypeSourceInfo *From = E->getArg(I);
7566 TypeLoc FromTL = From->getTypeLoc();
7567 if (!isa<PackExpansionTypeLoc>(FromTL)) {
7568 TypeLocBuilder TLB;
7569 TLB.reserve(FromTL.getFullDataSize());
7570 QualType To = getDerived().TransformType(TLB, FromTL);
7571 if (To.isNull())
7572 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007573
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007574 if (To == From->getType())
7575 Args.push_back(From);
7576 else {
7577 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7578 ArgChanged = true;
7579 }
7580 continue;
7581 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007582
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007583 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007584
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007585 // We have a pack expansion. Instantiate it.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007586 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL);
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007587 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
7588 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
7589 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007590
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007591 // Determine whether the set of unexpanded parameter packs can and should
7592 // be expanded.
7593 bool Expand = true;
7594 bool RetainExpansion = false;
7595 llvm::Optional<unsigned> OrigNumExpansions
7596 = ExpansionTL.getTypePtr()->getNumExpansions();
7597 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
7598 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
7599 PatternTL.getSourceRange(),
7600 Unexpanded,
7601 Expand, RetainExpansion,
7602 NumExpansions))
7603 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007604
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007605 if (!Expand) {
7606 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00007607 // transformation on the pack expansion, producing another pack
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007608 // expansion.
7609 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007610
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007611 TypeLocBuilder TLB;
7612 TLB.reserve(From->getTypeLoc().getFullDataSize());
7613
7614 QualType To = getDerived().TransformType(TLB, PatternTL);
7615 if (To.isNull())
7616 return ExprError();
7617
Chad Rosier4a9d7952012-08-08 18:46:20 +00007618 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007619 PatternTL.getSourceRange(),
7620 ExpansionTL.getEllipsisLoc(),
7621 NumExpansions);
7622 if (To.isNull())
7623 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007624
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007625 PackExpansionTypeLoc ToExpansionTL
7626 = TLB.push<PackExpansionTypeLoc>(To);
7627 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7628 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7629 continue;
7630 }
7631
7632 // Expand the pack expansion by substituting for each argument in the
7633 // pack(s).
7634 for (unsigned I = 0; I != *NumExpansions; ++I) {
7635 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
7636 TypeLocBuilder TLB;
7637 TLB.reserve(PatternTL.getFullDataSize());
7638 QualType To = getDerived().TransformType(TLB, PatternTL);
7639 if (To.isNull())
7640 return ExprError();
7641
7642 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7643 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007644
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007645 if (!RetainExpansion)
7646 continue;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007647
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007648 // If we're supposed to retain a pack expansion, do so by temporarily
7649 // forgetting the partially-substituted parameter pack.
7650 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7651
7652 TypeLocBuilder TLB;
7653 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007654
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007655 QualType To = getDerived().TransformType(TLB, PatternTL);
7656 if (To.isNull())
7657 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007658
7659 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007660 PatternTL.getSourceRange(),
7661 ExpansionTL.getEllipsisLoc(),
7662 NumExpansions);
7663 if (To.isNull())
7664 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007665
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007666 PackExpansionTypeLoc ToExpansionTL
7667 = TLB.push<PackExpansionTypeLoc>(To);
7668 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
7669 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
7670 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007671
Douglas Gregor4ca8ac22012-02-24 07:38:34 +00007672 if (!getDerived().AlwaysRebuild() && !ArgChanged)
7673 return SemaRef.Owned(E);
7674
7675 return getDerived().RebuildTypeTrait(E->getTrait(),
7676 E->getLocStart(),
7677 Args,
7678 E->getLocEnd());
7679}
7680
7681template<typename Derived>
7682ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007683TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7684 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7685 if (!T)
7686 return ExprError();
7687
7688 if (!getDerived().AlwaysRebuild() &&
7689 T == E->getQueriedTypeSourceInfo())
7690 return SemaRef.Owned(E);
7691
7692 ExprResult SubExpr;
7693 {
7694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7695 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7696 if (SubExpr.isInvalid())
7697 return ExprError();
7698
7699 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7700 return SemaRef.Owned(E);
7701 }
7702
7703 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7704 E->getLocStart(),
7705 T,
7706 SubExpr.get(),
7707 E->getLocEnd());
7708}
7709
7710template<typename Derived>
7711ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007712TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7713 ExprResult SubExpr;
7714 {
7715 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7716 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7717 if (SubExpr.isInvalid())
7718 return ExprError();
7719
7720 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7721 return SemaRef.Owned(E);
7722 }
7723
7724 return getDerived().RebuildExpressionTrait(
7725 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7726}
7727
7728template<typename Derived>
7729ExprResult
John McCall865d4472009-11-19 22:55:06 +00007730TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007731 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007732 NestedNameSpecifierLoc QualifierLoc
7733 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7734 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007735 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007736 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007737
John McCall43fed0d2010-11-12 08:19:04 +00007738 // TODO: If this is a conversion-function-id, verify that the
7739 // destination type name (if present) resolves the same way after
7740 // instantiation as it did in the local scope.
7741
Abramo Bagnara25777432010-08-11 22:01:17 +00007742 DeclarationNameInfo NameInfo
7743 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7744 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007746
John McCallf7a1a742009-11-24 19:00:30 +00007747 if (!E->hasExplicitTemplateArgs()) {
7748 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007749 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007750 // Note: it is sufficient to compare the Name component of NameInfo:
7751 // if name has not changed, DNLoc has not changed either.
7752 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007753 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007754
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007755 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007756 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007757 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007758 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007759 }
John McCalld5532b62009-11-23 01:53:49 +00007760
7761 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007762 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7763 E->getNumTemplateArgs(),
7764 TransArgs))
7765 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007766
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007767 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007768 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007769 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007770 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007771}
7772
7773template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007774ExprResult
John McCall454feb92009-12-08 09:21:05 +00007775TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007776 // CXXConstructExprs are always implicit, so when we have a
7777 // 1-argument construction we just transform that argument.
7778 if (E->getNumArgs() == 1 ||
7779 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7780 return getDerived().TransformExpr(E->getArg(0));
7781
Douglas Gregorb98b1992009-08-11 05:31:07 +00007782 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7783
7784 QualType T = getDerived().TransformType(E->getType());
7785 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007786 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007787
7788 CXXConstructorDecl *Constructor
7789 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007790 getDerived().TransformDecl(E->getLocStart(),
7791 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007792 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007793 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007794
Douglas Gregorb98b1992009-08-11 05:31:07 +00007795 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007796 SmallVector<Expr*, 8> Args;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007797 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007798 &ArgumentChanged))
7799 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007800
Douglas Gregorb98b1992009-08-11 05:31:07 +00007801 if (!getDerived().AlwaysRebuild() &&
7802 T == E->getType() &&
7803 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007804 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007805 // Mark the constructor as referenced.
7806 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007807 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007808 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007809 }
Mike Stump1eb44332009-09-09 15:08:12 +00007810
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007811 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7812 Constructor, E->isElidable(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007813 Args,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007814 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007815 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007816 E->getConstructionKind(),
7817 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007818}
Mike Stump1eb44332009-09-09 15:08:12 +00007819
Douglas Gregorb98b1992009-08-11 05:31:07 +00007820/// \brief Transform a C++ temporary-binding expression.
7821///
Douglas Gregor51326552009-12-24 18:51:59 +00007822/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7823/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007825ExprResult
John McCall454feb92009-12-08 09:21:05 +00007826TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007827 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007828}
Mike Stump1eb44332009-09-09 15:08:12 +00007829
John McCall4765fa02010-12-06 08:20:24 +00007830/// \brief Transform a C++ expression that contains cleanups that should
7831/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832///
John McCall4765fa02010-12-06 08:20:24 +00007833/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007834/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007835template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007836ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007837TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007838 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007839}
Mike Stump1eb44332009-09-09 15:08:12 +00007840
Douglas Gregorb98b1992009-08-11 05:31:07 +00007841template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007842ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007844 CXXTemporaryObjectExpr *E) {
7845 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7846 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007847 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007848
Douglas Gregorb98b1992009-08-11 05:31:07 +00007849 CXXConstructorDecl *Constructor
7850 = cast_or_null<CXXConstructorDecl>(
Chad Rosier4a9d7952012-08-08 18:46:20 +00007851 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007852 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007853 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007854 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007855
Douglas Gregorb98b1992009-08-11 05:31:07 +00007856 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00007857 SmallVector<Expr*, 8> Args;
Douglas Gregorb98b1992009-08-11 05:31:07 +00007858 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007859 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007860 &ArgumentChanged))
7861 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007862
Douglas Gregorb98b1992009-08-11 05:31:07 +00007863 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007864 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007866 !ArgumentChanged) {
7867 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007868 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007869 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007870 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007871
Douglas Gregorab6677e2010-09-08 00:15:04 +00007872 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7873 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00007874 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007875 E->getLocEnd());
7876}
Mike Stump1eb44332009-09-09 15:08:12 +00007877
Douglas Gregorb98b1992009-08-11 05:31:07 +00007878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007879ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007880TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Douglas Gregordfca6f52012-02-13 22:00:16 +00007881 // Create the local class that will describe the lambda.
7882 CXXRecordDecl *Class
Douglas Gregorf54486a2012-04-04 17:40:10 +00007883 = getSema().createLambdaClosureType(E->getIntroducerRange(),
7884 /*KnownDependent=*/false);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007885 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
Chad Rosier4a9d7952012-08-08 18:46:20 +00007886
Douglas Gregordfca6f52012-02-13 22:00:16 +00007887 // Transform the type of the lambda parameters and start the definition of
7888 // the lambda itself.
7889 TypeSourceInfo *MethodTy
Chad Rosier4a9d7952012-08-08 18:46:20 +00007890 = TransformType(E->getCallOperator()->getTypeSourceInfo());
Douglas Gregordfca6f52012-02-13 22:00:16 +00007891 if (!MethodTy)
7892 return ExprError();
7893
Douglas Gregorc6889e72012-02-14 22:28:59 +00007894 // Transform lambda parameters.
Douglas Gregorc6889e72012-02-14 22:28:59 +00007895 llvm::SmallVector<QualType, 4> ParamTypes;
7896 llvm::SmallVector<ParmVarDecl *, 4> Params;
7897 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7898 E->getCallOperator()->param_begin(),
7899 E->getCallOperator()->param_size(),
7900 0, ParamTypes, &Params))
Richard Smith612409e2012-07-25 03:56:55 +00007901 return ExprError();
Douglas Gregorc6889e72012-02-14 22:28:59 +00007902
Douglas Gregordfca6f52012-02-13 22:00:16 +00007903 // Build the call operator.
7904 CXXMethodDecl *CallOperator
7905 = getSema().startLambdaDefinition(Class, E->getIntroducerRange(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007906 MethodTy,
Douglas Gregorc6889e72012-02-14 22:28:59 +00007907 E->getCallOperator()->getLocEnd(),
Richard Smithadb1d4c2012-07-22 23:45:10 +00007908 Params);
Douglas Gregordfca6f52012-02-13 22:00:16 +00007909 getDerived().transformAttrs(E->getCallOperator(), CallOperator);
Douglas Gregord5387e82012-02-14 00:00:48 +00007910
Richard Smith612409e2012-07-25 03:56:55 +00007911 return getDerived().TransformLambdaScope(E, CallOperator);
7912}
7913
7914template<typename Derived>
7915ExprResult
7916TreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E,
7917 CXXMethodDecl *CallOperator) {
Douglas Gregord5387e82012-02-14 00:00:48 +00007918 // Introduce the context of the call operator.
7919 Sema::ContextRAII SavedContext(getSema(), CallOperator);
7920
Douglas Gregordfca6f52012-02-13 22:00:16 +00007921 // Enter the scope of the lambda.
7922 sema::LambdaScopeInfo *LSI
7923 = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(),
7924 E->getCaptureDefault(),
7925 E->hasExplicitParameters(),
7926 E->hasExplicitResultType(),
7927 E->isMutable());
Chad Rosier4a9d7952012-08-08 18:46:20 +00007928
Douglas Gregordfca6f52012-02-13 22:00:16 +00007929 // Transform captures.
Richard Smith612409e2012-07-25 03:56:55 +00007930 bool Invalid = false;
Douglas Gregordfca6f52012-02-13 22:00:16 +00007931 bool FinishedExplicitCaptures = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007932 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007933 CEnd = E->capture_end();
7934 C != CEnd; ++C) {
7935 // When we hit the first implicit capture, tell Sema that we've finished
7936 // the list of explicit captures.
7937 if (!FinishedExplicitCaptures && C->isImplicit()) {
7938 getSema().finishLambdaExplicitCaptures(LSI);
7939 FinishedExplicitCaptures = true;
7940 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007941
Douglas Gregordfca6f52012-02-13 22:00:16 +00007942 // Capturing 'this' is trivial.
7943 if (C->capturesThis()) {
7944 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
7945 continue;
7946 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007947
Douglas Gregora7365242012-02-14 19:27:52 +00007948 // Determine the capture kind for Sema.
7949 Sema::TryCaptureKind Kind
7950 = C->isImplicit()? Sema::TryCapture_Implicit
7951 : C->getCaptureKind() == LCK_ByCopy
7952 ? Sema::TryCapture_ExplicitByVal
7953 : Sema::TryCapture_ExplicitByRef;
7954 SourceLocation EllipsisLoc;
7955 if (C->isPackExpansion()) {
7956 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
7957 bool ShouldExpand = false;
7958 bool RetainExpansion = false;
7959 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00007960 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
7961 C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007962 Unexpanded,
7963 ShouldExpand, RetainExpansion,
7964 NumExpansions))
7965 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00007966
Douglas Gregora7365242012-02-14 19:27:52 +00007967 if (ShouldExpand) {
7968 // The transform has determined that we should perform an expansion;
7969 // transform and capture each of the arguments.
7970 // expansion of the pattern. Do so.
7971 VarDecl *Pack = C->getCapturedVar();
7972 for (unsigned I = 0; I != *NumExpansions; ++I) {
7973 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
7974 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007975 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregora7365242012-02-14 19:27:52 +00007976 Pack));
7977 if (!CapturedVar) {
7978 Invalid = true;
7979 continue;
7980 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007981
Douglas Gregora7365242012-02-14 19:27:52 +00007982 // Capture the transformed variable.
Chad Rosier4a9d7952012-08-08 18:46:20 +00007983 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
7984 }
Douglas Gregora7365242012-02-14 19:27:52 +00007985 continue;
7986 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007987
Douglas Gregora7365242012-02-14 19:27:52 +00007988 EllipsisLoc = C->getEllipsisLoc();
7989 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007990
Douglas Gregordfca6f52012-02-13 22:00:16 +00007991 // Transform the captured variable.
7992 VarDecl *CapturedVar
Chad Rosier4a9d7952012-08-08 18:46:20 +00007993 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregordfca6f52012-02-13 22:00:16 +00007994 C->getCapturedVar()));
7995 if (!CapturedVar) {
7996 Invalid = true;
7997 continue;
7998 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00007999
Douglas Gregordfca6f52012-02-13 22:00:16 +00008000 // Capture the transformed variable.
Douglas Gregor999713e2012-02-18 09:37:24 +00008001 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008002 }
8003 if (!FinishedExplicitCaptures)
8004 getSema().finishLambdaExplicitCaptures(LSI);
8005
Douglas Gregordfca6f52012-02-13 22:00:16 +00008006
8007 // Enter a new evaluation context to insulate the lambda from any
8008 // cleanups from the enclosing full-expression.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008009 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregordfca6f52012-02-13 22:00:16 +00008010
8011 if (Invalid) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008012 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregordfca6f52012-02-13 22:00:16 +00008013 /*IsInstantiation=*/true);
8014 return ExprError();
8015 }
8016
8017 // Instantiate the body of the lambda expression.
Douglas Gregord5387e82012-02-14 00:00:48 +00008018 StmtResult Body = getDerived().TransformStmt(E->getBody());
8019 if (Body.isInvalid()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008020 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0,
Douglas Gregord5387e82012-02-14 00:00:48 +00008021 /*IsInstantiation=*/true);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008022 return ExprError();
Douglas Gregord5387e82012-02-14 00:00:48 +00008023 }
Douglas Gregorccc1b5e2012-02-21 00:37:24 +00008024
Chad Rosier4a9d7952012-08-08 18:46:20 +00008025 return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(),
Douglas Gregorf54486a2012-04-04 17:40:10 +00008026 /*CurScope=*/0, /*IsInstantiation=*/true);
Douglas Gregor01d08012012-02-07 10:09:13 +00008027}
8028
8029template<typename Derived>
8030ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008031TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00008032 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00008033 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8034 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00008035 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008036
Douglas Gregorb98b1992009-08-11 05:31:07 +00008037 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008038 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008039 Args.reserve(E->arg_size());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008040 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008041 &ArgumentChanged))
8042 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008043
Douglas Gregorb98b1992009-08-11 05:31:07 +00008044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00008045 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00008046 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008047 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008048
Douglas Gregorb98b1992009-08-11 05:31:07 +00008049 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00008050 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051 E->getLParenLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008052 Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008053 E->getRParenLoc());
8054}
Mike Stump1eb44332009-09-09 15:08:12 +00008055
Douglas Gregorb98b1992009-08-11 05:31:07 +00008056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008057ExprResult
John McCall865d4472009-11-19 22:55:06 +00008058TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00008059 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008060 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008061 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008062 Expr *OldBase;
8063 QualType BaseType;
8064 QualType ObjectType;
8065 if (!E->isImplicitAccess()) {
8066 OldBase = E->getBase();
8067 Base = getDerived().TransformExpr(OldBase);
8068 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008069 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008070
John McCallaa81e162009-12-01 22:10:20 +00008071 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00008072 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00008073 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00008074 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008075 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00008076 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00008077 ObjectTy,
8078 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00008079 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008080 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00008081
John McCallb3d87482010-08-24 05:47:05 +00008082 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00008083 BaseType = ((Expr*) Base.get())->getType();
8084 } else {
8085 OldBase = 0;
8086 BaseType = getDerived().TransformType(E->getBaseType());
8087 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
8088 }
Mike Stump1eb44332009-09-09 15:08:12 +00008089
Douglas Gregor6cd21982009-10-20 05:58:46 +00008090 // Transform the first part of the nested-name-specifier that qualifies
8091 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00008092 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00008093 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008094 E->getFirstQualifierFoundInScope(),
8095 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00008096
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008097 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00008098 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008099 QualifierLoc
8100 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
8101 ObjectType,
8102 FirstQualifierInScope);
8103 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008104 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00008105 }
Mike Stump1eb44332009-09-09 15:08:12 +00008106
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008107 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
8108
John McCall43fed0d2010-11-12 08:19:04 +00008109 // TODO: If this is a conversion-function-id, verify that the
8110 // destination type name (if present) resolves the same way after
8111 // instantiation as it did in the local scope.
8112
Abramo Bagnara25777432010-08-11 22:01:17 +00008113 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00008114 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00008115 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00008116 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008117
John McCallaa81e162009-12-01 22:10:20 +00008118 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008119 // This is a reference to a member without an explicitly-specified
8120 // template argument list. Optimize for this common case.
8121 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00008122 Base.get() == OldBase &&
8123 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008124 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00008125 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008126 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00008127 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008128
John McCall9ae2f072010-08-23 23:25:46 +00008129 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008130 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008131 E->isArrow(),
8132 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008133 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008134 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00008135 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008136 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008137 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008138 }
8139
John McCalld5532b62009-11-23 01:53:49 +00008140 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008141 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8142 E->getNumTemplateArgs(),
8143 TransArgs))
8144 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008145
John McCall9ae2f072010-08-23 23:25:46 +00008146 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008147 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008148 E->isArrow(),
8149 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00008150 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008151 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00008152 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00008153 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00008154 &TransArgs);
8155}
8156
8157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008158ExprResult
John McCall454feb92009-12-08 09:21:05 +00008159TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00008160 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008161 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00008162 QualType BaseType;
8163 if (!Old->isImplicitAccess()) {
8164 Base = getDerived().TransformExpr(Old->getBase());
8165 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008166 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00008167 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
8168 Old->isArrow());
8169 if (Base.isInvalid())
8170 return ExprError();
8171 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00008172 } else {
8173 BaseType = getDerived().TransformType(Old->getBaseType());
8174 }
John McCall129e2df2009-11-30 22:42:35 +00008175
Douglas Gregor4c9be892011-02-28 20:01:57 +00008176 NestedNameSpecifierLoc QualifierLoc;
8177 if (Old->getQualifierLoc()) {
8178 QualifierLoc
8179 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
8180 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00008181 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008182 }
8183
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008184 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
8185
Abramo Bagnara25777432010-08-11 22:01:17 +00008186 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00008187 Sema::LookupOrdinaryName);
8188
8189 // Transform all the decls.
8190 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
8191 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00008192 NamedDecl *InstD = static_cast<NamedDecl*>(
8193 getDerived().TransformDecl(Old->getMemberLoc(),
8194 *I));
John McCall9f54ad42009-12-10 09:41:52 +00008195 if (!InstD) {
8196 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
8197 // This can happen because of dependent hiding.
8198 if (isa<UsingShadowDecl>(*I))
8199 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008200 else {
8201 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00008202 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00008203 }
John McCall9f54ad42009-12-10 09:41:52 +00008204 }
John McCall129e2df2009-11-30 22:42:35 +00008205
8206 // Expand using declarations.
8207 if (isa<UsingDecl>(InstD)) {
8208 UsingDecl *UD = cast<UsingDecl>(InstD);
8209 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
8210 E = UD->shadow_end(); I != E; ++I)
8211 R.addDecl(*I);
8212 continue;
8213 }
8214
8215 R.addDecl(InstD);
8216 }
8217
8218 R.resolveKind();
8219
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008220 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00008221 if (Old->getNamingClass()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008222 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008223 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00008224 Old->getMemberLoc(),
8225 Old->getNamingClass()));
8226 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00008227 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008228
Douglas Gregor66c45152010-04-27 16:10:10 +00008229 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00008230 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008231
John McCall129e2df2009-11-30 22:42:35 +00008232 TemplateArgumentListInfo TransArgs;
8233 if (Old->hasExplicitTemplateArgs()) {
8234 TransArgs.setLAngleLoc(Old->getLAngleLoc());
8235 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00008236 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
8237 Old->getNumTemplateArgs(),
8238 TransArgs))
8239 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00008240 }
John McCallc2233c52010-01-15 08:34:02 +00008241
8242 // FIXME: to do this check properly, we will need to preserve the
8243 // first-qualifier-in-scope here, just in case we had a dependent
8244 // base (and therefore couldn't do the check) and a
8245 // nested-name-qualifier (and therefore could do the lookup).
8246 NamedDecl *FirstQualifierInScope = 0;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008247
John McCall9ae2f072010-08-23 23:25:46 +00008248 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00008249 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00008250 Old->getOperatorLoc(),
8251 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00008252 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008253 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00008254 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00008255 R,
8256 (Old->hasExplicitTemplateArgs()
8257 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00008258}
8259
8260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008261ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00008262TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00008263 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00008264 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
8265 if (SubExpr.isInvalid())
8266 return ExprError();
8267
8268 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00008269 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00008270
8271 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
8272}
8273
8274template<typename Derived>
8275ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00008276TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008277 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
8278 if (Pattern.isInvalid())
8279 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008280
Douglas Gregor4f1d2822011-01-13 00:19:55 +00008281 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
8282 return SemaRef.Owned(E);
8283
Douglas Gregor67fd1252011-01-14 21:20:45 +00008284 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
8285 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00008286}
Douglas Gregoree8aff02011-01-04 17:33:58 +00008287
8288template<typename Derived>
8289ExprResult
8290TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
8291 // If E is not value-dependent, then nothing will change when we transform it.
8292 // Note: This is an instantiation-centric view.
8293 if (!E->isValueDependent())
8294 return SemaRef.Owned(E);
8295
8296 // Note: None of the implementations of TryExpandParameterPacks can ever
8297 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier4a9d7952012-08-08 18:46:20 +00008298 // so
Douglas Gregoree8aff02011-01-04 17:33:58 +00008299 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
8300 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00008301 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00008302 llvm::Optional<unsigned> NumExpansions;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008303 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00008304 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00008305 ShouldExpand, RetainExpansion,
8306 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00008307 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008308
Douglas Gregor089e8932011-10-10 18:59:29 +00008309 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00008310 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008311
Douglas Gregor089e8932011-10-10 18:59:29 +00008312 NamedDecl *Pack = E->getPack();
8313 if (!ShouldExpand) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008314 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008315 Pack));
8316 if (!Pack)
8317 return ExprError();
8318 }
8319
Chad Rosier4a9d7952012-08-08 18:46:20 +00008320
Douglas Gregoree8aff02011-01-04 17:33:58 +00008321 // We now know the length of the parameter pack, so build a new expression
8322 // that stores that length.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008323 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
8324 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00008325 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00008326}
8327
Douglas Gregorbe230c32011-01-03 17:17:50 +00008328template<typename Derived>
8329ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00008330TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
8331 SubstNonTypeTemplateParmPackExpr *E) {
8332 // Default behavior is to do nothing with this transformation.
8333 return SemaRef.Owned(E);
8334}
8335
8336template<typename Derived>
8337ExprResult
John McCall91a57552011-07-15 05:09:51 +00008338TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
8339 SubstNonTypeTemplateParmExpr *E) {
8340 // Default behavior is to do nothing with this transformation.
8341 return SemaRef.Owned(E);
8342}
8343
8344template<typename Derived>
8345ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00008346TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
8347 MaterializeTemporaryExpr *E) {
8348 return getDerived().TransformExpr(E->GetTemporaryExpr());
8349}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008350
Douglas Gregor03e80032011-06-21 17:03:29 +00008351template<typename Derived>
8352ExprResult
John McCall454feb92009-12-08 09:21:05 +00008353TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008354 return SemaRef.MaybeBindToTemporary(E);
8355}
8356
8357template<typename Derived>
8358ExprResult
8359TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Jordy Rosed8b5ca12012-03-12 17:53:02 +00008360 return SemaRef.Owned(E);
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008361}
8362
8363template<typename Derived>
8364ExprResult
Patrick Beardeb382ec2012-04-19 00:25:12 +00008365TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
8366 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
8367 if (SubExpr.isInvalid())
8368 return ExprError();
8369
8370 if (!getDerived().AlwaysRebuild() &&
8371 SubExpr.get() == E->getSubExpr())
8372 return SemaRef.Owned(E);
8373
8374 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008375}
8376
8377template<typename Derived>
8378ExprResult
8379TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
8380 // Transform each of the elements.
8381 llvm::SmallVector<Expr *, 8> Elements;
8382 bool ArgChanged = false;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008383 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008384 /*IsCall=*/false, Elements, &ArgChanged))
8385 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008386
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008387 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8388 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008389
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008390 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
8391 Elements.data(),
8392 Elements.size());
8393}
8394
8395template<typename Derived>
8396ExprResult
8397TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier4a9d7952012-08-08 18:46:20 +00008398 ObjCDictionaryLiteral *E) {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008399 // Transform each of the elements.
8400 llvm::SmallVector<ObjCDictionaryElement, 8> Elements;
8401 bool ArgChanged = false;
8402 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
8403 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008404
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008405 if (OrigElement.isPackExpansion()) {
8406 // This key/value element is a pack expansion.
8407 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
8408 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
8409 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
8410 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8411
8412 // Determine whether the set of unexpanded parameter packs can
8413 // and should be expanded.
8414 bool Expand = true;
8415 bool RetainExpansion = false;
8416 llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
8417 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
8418 SourceRange PatternRange(OrigElement.Key->getLocStart(),
8419 OrigElement.Value->getLocEnd());
8420 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
8421 PatternRange,
8422 Unexpanded,
8423 Expand, RetainExpansion,
8424 NumExpansions))
8425 return ExprError();
8426
8427 if (!Expand) {
8428 // The transform has determined that we should perform a simple
Chad Rosier4a9d7952012-08-08 18:46:20 +00008429 // transformation on the pack expansion, producing another pack
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008430 // expansion.
8431 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
8432 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8433 if (Key.isInvalid())
8434 return ExprError();
8435
8436 if (Key.get() != OrigElement.Key)
8437 ArgChanged = true;
8438
8439 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8440 if (Value.isInvalid())
8441 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008442
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008443 if (Value.get() != OrigElement.Value)
8444 ArgChanged = true;
8445
Chad Rosier4a9d7952012-08-08 18:46:20 +00008446 ObjCDictionaryElement Expansion = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008447 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
8448 };
8449 Elements.push_back(Expansion);
8450 continue;
8451 }
8452
8453 // Record right away that the argument was changed. This needs
8454 // to happen even if the array expands to nothing.
8455 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008456
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008457 // The transform has determined that we should perform an elementwise
8458 // expansion of the pattern. Do so.
8459 for (unsigned I = 0; I != *NumExpansions; ++I) {
8460 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
8461 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8462 if (Key.isInvalid())
8463 return ExprError();
8464
8465 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
8466 if (Value.isInvalid())
8467 return ExprError();
8468
Chad Rosier4a9d7952012-08-08 18:46:20 +00008469 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008470 Key.get(), Value.get(), SourceLocation(), NumExpansions
8471 };
8472
8473 // If any unexpanded parameter packs remain, we still have a
8474 // pack expansion.
8475 if (Key.get()->containsUnexpandedParameterPack() ||
8476 Value.get()->containsUnexpandedParameterPack())
8477 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008478
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008479 Elements.push_back(Element);
8480 }
8481
8482 // We've finished with this pack expansion.
8483 continue;
8484 }
8485
8486 // Transform and check key.
8487 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
8488 if (Key.isInvalid())
8489 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008490
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008491 if (Key.get() != OrigElement.Key)
8492 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008493
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008494 // Transform and check value.
8495 ExprResult Value
8496 = getDerived().TransformExpr(OrigElement.Value);
8497 if (Value.isInvalid())
8498 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008499
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008500 if (Value.get() != OrigElement.Value)
8501 ArgChanged = true;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008502
8503 ObjCDictionaryElement Element = {
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008504 Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>()
8505 };
8506 Elements.push_back(Element);
8507 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008508
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008509 if (!getDerived().AlwaysRebuild() && !ArgChanged)
8510 return SemaRef.MaybeBindToTemporary(E);
8511
8512 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
8513 Elements.data(),
8514 Elements.size());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008515}
8516
Mike Stump1eb44332009-09-09 15:08:12 +00008517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008518ExprResult
John McCall454feb92009-12-08 09:21:05 +00008519TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00008520 TypeSourceInfo *EncodedTypeInfo
8521 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
8522 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008523 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008524
Douglas Gregorb98b1992009-08-11 05:31:07 +00008525 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00008526 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00008527 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008528
8529 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00008530 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008531 E->getRParenLoc());
8532}
Mike Stump1eb44332009-09-09 15:08:12 +00008533
Douglas Gregorb98b1992009-08-11 05:31:07 +00008534template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00008535ExprResult TreeTransform<Derived>::
8536TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
8537 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
8538 if (result.isInvalid()) return ExprError();
8539 Expr *subExpr = result.take();
8540
8541 if (!getDerived().AlwaysRebuild() &&
8542 subExpr == E->getSubExpr())
8543 return SemaRef.Owned(E);
8544
8545 return SemaRef.Owned(new(SemaRef.Context)
8546 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
8547}
8548
8549template<typename Derived>
8550ExprResult TreeTransform<Derived>::
8551TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008552 TypeSourceInfo *TSInfo
John McCallf85e1932011-06-15 23:02:42 +00008553 = getDerived().TransformType(E->getTypeInfoAsWritten());
8554 if (!TSInfo)
8555 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008556
John McCallf85e1932011-06-15 23:02:42 +00008557 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008558 if (Result.isInvalid())
John McCallf85e1932011-06-15 23:02:42 +00008559 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008560
John McCallf85e1932011-06-15 23:02:42 +00008561 if (!getDerived().AlwaysRebuild() &&
8562 TSInfo == E->getTypeInfoAsWritten() &&
8563 Result.get() == E->getSubExpr())
8564 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008565
John McCallf85e1932011-06-15 23:02:42 +00008566 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier4a9d7952012-08-08 18:46:20 +00008567 E->getBridgeKeywordLoc(), TSInfo,
John McCallf85e1932011-06-15 23:02:42 +00008568 Result.get());
8569}
8570
8571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008572ExprResult
John McCall454feb92009-12-08 09:21:05 +00008573TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008574 // Transform arguments.
8575 bool ArgChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008576 SmallVector<Expr*, 8> Args;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008577 Args.reserve(E->getNumArgs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008578 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008579 &ArgChanged))
8580 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008581
Douglas Gregor92e986e2010-04-22 16:44:27 +00008582 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8583 // Class message: transform the receiver type.
8584 TypeSourceInfo *ReceiverTypeInfo
8585 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8586 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008587 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008588
Douglas Gregor92e986e2010-04-22 16:44:27 +00008589 // If nothing changed, just retain the existing message send.
8590 if (!getDerived().AlwaysRebuild() &&
8591 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008592 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008593
8594 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008595 SmallVector<SourceLocation, 16> SelLocs;
8596 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008597 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8598 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008599 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008600 E->getMethodDecl(),
8601 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008602 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008603 E->getRightLoc());
8604 }
8605
8606 // Instance message: transform the receiver
8607 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8608 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008609 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008610 = getDerived().TransformExpr(E->getInstanceReceiver());
8611 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008612 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008613
8614 // If nothing changed, just retain the existing message send.
8615 if (!getDerived().AlwaysRebuild() &&
8616 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008617 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008618
Douglas Gregor92e986e2010-04-22 16:44:27 +00008619 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008620 SmallVector<SourceLocation, 16> SelLocs;
8621 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008622 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008623 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008624 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008625 E->getMethodDecl(),
8626 E->getLeftLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008627 Args,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008628 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008629}
8630
Mike Stump1eb44332009-09-09 15:08:12 +00008631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008632ExprResult
John McCall454feb92009-12-08 09:21:05 +00008633TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008634 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008635}
8636
Mike Stump1eb44332009-09-09 15:08:12 +00008637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008638ExprResult
John McCall454feb92009-12-08 09:21:05 +00008639TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008640 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008641}
8642
Mike Stump1eb44332009-09-09 15:08:12 +00008643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008644ExprResult
John McCall454feb92009-12-08 09:21:05 +00008645TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008646 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008647 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008648 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008649 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008650
8651 // We don't need to transform the ivar; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008652
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008653 // If nothing changed, just retain the existing expression.
8654 if (!getDerived().AlwaysRebuild() &&
8655 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008656 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008657
John McCall9ae2f072010-08-23 23:25:46 +00008658 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008659 E->getLocation(),
8660 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008661}
8662
Mike Stump1eb44332009-09-09 15:08:12 +00008663template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008664ExprResult
John McCall454feb92009-12-08 09:21:05 +00008665TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008666 // 'super' and types never change. Property never changes. Just
8667 // retain the existing expression.
8668 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008669 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008670
Douglas Gregore3303542010-04-26 20:47:02 +00008671 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008672 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008673 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008674 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008675
Douglas Gregore3303542010-04-26 20:47:02 +00008676 // We don't need to transform the property; it will never change.
Chad Rosier4a9d7952012-08-08 18:46:20 +00008677
Douglas Gregore3303542010-04-26 20:47:02 +00008678 // If nothing changed, just retain the existing expression.
8679 if (!getDerived().AlwaysRebuild() &&
8680 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008681 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008682
John McCall12f78a62010-12-02 01:19:52 +00008683 if (E->isExplicitProperty())
8684 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8685 E->getExplicitProperty(),
8686 E->getLocation());
8687
8688 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008689 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008690 E->getImplicitPropertyGetter(),
8691 E->getImplicitPropertySetter(),
8692 E->getLocation());
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
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008697TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
8698 // Transform the base expression.
8699 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8700 if (Base.isInvalid())
8701 return ExprError();
8702
8703 // Transform the key expression.
8704 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
8705 if (Key.isInvalid())
8706 return ExprError();
8707
8708 // If nothing changed, just retain the existing expression.
8709 if (!getDerived().AlwaysRebuild() &&
8710 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
8711 return SemaRef.Owned(E);
8712
Chad Rosier4a9d7952012-08-08 18:46:20 +00008713 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremenekebcb57a2012-03-06 20:05:56 +00008714 Base.get(), Key.get(),
8715 E->getAtIndexMethodDecl(),
8716 E->setAtIndexMethodDecl());
8717}
8718
8719template<typename Derived>
8720ExprResult
John McCall454feb92009-12-08 09:21:05 +00008721TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008722 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008723 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008724 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008725 return ExprError();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008726
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008727 // If nothing changed, just retain the existing expression.
8728 if (!getDerived().AlwaysRebuild() &&
8729 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008730 return SemaRef.Owned(E);
Chad Rosier4a9d7952012-08-08 18:46:20 +00008731
John McCall9ae2f072010-08-23 23:25:46 +00008732 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008733 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008734}
8735
Mike Stump1eb44332009-09-09 15:08:12 +00008736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008737ExprResult
John McCall454feb92009-12-08 09:21:05 +00008738TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008739 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008740 SmallVector<Expr*, 8> SubExprs;
Douglas Gregoraa165f82011-01-03 19:04:46 +00008741 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008742 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregoraa165f82011-01-03 19:04:46 +00008743 SubExprs, &ArgumentChanged))
8744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008745
Douglas Gregorb98b1992009-08-11 05:31:07 +00008746 if (!getDerived().AlwaysRebuild() &&
8747 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008748 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008749
Douglas Gregorb98b1992009-08-11 05:31:07 +00008750 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008751 SubExprs,
Douglas Gregorb98b1992009-08-11 05:31:07 +00008752 E->getRParenLoc());
8753}
8754
Mike Stump1eb44332009-09-09 15:08:12 +00008755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008756ExprResult
John McCall454feb92009-12-08 09:21:05 +00008757TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008758 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier4a9d7952012-08-08 18:46:20 +00008759
John McCallc6ac9c32011-02-04 18:33:18 +00008760 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8761 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8762
8763 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008764 blockScope->TheDecl->setBlockMissingReturnType(
8765 oldBlock->blockMissingReturnType());
Chad Rosier4a9d7952012-08-08 18:46:20 +00008766
Chris Lattner686775d2011-07-20 06:58:45 +00008767 SmallVector<ParmVarDecl*, 4> params;
8768 SmallVector<QualType, 4> paramTypes;
Chad Rosier4a9d7952012-08-08 18:46:20 +00008769
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008770 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008771 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8772 oldBlock->param_begin(),
8773 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008774 0, paramTypes, &params)) {
8775 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008776 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008777 }
John McCallc6ac9c32011-02-04 18:33:18 +00008778
8779 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008780 QualType exprResultType =
8781 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008782
8783 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008784 if (exprResultType->isObjCObjectType()) {
Chad Rosier4a9d7952012-08-08 18:46:20 +00008785 getSema().Diag(E->getCaretLocation(),
8786 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008787 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008788 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008789 return ExprError();
8790 }
John McCall711c52b2011-01-05 12:14:39 +00008791
John McCallc6ac9c32011-02-04 18:33:18 +00008792 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008793 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008794 paramTypes.data(),
8795 paramTypes.size(),
8796 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008797 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008798 exprFunctionType->getExtInfo());
8799 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008800
8801 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008802 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008803 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008804
8805 if (!oldBlock->blockMissingReturnType()) {
8806 blockScope->HasImplicitReturnType = false;
8807 blockScope->ReturnType = exprResultType;
8808 }
Chad Rosier4a9d7952012-08-08 18:46:20 +00008809
John McCall711c52b2011-01-05 12:14:39 +00008810 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008811 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008812 if (body.isInvalid()) {
8813 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008814 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008815 }
John McCall711c52b2011-01-05 12:14:39 +00008816
John McCallc6ac9c32011-02-04 18:33:18 +00008817#ifndef NDEBUG
8818 // In builds with assertions, make sure that we captured everything we
8819 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008820 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8821 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8822 e = oldBlock->capture_end(); i != e; ++i) {
8823 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008824
Douglas Gregorfc921372011-05-20 15:32:55 +00008825 // Ignore parameter packs.
8826 if (isa<ParmVarDecl>(oldCapture) &&
8827 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8828 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008829
Douglas Gregorfc921372011-05-20 15:32:55 +00008830 VarDecl *newCapture =
8831 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8832 oldCapture));
8833 assert(blockScope->CaptureMap.count(newCapture));
8834 }
Douglas Gregorec79d872012-02-24 17:41:38 +00008835 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCallc6ac9c32011-02-04 18:33:18 +00008836 }
8837#endif
8838
8839 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8840 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008841}
8842
Mike Stump1eb44332009-09-09 15:08:12 +00008843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008844ExprResult
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008845TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008846 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008847}
Eli Friedman276b0612011-10-11 02:20:01 +00008848
8849template<typename Derived>
8850ExprResult
8851TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008852 QualType RetTy = getDerived().TransformType(E->getType());
8853 bool ArgumentChanged = false;
Benjamin Kramer4e28d9e2012-08-23 22:51:59 +00008854 SmallVector<Expr*, 8> SubExprs;
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008855 SubExprs.reserve(E->getNumSubExprs());
8856 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8857 SubExprs, &ArgumentChanged))
8858 return ExprError();
8859
8860 if (!getDerived().AlwaysRebuild() &&
8861 !ArgumentChanged)
8862 return SemaRef.Owned(E);
8863
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00008864 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008865 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008866}
Chad Rosier4a9d7952012-08-08 18:46:20 +00008867
Douglas Gregorb98b1992009-08-11 05:31:07 +00008868//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008869// Type reconstruction
8870//===----------------------------------------------------------------------===//
8871
Mike Stump1eb44332009-09-09 15:08:12 +00008872template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008873QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8874 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008875 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008876 getDerived().getBaseEntity());
8877}
8878
Mike Stump1eb44332009-09-09 15:08:12 +00008879template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008880QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8881 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008882 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008883 getDerived().getBaseEntity());
8884}
8885
Mike Stump1eb44332009-09-09 15:08:12 +00008886template<typename Derived>
8887QualType
John McCall85737a72009-10-30 00:06:24 +00008888TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8889 bool WrittenAsLValue,
8890 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008891 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008892 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008893}
8894
8895template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008896QualType
John McCall85737a72009-10-30 00:06:24 +00008897TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8898 QualType ClassType,
8899 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008900 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008901 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008902}
8903
8904template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008905QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008906TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8907 ArrayType::ArraySizeModifier SizeMod,
8908 const llvm::APInt *Size,
8909 Expr *SizeExpr,
8910 unsigned IndexTypeQuals,
8911 SourceRange BracketsRange) {
8912 if (SizeExpr || !Size)
8913 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8914 IndexTypeQuals, BracketsRange,
8915 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008916
8917 QualType Types[] = {
8918 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8919 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8920 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008921 };
8922 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8923 QualType SizeType;
8924 for (unsigned I = 0; I != NumTypes; ++I)
8925 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8926 SizeType = Types[I];
8927 break;
8928 }
Mike Stump1eb44332009-09-09 15:08:12 +00008929
Eli Friedman01f276d2012-01-25 23:20:27 +00008930 // Note that we can return a VariableArrayType here in the case where
8931 // the element type was a dependent VariableArrayType.
8932 IntegerLiteral *ArraySize
8933 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8934 /*FIXME*/BracketsRange.getBegin());
8935 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008936 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008937 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008938}
Mike Stump1eb44332009-09-09 15:08:12 +00008939
Douglas Gregor577f75a2009-08-04 16:50:30 +00008940template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008941QualType
8942TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008943 ArrayType::ArraySizeModifier SizeMod,
8944 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008945 unsigned IndexTypeQuals,
8946 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008947 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008948 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008949}
8950
8951template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008952QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008953TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008954 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008955 unsigned IndexTypeQuals,
8956 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008957 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008958 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008959}
Mike Stump1eb44332009-09-09 15:08:12 +00008960
Douglas Gregor577f75a2009-08-04 16:50:30 +00008961template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008962QualType
8963TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008964 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008965 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008966 unsigned IndexTypeQuals,
8967 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008968 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008969 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008970 IndexTypeQuals, BracketsRange);
8971}
8972
8973template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008974QualType
8975TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008976 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008977 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008978 unsigned IndexTypeQuals,
8979 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008980 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008981 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008982 IndexTypeQuals, BracketsRange);
8983}
8984
8985template<typename Derived>
8986QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008987 unsigned NumElements,
8988 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008989 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008990 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008991}
Mike Stump1eb44332009-09-09 15:08:12 +00008992
Douglas Gregor577f75a2009-08-04 16:50:30 +00008993template<typename Derived>
8994QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8995 unsigned NumElements,
8996 SourceLocation AttributeLoc) {
8997 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8998 NumElements, true);
8999 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00009000 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
9001 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00009002 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009003}
Mike Stump1eb44332009-09-09 15:08:12 +00009004
Douglas Gregor577f75a2009-08-04 16:50:30 +00009005template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009006QualType
9007TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00009008 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009009 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00009010 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009011}
Mike Stump1eb44332009-09-09 15:08:12 +00009012
Douglas Gregor577f75a2009-08-04 16:50:30 +00009013template<typename Derived>
9014QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00009015 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009016 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00009017 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009018 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00009019 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00009020 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00009021 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00009022 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00009023 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00009024 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00009025 getDerived().getBaseEntity(),
9026 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009027}
Mike Stump1eb44332009-09-09 15:08:12 +00009028
Douglas Gregor577f75a2009-08-04 16:50:30 +00009029template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00009030QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
9031 return SemaRef.Context.getFunctionNoProtoType(T);
9032}
9033
9034template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00009035QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
9036 assert(D && "no decl found");
9037 if (D->isInvalidDecl()) return QualType();
9038
Douglas Gregor92e986e2010-04-22 16:44:27 +00009039 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00009040 TypeDecl *Ty;
9041 if (isa<UsingDecl>(D)) {
9042 UsingDecl *Using = cast<UsingDecl>(D);
9043 assert(Using->isTypeName() &&
9044 "UnresolvedUsingTypenameDecl transformed to non-typename using");
9045
9046 // A valid resolved using typename decl points to exactly one type decl.
9047 assert(++Using->shadow_begin() == Using->shadow_end());
9048 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier4a9d7952012-08-08 18:46:20 +00009049
John McCalled976492009-12-04 22:46:56 +00009050 } else {
9051 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
9052 "UnresolvedUsingTypenameDecl transformed to non-using decl");
9053 Ty = cast<UnresolvedUsingTypenameDecl>(D);
9054 }
9055
9056 return SemaRef.Context.getTypeDeclType(Ty);
9057}
9058
9059template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009060QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
9061 SourceLocation Loc) {
9062 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009063}
9064
9065template<typename Derived>
9066QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
9067 return SemaRef.Context.getTypeOfType(Underlying);
9068}
9069
9070template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00009071QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
9072 SourceLocation Loc) {
9073 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009074}
9075
9076template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00009077QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
9078 UnaryTransformType::UTTKind UKind,
9079 SourceLocation Loc) {
9080 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
9081}
9082
9083template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00009084QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00009085 TemplateName Template,
9086 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00009087 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00009088 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00009089}
Mike Stump1eb44332009-09-09 15:08:12 +00009090
Douglas Gregordcee1a12009-08-06 05:28:30 +00009091template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00009092QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
9093 SourceLocation KWLoc) {
9094 return SemaRef.BuildAtomicType(ValueType, KWLoc);
9095}
9096
9097template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009098TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009099TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00009100 bool TemplateKW,
9101 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009102 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00009103 Template);
9104}
9105
9106template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00009107TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009108TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
9109 const IdentifierInfo &Name,
9110 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00009111 QualType ObjectType,
9112 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009113 UnqualifiedId TemplateName;
9114 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00009115 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009116 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009117 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009118 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00009119 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009120 /*EnteringContext=*/false,
9121 Template);
John McCall43fed0d2010-11-12 08:19:04 +00009122 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00009123}
Mike Stump1eb44332009-09-09 15:08:12 +00009124
Douglas Gregorb98b1992009-08-11 05:31:07 +00009125template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009126TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009127TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009128 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009129 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009130 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009131 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009132 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009133 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00009134 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009135 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00009136 Sema::TemplateTy Template;
9137 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009138 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00009139 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00009140 /*EnteringContext=*/false,
9141 Template);
9142 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009143}
Chad Rosier4a9d7952012-08-08 18:46:20 +00009144
Douglas Gregorca1bdd72009-11-04 00:56:37 +00009145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00009146ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00009147TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
9148 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00009149 Expr *OrigCallee,
9150 Expr *First,
9151 Expr *Second) {
9152 Expr *Callee = OrigCallee->IgnoreParenCasts();
9153 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00009154
Douglas Gregorb98b1992009-08-11 05:31:07 +00009155 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00009156 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00009157 if (!First->getType()->isOverloadableType() &&
9158 !Second->getType()->isOverloadableType())
9159 return getSema().CreateBuiltinArraySubscriptExpr(First,
9160 Callee->getLocStart(),
9161 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00009162 } else if (Op == OO_Arrow) {
9163 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00009164 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
9165 } else if (Second == 0 || isPostIncDec) {
9166 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009167 // The argument is not of overloadable type, so try to create a
9168 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00009169 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009170 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00009171
John McCall9ae2f072010-08-23 23:25:46 +00009172 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009173 }
9174 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009175 if (!First->getType()->isOverloadableType() &&
9176 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00009177 // Neither of the arguments is an overloadable type, so try to
9178 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00009179 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009180 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00009181 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009182 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009183 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009184
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009185 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009186 }
9187 }
Mike Stump1eb44332009-09-09 15:08:12 +00009188
9189 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00009190 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00009191 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00009192
John McCall9ae2f072010-08-23 23:25:46 +00009193 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00009194 assert(ULE->requiresADL());
9195
9196 // FIXME: Do we have to check
9197 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00009198 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00009199 } else {
John McCall9ae2f072010-08-23 23:25:46 +00009200 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00009201 }
Mike Stump1eb44332009-09-09 15:08:12 +00009202
Douglas Gregorb98b1992009-08-11 05:31:07 +00009203 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00009204 Expr *Args[2] = { First, Second };
9205 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00009206
Douglas Gregorb98b1992009-08-11 05:31:07 +00009207 // Create the overloaded operator invocation for unary operators.
9208 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00009209 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00009210 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00009211 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00009212 }
Mike Stump1eb44332009-09-09 15:08:12 +00009213
Douglas Gregor5b8968c2011-07-15 16:25:15 +00009214 if (Op == OO_Subscript) {
9215 SourceLocation LBrace;
9216 SourceLocation RBrace;
9217
9218 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
9219 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
9220 LBrace = SourceLocation::getFromRawEncoding(
9221 NameLoc.CXXOperatorName.BeginOpNameLoc);
9222 RBrace = SourceLocation::getFromRawEncoding(
9223 NameLoc.CXXOperatorName.EndOpNameLoc);
9224 } else {
9225 LBrace = Callee->getLocStart();
9226 RBrace = OpLoc;
9227 }
9228
9229 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
9230 First, Second);
9231 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00009232
Douglas Gregorb98b1992009-08-11 05:31:07 +00009233 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00009234 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00009235 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00009236 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
9237 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00009238 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00009239
Benjamin Kramer3fe198b2012-08-23 21:35:17 +00009240 return Result;
Douglas Gregorb98b1992009-08-11 05:31:07 +00009241}
Mike Stump1eb44332009-09-09 15:08:12 +00009242
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009243template<typename Derived>
Chad Rosier4a9d7952012-08-08 18:46:20 +00009244ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00009245TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009246 SourceLocation OperatorLoc,
9247 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00009248 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009249 TypeSourceInfo *ScopeType,
9250 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009251 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009252 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00009253 QualType BaseType = Base->getType();
9254 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009255 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier4a9d7952012-08-08 18:46:20 +00009256 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00009257 !BaseType->getAs<PointerType>()->getPointeeType()
9258 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009259 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00009260 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009261 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00009262 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009263 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009264 /*FIXME?*/true);
9265 }
Abramo Bagnara25777432010-08-11 22:01:17 +00009266
Douglas Gregora2e7dd22010-02-25 01:56:36 +00009267 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00009268 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
9269 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
9270 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
9271 NameInfo.setNamedTypeInfo(DestroyedType);
9272
Richard Smith6314db92012-05-15 06:15:11 +00009273 // The scope type is now known to be a valid nested name specifier
9274 // component. Tack it on to the end of the nested name specifier.
9275 if (ScopeType)
9276 SS.Extend(SemaRef.Context, SourceLocation(),
9277 ScopeType->getTypeLoc(), CCLoc);
Abramo Bagnara25777432010-08-11 22:01:17 +00009278
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009279 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00009280 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009281 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00009282 SS, TemplateKWLoc,
9283 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00009284 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00009285 /*TemplateArgs*/ 0);
9286}
9287
Douglas Gregor577f75a2009-08-04 16:50:30 +00009288} // end namespace clang
9289
9290#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H