blob: cb0d4250fca577175a769e142b3d4bfa941dbe41 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +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.
7//===----------------------------------------------------------------------===/
8//
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//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCall781472f2010-08-25 08:40:02 +000037using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000038
Douglas Gregor577f75a2009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump1eb44332009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump1eb44332009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000092 /// \brief Private RAII object that helps us forget and then re-remember
93 /// the template argument corresponding to a partially-substituted parameter
94 /// pack.
95 class ForgetPartiallySubstitutedPackRAII {
96 Derived &Self;
97 TemplateArgument Old;
98
99 public:
100 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
101 Old = Self.ForgetPartiallySubstitutedPack();
102 }
103
104 ~ForgetPartiallySubstitutedPackRAII() {
105 Self.RememberPartiallySubstitutedPack(Old);
106 }
107 };
108
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109protected:
110 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000111
Mike Stump1eb44332009-09-09 15:08:12 +0000112public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000114 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000115
Douglas Gregor577f75a2009-08-04 16:50:30 +0000116 /// \brief Retrieves a reference to the derived class.
117 Derived &getDerived() { return static_cast<Derived&>(*this); }
118
119 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000120 const Derived &getDerived() const {
121 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 }
123
John McCall60d7b3a2010-08-24 06:29:42 +0000124 static inline ExprResult Owned(Expr *E) { return E; }
125 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000126
Douglas Gregor577f75a2009-08-04 16:50:30 +0000127 /// \brief Retrieves a reference to the semantic analysis object used for
128 /// this tree transform.
129 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000130
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 /// \brief Whether the transformation should always rebuild AST nodes, even
132 /// if none of the children have changed.
133 ///
134 /// Subclasses may override this function to specify when the transformation
135 /// should rebuild all AST nodes.
136 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000137
Douglas Gregor577f75a2009-08-04 16:50:30 +0000138 /// \brief Returns the location of the entity being transformed, if that
139 /// information was not available elsewhere in the AST.
140 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000141 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000142 /// provide an alternative implementation that provides better location
143 /// information.
144 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the name of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
149 /// By default, returns an empty name. Subclasses can provide an alternative
150 /// implementation with a more precise name.
151 DeclarationName getBaseEntity() { return DeclarationName(); }
152
Douglas Gregorb98b1992009-08-11 05:31:07 +0000153 /// \brief Sets the "base" location and entity when that
154 /// information is known based on another transformation.
155 ///
156 /// By default, the source location and entity are ignored. Subclasses can
157 /// override this function to provide a customized implementation.
158 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000159
Douglas Gregorb98b1992009-08-11 05:31:07 +0000160 /// \brief RAII object that temporarily sets the base location and entity
161 /// used for reporting diagnostics in types.
162 class TemporaryBase {
163 TreeTransform &Self;
164 SourceLocation OldLocation;
165 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000166
Douglas Gregorb98b1992009-08-11 05:31:07 +0000167 public:
168 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000169 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000170 OldLocation = Self.getDerived().getBaseLocation();
171 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000172
173 if (Location.isValid())
174 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 }
Mike Stump1eb44332009-09-09 15:08:12 +0000176
Douglas Gregorb98b1992009-08-11 05:31:07 +0000177 ~TemporaryBase() {
178 Self.getDerived().setBase(OldLocation, OldEntity);
179 }
180 };
Mike Stump1eb44332009-09-09 15:08:12 +0000181
182 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000183 /// transformed.
184 ///
185 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000186 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000187 /// not change. For example, template instantiation need not traverse
188 /// non-dependent types.
189 bool AlreadyTransformed(QualType T) {
190 return T.isNull();
191 }
192
Douglas Gregor6eef5192009-12-14 19:27:10 +0000193 /// \brief Determine whether the given call argument should be dropped, e.g.,
194 /// because it is a default argument.
195 ///
196 /// Subclasses can provide an alternative implementation of this routine to
197 /// determine which kinds of call arguments get dropped. By default,
198 /// CXXDefaultArgument nodes are dropped (prior to transformation).
199 bool DropCallArgument(Expr *E) {
200 return E->isDefaultArgument();
201 }
Sean Huntc3021132010-05-05 15:23:54 +0000202
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000203 /// \brief Determine whether we should expand a pack expansion with the
204 /// given set of parameter packs into separate arguments by repeatedly
205 /// transforming the pattern.
206 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000207 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000208 /// Subclasses can override this routine to provide different behavior.
209 ///
210 /// \param EllipsisLoc The location of the ellipsis that identifies the
211 /// pack expansion.
212 ///
213 /// \param PatternRange The source range that covers the entire pattern of
214 /// the pack expansion.
215 ///
216 /// \param Unexpanded The set of unexpanded parameter packs within the
217 /// pattern.
218 ///
219 /// \param NumUnexpanded The number of unexpanded parameter packs in
220 /// \p Unexpanded.
221 ///
222 /// \param ShouldExpand Will be set to \c true if the transformer should
223 /// expand the corresponding pack expansions into separate arguments. When
224 /// set, \c NumExpansions must also be set.
225 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000226 /// \param RetainExpansion Whether the caller should add an unexpanded
227 /// pack expansion after all of the expanded arguments. This is used
228 /// when extending explicitly-specified template argument packs per
229 /// C++0x [temp.arg.explicit]p9.
230 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000231 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000232 /// the expanded form of the corresponding pack expansion. This is both an
233 /// input and an output parameter, which can be set by the caller if the
234 /// number of expansions is known a priori (e.g., due to a prior substitution)
235 /// and will be set by the callee when the number of expansions is known.
236 /// The callee must set this value when \c ShouldExpand is \c true; it may
237 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000238 ///
239 /// \returns true if an error occurred (e.g., because the parameter packs
240 /// are to be instantiated with arguments of different lengths), false
241 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
242 /// must be set.
243 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
244 SourceRange PatternRange,
245 const UnexpandedParameterPack *Unexpanded,
246 unsigned NumUnexpanded,
247 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000248 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000249 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000250 ShouldExpand = false;
251 return false;
252 }
253
Douglas Gregord3731192011-01-10 07:32:04 +0000254 /// \brief "Forget" about the partially-substituted pack template argument,
255 /// when performing an instantiation that must preserve the parameter pack
256 /// use.
257 ///
258 /// This routine is meant to be overridden by the template instantiator.
259 TemplateArgument ForgetPartiallySubstitutedPack() {
260 return TemplateArgument();
261 }
262
263 /// \brief "Remember" the partially-substituted pack template argument
264 /// after performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
269
Douglas Gregor12c9c002011-01-07 16:43:16 +0000270 /// \brief Note to the derived class when a function parameter pack is
271 /// being expanded.
272 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
273
Douglas Gregor577f75a2009-08-04 16:50:30 +0000274 /// \brief Transforms the given type into another type.
275 ///
John McCalla2becad2009-10-21 00:40:46 +0000276 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000277 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000278 /// function. This is expensive, but we don't mind, because
279 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000280 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 ///
282 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000283 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000284
John McCalla2becad2009-10-21 00:40:46 +0000285 /// \brief Transforms the given type-with-location into a new
286 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 ///
John McCalla2becad2009-10-21 00:40:46 +0000288 /// By default, this routine transforms a type by delegating to the
289 /// appropriate TransformXXXType to build a new type. Subclasses
290 /// may override this function (to take over all type
291 /// transformations) or some set of the TransformXXXType functions
292 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000293 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000294
295 /// \brief Transform the given type-with-location into a new
296 /// type, collecting location information in the given builder
297 /// as necessary.
298 ///
John McCall43fed0d2010-11-12 08:19:04 +0000299 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000300
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000301 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000302 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000303 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000304 /// appropriate TransformXXXStmt function to transform a specific kind of
305 /// statement or the TransformExpr() function to transform an expression.
306 /// Subclasses may override this function to transform statements using some
307 /// other mechanism.
308 ///
309 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000310 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000311
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000312 /// \brief Transform the given expression.
313 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000314 /// By default, this routine transforms an expression by delegating to the
315 /// appropriate TransformXXXExpr function to build a new expression.
316 /// Subclasses may override this function to transform expressions using some
317 /// other mechanism.
318 ///
319 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000320 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000321
Douglas Gregoraa165f82011-01-03 19:04:46 +0000322 /// \brief Transform the given list of expressions.
323 ///
324 /// This routine transforms a list of expressions by invoking
325 /// \c TransformExpr() for each subexpression. However, it also provides
326 /// support for variadic templates by expanding any pack expansions (if the
327 /// derived class permits such expansion) along the way. When pack expansions
328 /// are present, the number of outputs may not equal the number of inputs.
329 ///
330 /// \param Inputs The set of expressions to be transformed.
331 ///
332 /// \param NumInputs The number of expressions in \c Inputs.
333 ///
334 /// \param IsCall If \c true, then this transform is being performed on
335 /// function-call arguments, and any arguments that should be dropped, will
336 /// be.
337 ///
338 /// \param Outputs The transformed input expressions will be added to this
339 /// vector.
340 ///
341 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
342 /// due to transformation.
343 ///
344 /// \returns true if an error occurred, false otherwise.
345 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
346 llvm::SmallVectorImpl<Expr *> &Outputs,
347 bool *ArgChanged = 0);
348
Douglas Gregor577f75a2009-08-04 16:50:30 +0000349 /// \brief Transform the given declaration, which is referenced from a type
350 /// or expression.
351 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000352 /// By default, acts as the identity function on declarations. Subclasses
353 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000354 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000355
356 /// \brief Transform the definition of the given declaration.
357 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000358 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000359 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000360 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
361 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000362 }
Mike Stump1eb44332009-09-09 15:08:12 +0000363
Douglas Gregor6cd21982009-10-20 05:58:46 +0000364 /// \brief Transform the given declaration, which was the first part of a
365 /// nested-name-specifier in a member access expression.
366 ///
Sean Huntc3021132010-05-05 15:23:54 +0000367 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000368 /// identifier in a nested-name-specifier of a member access expression, e.g.,
369 /// the \c T in \c x->T::member
370 ///
371 /// By default, invokes TransformDecl() to transform the declaration.
372 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000373 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
374 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000375 }
Sean Huntc3021132010-05-05 15:23:54 +0000376
Douglas Gregor577f75a2009-08-04 16:50:30 +0000377 /// \brief Transform the given nested-name-specifier.
378 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000379 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000380 /// nested-name-specifier. Subclasses may override this function to provide
381 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000382 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000383 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000384 QualType ObjectType = QualType(),
385 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000386
Douglas Gregor81499bb2009-09-03 22:13:48 +0000387 /// \brief Transform the given declaration name.
388 ///
389 /// By default, transforms the types of conversion function, constructor,
390 /// and destructor names and then (if needed) rebuilds the declaration name.
391 /// Identifiers and selectors are returned unmodified. Sublcasses may
392 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000393 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000394 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Douglas Gregor577f75a2009-08-04 16:50:30 +0000396 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000397 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000398 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000399 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000400 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000401 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000402 QualType ObjectType = QualType(),
403 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000404
Douglas Gregor577f75a2009-08-04 16:50:30 +0000405 /// \brief Transform the given template argument.
406 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000407 /// By default, this operation transforms the type, expression, or
408 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000409 /// new template argument from the transformed result. Subclasses may
410 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000411 ///
412 /// Returns true if there was an error.
413 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
414 TemplateArgumentLoc &Output);
415
Douglas Gregorfcc12532010-12-20 17:31:10 +0000416 /// \brief Transform the given set of template arguments.
417 ///
418 /// By default, this operation transforms all of the template arguments
419 /// in the input set using \c TransformTemplateArgument(), and appends
420 /// the transformed arguments to the output list.
421 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000422 /// Note that this overload of \c TransformTemplateArguments() is merely
423 /// a convenience function. Subclasses that wish to override this behavior
424 /// should override the iterator-based member template version.
425 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000426 /// \param Inputs The set of template arguments to be transformed.
427 ///
428 /// \param NumInputs The number of template arguments in \p Inputs.
429 ///
430 /// \param Outputs The set of transformed template arguments output by this
431 /// routine.
432 ///
433 /// Returns true if an error occurred.
434 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
435 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000436 TemplateArgumentListInfo &Outputs) {
437 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
438 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000439
440 /// \brief Transform the given set of template arguments.
441 ///
442 /// By default, this operation transforms all of the template arguments
443 /// in the input set using \c TransformTemplateArgument(), and appends
444 /// the transformed arguments to the output list.
445 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000446 /// \param First An iterator to the first template argument.
447 ///
448 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000454 template<typename InputIterator>
455 bool TransformTemplateArguments(InputIterator First,
456 InputIterator Last,
457 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000458
John McCall833ca992009-10-29 08:12:44 +0000459 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
460 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
461 TemplateArgumentLoc &ArgLoc);
462
John McCalla93c9342009-12-07 02:54:59 +0000463 /// \brief Fakes up a TypeSourceInfo for a type.
464 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
465 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000466 getDerived().getBaseLocation());
467 }
Mike Stump1eb44332009-09-09 15:08:12 +0000468
John McCalla2becad2009-10-21 00:40:46 +0000469#define ABSTRACT_TYPELOC(CLASS, PARENT)
470#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000471 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000472#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000473
John McCall43fed0d2010-11-12 08:19:04 +0000474 QualType
475 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
476 TemplateSpecializationTypeLoc TL,
477 TemplateName Template);
478
479 QualType
480 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
481 DependentTemplateSpecializationTypeLoc TL,
482 NestedNameSpecifier *Prefix);
483
John McCall21ef0fa2010-03-11 09:03:00 +0000484 /// \brief Transforms the parameters of a function type into the
485 /// given vectors.
486 ///
487 /// The result vectors should be kept in sync; null entries in the
488 /// variables vector are acceptable.
489 ///
490 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000491 bool TransformFunctionTypeParams(SourceLocation Loc,
492 ParmVarDecl **Params, unsigned NumParams,
493 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000494 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000495 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000496
497 /// \brief Transforms a single function-type parameter. Return null
498 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000499 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
500 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000501
John McCall43fed0d2010-11-12 08:19:04 +0000502 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000503
John McCall60d7b3a2010-08-24 06:29:42 +0000504 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
505 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000506
Douglas Gregor43959a92009-08-20 07:17:43 +0000507#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000508 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000509#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000510 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000511#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000512#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000513
Douglas Gregor577f75a2009-08-04 16:50:30 +0000514 /// \brief Build a new pointer type given its pointee type.
515 ///
516 /// By default, performs semantic analysis when building the pointer type.
517 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000518 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000519
520 /// \brief Build a new block pointer type given its pointee type.
521 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000522 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000523 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000524 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000525
John McCall85737a72009-10-30 00:06:24 +0000526 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000527 ///
John McCall85737a72009-10-30 00:06:24 +0000528 /// By default, performs semantic analysis when building the
529 /// reference type. Subclasses may override this routine to provide
530 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 ///
John McCall85737a72009-10-30 00:06:24 +0000532 /// \param LValue whether the type was written with an lvalue sigil
533 /// or an rvalue sigil.
534 QualType RebuildReferenceType(QualType ReferentType,
535 bool LValue,
536 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Douglas Gregor577f75a2009-08-04 16:50:30 +0000538 /// \brief Build a new member pointer type given the pointee type and the
539 /// class type it refers into.
540 ///
541 /// By default, performs semantic analysis when building the member pointer
542 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000543 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
544 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000545
Douglas Gregor577f75a2009-08-04 16:50:30 +0000546 /// \brief Build a new array type given the element type, size
547 /// modifier, size of the array (if known), size expression, and index type
548 /// qualifiers.
549 ///
550 /// By default, performs semantic analysis when building the array type.
551 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000552 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553 QualType RebuildArrayType(QualType ElementType,
554 ArrayType::ArraySizeModifier SizeMod,
555 const llvm::APInt *Size,
556 Expr *SizeExpr,
557 unsigned IndexTypeQuals,
558 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000559
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 /// \brief Build a new constant array type given the element type, size
561 /// modifier, (known) size of the array, and index type qualifiers.
562 ///
563 /// By default, performs semantic analysis when building the array type.
564 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000565 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000566 ArrayType::ArraySizeModifier SizeMod,
567 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000568 unsigned IndexTypeQuals,
569 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new incomplete array type given the element type, size
572 /// modifier, and index type qualifiers.
573 ///
574 /// By default, performs semantic analysis when building the array type.
575 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000576 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000577 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000578 unsigned IndexTypeQuals,
579 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000580
Mike Stump1eb44332009-09-09 15:08:12 +0000581 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000582 /// size modifier, size expression, and index type qualifiers.
583 ///
584 /// By default, performs semantic analysis when building the array type.
585 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000586 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000588 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000589 unsigned IndexTypeQuals,
590 SourceRange BracketsRange);
591
Mike Stump1eb44332009-09-09 15:08:12 +0000592 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// size modifier, size expression, and index type qualifiers.
594 ///
595 /// By default, performs semantic analysis when building the array type.
596 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000597 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000599 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000600 unsigned IndexTypeQuals,
601 SourceRange BracketsRange);
602
603 /// \brief Build a new vector type given the element type and
604 /// number of elements.
605 ///
606 /// By default, performs semantic analysis when building the vector type.
607 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000608 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000609 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000610
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 /// \brief Build a new extended vector type given the element type and
612 /// number of elements.
613 ///
614 /// By default, performs semantic analysis when building the vector type.
615 /// Subclasses may override this routine to provide different behavior.
616 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
617 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000618
619 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 /// given the element type and number of elements.
621 ///
622 /// By default, performs semantic analysis when building the vector type.
623 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000624 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000625 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000627
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628 /// \brief Build a new function type.
629 ///
630 /// By default, performs semantic analysis when building the function type.
631 /// Subclasses may override this routine to provide different behavior.
632 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000633 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000635 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000636 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000637 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000638
John McCalla2becad2009-10-21 00:40:46 +0000639 /// \brief Build a new unprototyped function type.
640 QualType RebuildFunctionNoProtoType(QualType ResultType);
641
John McCalled976492009-12-04 22:46:56 +0000642 /// \brief Rebuild an unresolved typename type, given the decl that
643 /// the UnresolvedUsingTypenameDecl was transformed to.
644 QualType RebuildUnresolvedUsingType(Decl *D);
645
Douglas Gregor577f75a2009-08-04 16:50:30 +0000646 /// \brief Build a new typedef type.
647 QualType RebuildTypedefType(TypedefDecl *Typedef) {
648 return SemaRef.Context.getTypeDeclType(Typedef);
649 }
650
651 /// \brief Build a new class/struct/union type.
652 QualType RebuildRecordType(RecordDecl *Record) {
653 return SemaRef.Context.getTypeDeclType(Record);
654 }
655
656 /// \brief Build a new Enum type.
657 QualType RebuildEnumType(EnumDecl *Enum) {
658 return SemaRef.Context.getTypeDeclType(Enum);
659 }
John McCall7da24312009-09-05 00:15:47 +0000660
Mike Stump1eb44332009-09-09 15:08:12 +0000661 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 ///
663 /// By default, performs semantic analysis when building the typeof type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000665 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000666
Mike Stump1eb44332009-09-09 15:08:12 +0000667 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 ///
669 /// By default, builds a new TypeOfType with the given underlying type.
670 QualType RebuildTypeOfType(QualType Underlying);
671
Mike Stump1eb44332009-09-09 15:08:12 +0000672 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 ///
674 /// By default, performs semantic analysis when building the decltype type.
675 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000676 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000677
Douglas Gregor577f75a2009-08-04 16:50:30 +0000678 /// \brief Build a new template specialization type.
679 ///
680 /// By default, performs semantic analysis when building the template
681 /// specialization type. Subclasses may override this routine to provide
682 /// different behavior.
683 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000684 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000685 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000686
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000687 /// \brief Build a new parenthesized type.
688 ///
689 /// By default, builds a new ParenType type from the inner type.
690 /// Subclasses may override this routine to provide different behavior.
691 QualType RebuildParenType(QualType InnerType) {
692 return SemaRef.Context.getParenType(InnerType);
693 }
694
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 /// \brief Build a new qualified name type.
696 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000697 /// By default, builds a new ElaboratedType type from the keyword,
698 /// the nested-name-specifier and the named type.
699 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000700 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
701 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000702 NestedNameSpecifier *NNS, QualType Named) {
703 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000704 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000705
706 /// \brief Build a new typename type that refers to a template-id.
707 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000708 /// By default, builds a new DependentNameType type from the
709 /// nested-name-specifier and the given type. Subclasses may override
710 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000711 QualType RebuildDependentTemplateSpecializationType(
712 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000713 NestedNameSpecifier *Qualifier,
714 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000715 const IdentifierInfo *Name,
716 SourceLocation NameLoc,
717 const TemplateArgumentListInfo &Args) {
718 // Rebuild the template name.
719 // TODO: avoid TemplateName abstraction
720 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000721 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000722 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000723
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000724 if (InstName.isNull())
725 return QualType();
726
John McCall33500952010-06-11 00:33:02 +0000727 // If it's still dependent, make a dependent specialization.
728 if (InstName.getAsDependentTemplateName())
729 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000730 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000731
732 // Otherwise, make an elaborated type wrapping a non-dependent
733 // specialization.
734 QualType T =
735 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
736 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000737
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000738 // NOTE: NNS is already recorded in template specialization type T.
739 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000740 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000741
742 /// \brief Build a new typename type that refers to an identifier.
743 ///
744 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000745 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000746 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000747 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000748 NestedNameSpecifier *NNS,
749 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000750 SourceLocation KeywordLoc,
751 SourceRange NNSRange,
752 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000753 CXXScopeSpec SS;
754 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000755 SS.setRange(NNSRange);
756
Douglas Gregor40336422010-03-31 22:19:08 +0000757 if (NNS->isDependent()) {
758 // If the name is still dependent, just build a new dependent name type.
759 if (!SemaRef.computeDeclContext(SS))
760 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
761 }
762
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000763 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000764 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
765 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000766
767 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
768
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000769 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000770 // into a non-dependent elaborated-type-specifier. Find the tag we're
771 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000772 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000773 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
774 if (!DC)
775 return QualType();
776
John McCall56138762010-05-27 06:40:31 +0000777 if (SemaRef.RequireCompleteDeclContext(SS, DC))
778 return QualType();
779
Douglas Gregor40336422010-03-31 22:19:08 +0000780 TagDecl *Tag = 0;
781 SemaRef.LookupQualifiedName(Result, DC);
782 switch (Result.getResultKind()) {
783 case LookupResult::NotFound:
784 case LookupResult::NotFoundInCurrentInstantiation:
785 break;
Sean Huntc3021132010-05-05 15:23:54 +0000786
Douglas Gregor40336422010-03-31 22:19:08 +0000787 case LookupResult::Found:
788 Tag = Result.getAsSingle<TagDecl>();
789 break;
Sean Huntc3021132010-05-05 15:23:54 +0000790
Douglas Gregor40336422010-03-31 22:19:08 +0000791 case LookupResult::FoundOverloaded:
792 case LookupResult::FoundUnresolvedValue:
793 llvm_unreachable("Tag lookup cannot find non-tags");
794 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000795
Douglas Gregor40336422010-03-31 22:19:08 +0000796 case LookupResult::Ambiguous:
797 // Let the LookupResult structure handle ambiguities.
798 return QualType();
799 }
800
801 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000802 // Check where the name exists but isn't a tag type and use that to emit
803 // better diagnostics.
804 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
805 SemaRef.LookupQualifiedName(Result, DC);
806 switch (Result.getResultKind()) {
807 case LookupResult::Found:
808 case LookupResult::FoundOverloaded:
809 case LookupResult::FoundUnresolvedValue: {
810 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
811 unsigned Kind = 0;
812 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
813 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
814 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
815 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
816 break;
817 }
818 default:
819 // FIXME: Would be nice to highlight just the source range.
820 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
821 << Kind << Id << DC;
822 break;
823 }
Douglas Gregor40336422010-03-31 22:19:08 +0000824 return QualType();
825 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000826
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000827 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
828 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000829 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
830 return QualType();
831 }
832
833 // Build the elaborated-type-specifier type.
834 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000835 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000836 }
Mike Stump1eb44332009-09-09 15:08:12 +0000837
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000838 /// \brief Build a new pack expansion type.
839 ///
840 /// By default, builds a new PackExpansionType type from the given pattern.
841 /// Subclasses may override this routine to provide different behavior.
842 QualType RebuildPackExpansionType(QualType Pattern,
843 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000844 SourceLocation EllipsisLoc,
845 llvm::Optional<unsigned> NumExpansions) {
846 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
847 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000848 }
849
Douglas Gregordcee1a12009-08-06 05:28:30 +0000850 /// \brief Build a new nested-name-specifier given the prefix and an
851 /// identifier that names the next step in the nested-name-specifier.
852 ///
853 /// By default, performs semantic analysis when building the new
854 /// nested-name-specifier. Subclasses may override this routine to provide
855 /// different behavior.
856 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
857 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000858 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000859 QualType ObjectType,
860 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000861
862 /// \brief Build a new nested-name-specifier given the prefix and the
863 /// namespace named in the next step in the nested-name-specifier.
864 ///
865 /// By default, performs semantic analysis when building the new
866 /// nested-name-specifier. Subclasses may override this routine to provide
867 /// different behavior.
868 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
869 SourceRange Range,
870 NamespaceDecl *NS);
871
872 /// \brief Build a new nested-name-specifier given the prefix and the
873 /// type named in the next step in the nested-name-specifier.
874 ///
875 /// By default, performs semantic analysis when building the new
876 /// nested-name-specifier. Subclasses may override this routine to provide
877 /// different behavior.
878 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
879 SourceRange Range,
880 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000881 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000882
883 /// \brief Build a new template name given a nested name specifier, a flag
884 /// indicating whether the "template" keyword was provided, and the template
885 /// that the template name refers to.
886 ///
887 /// By default, builds the new template name directly. Subclasses may override
888 /// this routine to provide different behavior.
889 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
890 bool TemplateKW,
891 TemplateDecl *Template);
892
Douglas Gregord1067e52009-08-06 06:41:21 +0000893 /// \brief Build a new template name given a nested name specifier and the
894 /// name that is referred to as a template.
895 ///
896 /// By default, performs semantic analysis to determine whether the name can
897 /// be resolved to a specific template, then builds the appropriate kind of
898 /// template name. Subclasses may override this routine to provide different
899 /// behavior.
900 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000901 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000902 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000903 QualType ObjectType,
904 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000905
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000906 /// \brief Build a new template name given a nested name specifier and the
907 /// overloaded operator name that is referred to as a template.
908 ///
909 /// By default, performs semantic analysis to determine whether the name can
910 /// be resolved to a specific template, then builds the appropriate kind of
911 /// template name. Subclasses may override this routine to provide different
912 /// behavior.
913 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
914 OverloadedOperatorKind Operator,
915 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000916
917 /// \brief Build a new template name given a template template parameter pack
918 /// and the
919 ///
920 /// By default, performs semantic analysis to determine whether the name can
921 /// be resolved to a specific template, then builds the appropriate kind of
922 /// template name. Subclasses may override this routine to provide different
923 /// behavior.
924 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
925 const TemplateArgument &ArgPack) {
926 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
927 }
928
Douglas Gregor43959a92009-08-20 07:17:43 +0000929 /// \brief Build a new compound statement.
930 ///
931 /// By default, performs semantic analysis to build the new statement.
932 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000933 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000934 MultiStmtArg Statements,
935 SourceLocation RBraceLoc,
936 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000937 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000938 IsStmtExpr);
939 }
940
941 /// \brief Build a new case statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000945 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000946 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000947 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000948 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000949 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000950 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000951 ColonLoc);
952 }
Mike Stump1eb44332009-09-09 15:08:12 +0000953
Douglas Gregor43959a92009-08-20 07:17:43 +0000954 /// \brief Attach the body to a new case statement.
955 ///
956 /// By default, performs semantic analysis to build the new statement.
957 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000958 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000959 getSema().ActOnCaseStmtBody(S, Body);
960 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000961 }
Mike Stump1eb44332009-09-09 15:08:12 +0000962
Douglas Gregor43959a92009-08-20 07:17:43 +0000963 /// \brief Build a new default statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000967 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000968 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000969 Stmt *SubStmt) {
970 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000971 /*CurScope=*/0);
972 }
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregor43959a92009-08-20 07:17:43 +0000974 /// \brief Build a new label statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000978 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, IdentifierInfo *Id,
979 SourceLocation ColonLoc, Stmt *SubStmt,
980 bool HasUnusedAttr) {
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000981 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
982 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 }
Mike Stump1eb44332009-09-09 15:08:12 +0000984
Douglas Gregor43959a92009-08-20 07:17:43 +0000985 /// \brief Build a new "if" statement.
986 ///
987 /// By default, performs semantic analysis to build the new statement.
988 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000989 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000990 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000991 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000992 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 }
Mike Stump1eb44332009-09-09 15:08:12 +0000994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Start building a new switch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001000 Expr *Cond, VarDecl *CondVar) {
1001 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001002 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 }
Mike Stump1eb44332009-09-09 15:08:12 +00001004
Douglas Gregor43959a92009-08-20 07:17:43 +00001005 /// \brief Attach the body to the switch statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001009 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001010 Stmt *Switch, Stmt *Body) {
1011 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 }
1013
1014 /// \brief Build a new while statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001018 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00001019 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001020 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +00001021 Stmt *Body) {
1022 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 /// \brief Build a new do-while statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001029 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001030 SourceLocation WhileLoc, SourceLocation LParenLoc,
1031 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001032 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1033 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 }
1035
1036 /// \brief Build a new for statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001040 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1041 Stmt *Init, Sema::FullExprArg Cond,
1042 VarDecl *CondVar, Sema::FullExprArg Inc,
1043 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001044 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001045 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 }
Mike Stump1eb44332009-09-09 15:08:12 +00001047
Douglas Gregor43959a92009-08-20 07:17:43 +00001048 /// \brief Build a new goto statement.
1049 ///
1050 /// By default, performs semantic analysis to build the new statement.
1051 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001052 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1053 LabelDecl *Label) {
1054 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getIdentifier());
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 }
1056
1057 /// \brief Build a new indirect goto statement.
1058 ///
1059 /// By default, performs semantic analysis to build the new statement.
1060 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001061 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001062 SourceLocation StarLoc,
1063 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001064 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 }
Mike Stump1eb44332009-09-09 15:08:12 +00001066
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 /// \brief Build a new return statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001071 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001072 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new declaration statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001080 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 SourceLocation EndLoc) {
1082 return getSema().Owned(
1083 new (getSema().Context) DeclStmt(
1084 DeclGroupRef::Create(getSema().Context,
1085 Decls, NumDecls),
1086 StartLoc, EndLoc));
1087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Anders Carlsson703e3942010-01-24 05:50:09 +00001089 /// \brief Build a new inline asm statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001093 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001094 bool IsSimple,
1095 bool IsVolatile,
1096 unsigned NumOutputs,
1097 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001098 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001099 MultiExprArg Constraints,
1100 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001101 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001102 MultiExprArg Clobbers,
1103 SourceLocation RParenLoc,
1104 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001105 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001106 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001107 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001108 RParenLoc, MSAsm);
1109 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001110
1111 /// \brief Build a new Objective-C @try statement.
1112 ///
1113 /// By default, performs semantic analysis to build the new statement.
1114 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001115 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001116 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001117 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001118 Stmt *Finally) {
1119 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1120 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001121 }
1122
Douglas Gregorbe270a02010-04-26 17:57:08 +00001123 /// \brief Rebuild an Objective-C exception declaration.
1124 ///
1125 /// By default, performs semantic analysis to build the new declaration.
1126 /// Subclasses may override this routine to provide different behavior.
1127 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1128 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001129 return getSema().BuildObjCExceptionDecl(TInfo, T,
1130 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001131 ExceptionDecl->getLocation());
1132 }
Sean Huntc3021132010-05-05 15:23:54 +00001133
Douglas Gregorbe270a02010-04-26 17:57:08 +00001134 /// \brief Build a new Objective-C @catch statement.
1135 ///
1136 /// By default, performs semantic analysis to build the new statement.
1137 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001138 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001139 SourceLocation RParenLoc,
1140 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001141 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001142 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001144 }
Sean Huntc3021132010-05-05 15:23:54 +00001145
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001146 /// \brief Build a new Objective-C @finally statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001150 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001151 Stmt *Body) {
1152 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001153 }
Sean Huntc3021132010-05-05 15:23:54 +00001154
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001155 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001159 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001160 Expr *Operand) {
1161 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001162 }
Sean Huntc3021132010-05-05 15:23:54 +00001163
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001164 /// \brief Build a new Objective-C @synchronized statement.
1165 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001168 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Expr *Object,
1170 Stmt *Body) {
1171 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1172 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001173 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001174
1175 /// \brief Build a new Objective-C fast enumeration statement.
1176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001179 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001180 SourceLocation LParenLoc,
1181 Stmt *Element,
1182 Expr *Collection,
1183 SourceLocation RParenLoc,
1184 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001185 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001186 Element,
1187 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001188 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001189 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001190 }
Sean Huntc3021132010-05-05 15:23:54 +00001191
Douglas Gregor43959a92009-08-20 07:17:43 +00001192 /// \brief Build a new C++ exception declaration.
1193 ///
1194 /// By default, performs semantic analysis to build the new decaration.
1195 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001196 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001197 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001198 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001199 SourceLocation Loc) {
1200 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001201 }
1202
1203 /// \brief Build a new C++ catch statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001207 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001208 VarDecl *ExceptionDecl,
1209 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001210 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1211 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001212 }
Mike Stump1eb44332009-09-09 15:08:12 +00001213
Douglas Gregor43959a92009-08-20 07:17:43 +00001214 /// \brief Build a new C++ try statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001218 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001219 Stmt *TryBlock,
1220 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001221 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001222 }
Mike Stump1eb44332009-09-09 15:08:12 +00001223
Douglas Gregorb98b1992009-08-11 05:31:07 +00001224 /// \brief Build a new expression that references a declaration.
1225 ///
1226 /// By default, performs semantic analysis to build the new expression.
1227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001228 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001229 LookupResult &R,
1230 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001231 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1232 }
1233
1234
1235 /// \brief Build a new expression that references a declaration.
1236 ///
1237 /// By default, performs semantic analysis to build the new expression.
1238 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001239 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001240 SourceRange QualifierRange,
1241 ValueDecl *VD,
1242 const DeclarationNameInfo &NameInfo,
1243 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001244 CXXScopeSpec SS;
1245 SS.setScopeRep(Qualifier);
1246 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001247
1248 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001249
1250 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001251 }
Mike Stump1eb44332009-09-09 15:08:12 +00001252
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001254 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001257 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001259 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001260 }
1261
Douglas Gregora71d8192009-09-04 17:36:40 +00001262 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001263 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001264 /// By default, performs semantic analysis to build the new expression.
1265 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001266 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001267 SourceLocation OperatorLoc,
1268 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001269 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001270 SourceRange QualifierRange,
1271 TypeSourceInfo *ScopeType,
1272 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001273 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001274 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001275
Douglas Gregorb98b1992009-08-11 05:31:07 +00001276 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001277 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 /// By default, performs semantic analysis to build the new expression.
1279 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001280 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001281 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001282 Expr *SubExpr) {
1283 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 }
Mike Stump1eb44332009-09-09 15:08:12 +00001285
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001286 /// \brief Build a new builtin offsetof expression.
1287 ///
1288 /// By default, performs semantic analysis to build the new expression.
1289 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001290 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001291 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001292 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001293 unsigned NumComponents,
1294 SourceLocation RParenLoc) {
1295 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1296 NumComponents, RParenLoc);
1297 }
Sean Huntc3021132010-05-05 15:23:54 +00001298
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001300 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001303 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001304 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001305 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001306 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 }
1308
Mike Stump1eb44332009-09-09 15:08:12 +00001309 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001311 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001316 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001317 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001319 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001320
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 return move(Result);
1322 }
Mike Stump1eb44332009-09-09 15:08:12 +00001323
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001325 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 /// By default, performs semantic analysis to build the new expression.
1327 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001328 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001330 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001332 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1333 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 RBracketLoc);
1335 }
1336
1337 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001338 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001341 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001343 SourceLocation RParenLoc,
1344 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001345 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001346 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 }
1348
1349 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001350 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001353 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001354 bool isArrow,
1355 NestedNameSpecifier *Qualifier,
1356 SourceRange QualifierRange,
1357 const DeclarationNameInfo &MemberNameInfo,
1358 ValueDecl *Member,
1359 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001360 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001361 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001362 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001363 // We have a reference to an unnamed field. This is always the
1364 // base of an anonymous struct/union member access, i.e. the
1365 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001366 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001367 assert(Member->getType()->isRecordType() &&
1368 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001369
John McCall9ae2f072010-08-23 23:25:46 +00001370 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001371 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001372 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001373
John McCallf89e55a2010-11-18 06:31:45 +00001374 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001375 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001376 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001377 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001378 cast<FieldDecl>(Member)->getType(),
1379 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001380 return getSema().Owned(ME);
1381 }
Mike Stump1eb44332009-09-09 15:08:12 +00001382
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001383 CXXScopeSpec SS;
1384 if (Qualifier) {
1385 SS.setRange(QualifierRange);
1386 SS.setScopeRep(Qualifier);
1387 }
1388
John McCall9ae2f072010-08-23 23:25:46 +00001389 getSema().DefaultFunctionArrayConversion(Base);
1390 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001391
John McCall6bb80172010-03-30 21:47:33 +00001392 // FIXME: this involves duplicating earlier analysis in a lot of
1393 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001394 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001395 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001396 R.resolveKind();
1397
John McCall9ae2f072010-08-23 23:25:46 +00001398 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001399 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001400 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 }
Mike Stump1eb44332009-09-09 15:08:12 +00001402
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001404 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001407 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001408 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001409 Expr *LHS, Expr *RHS) {
1410 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 }
1412
1413 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001414 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001417 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001419 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001420 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001421 Expr *RHS) {
1422 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1423 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 }
1425
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001427 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001430 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001431 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001432 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001433 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001434 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001435 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 }
Mike Stump1eb44332009-09-09 15:08:12 +00001437
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001439 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001442 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001443 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001445 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001446 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001447 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 }
Mike Stump1eb44332009-09-09 15:08:12 +00001449
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001451 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 /// By default, performs semantic analysis to build the new expression.
1453 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001454 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 SourceLocation OpLoc,
1456 SourceLocation AccessorLoc,
1457 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001458
John McCall129e2df2009-11-30 22:42:35 +00001459 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001460 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001461 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001462 OpLoc, /*IsArrow*/ false,
1463 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001464 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001465 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 }
Mike Stump1eb44332009-09-09 15:08:12 +00001467
Douglas Gregorb98b1992009-08-11 05:31:07 +00001468 /// \brief Build a new initializer list expression.
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.
John McCall60d7b3a2010-08-24 06:29:42 +00001472 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001474 SourceLocation RBraceLoc,
1475 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001477 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1478 if (Result.isInvalid() || ResultTy->isDependentType())
1479 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001480
Douglas Gregore48319a2009-11-09 17:16:50 +00001481 // Patch in the result type we were given, which may have been computed
1482 // when the initial InitListExpr was built.
1483 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1484 ILE->setType(ResultTy);
1485 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 }
Mike Stump1eb44332009-09-09 15:08:12 +00001487
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001489 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 /// By default, performs semantic analysis to build the new expression.
1491 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001492 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 MultiExprArg ArrayExprs,
1494 SourceLocation EqualOrColonLoc,
1495 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001496 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001499 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001502
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 ArrayExprs.release();
1504 return move(Result);
1505 }
Mike Stump1eb44332009-09-09 15:08:12 +00001506
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001508 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 /// By default, builds the implicit value initialization without performing
1510 /// any semantic analysis. Subclasses may override this routine to provide
1511 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001512 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1514 }
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001517 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001520 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001521 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001522 SourceLocation RParenLoc) {
1523 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001524 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001525 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 }
1527
1528 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001529 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001532 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 MultiExprArg SubExprs,
1534 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001535 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001536 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 }
Mike Stump1eb44332009-09-09 15:08:12 +00001538
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001540 ///
1541 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 /// rather than attempting to map the label statement itself.
1543 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001544 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001545 SourceLocation LabelLoc, LabelDecl *Label) {
1546 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc,Label->getIdentifier());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 }
Mike Stump1eb44332009-09-09 15:08:12 +00001548
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001554 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001556 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 }
Mike Stump1eb44332009-09-09 15:08:12 +00001558
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// \brief Build a new __builtin_choose_expr expression.
1560 ///
1561 /// By default, performs semantic analysis to build the new expression.
1562 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001563 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001564 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 SourceLocation RParenLoc) {
1566 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001567 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 RParenLoc);
1569 }
Mike Stump1eb44332009-09-09 15:08:12 +00001570
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 /// \brief Build a new overloaded operator call expression.
1572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// The semantic analysis provides the behavior of template instantiation,
1575 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001576 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// argument-dependent lookup, etc. Subclasses may override this routine to
1578 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001581 Expr *Callee,
1582 Expr *First,
1583 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001584
1585 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// reinterpret_cast.
1587 ///
1588 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001589 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001591 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 Stmt::StmtClass Class,
1593 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001594 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 SourceLocation RAngleLoc,
1596 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001597 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 SourceLocation RParenLoc) {
1599 switch (Class) {
1600 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001601 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001602 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001603 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604
1605 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001606 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001607 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001608 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001609
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001611 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001612 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001613 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001615
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001617 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001618 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001619 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001620
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 default:
1622 assert(false && "Invalid C++ named cast");
1623 break;
1624 }
Mike Stump1eb44332009-09-09 15:08:12 +00001625
John McCallf312b1e2010-08-26 23:41:50 +00001626 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 }
Mike Stump1eb44332009-09-09 15:08:12 +00001628
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// \brief Build a new C++ static_cast expression.
1630 ///
1631 /// By default, performs semantic analysis to build the new expression.
1632 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001633 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001635 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 SourceLocation RAngleLoc,
1637 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001638 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001640 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001641 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001642 SourceRange(LAngleLoc, RAngleLoc),
1643 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 }
1645
1646 /// \brief Build a new C++ dynamic_cast expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001650 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001652 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 SourceLocation RAngleLoc,
1654 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001655 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001657 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001658 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001659 SourceRange(LAngleLoc, RAngleLoc),
1660 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 }
1662
1663 /// \brief Build a new C++ reinterpret_cast expression.
1664 ///
1665 /// By default, performs semantic analysis to build the new expression.
1666 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001667 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001669 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 SourceLocation RAngleLoc,
1671 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001672 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001674 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001675 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001676 SourceRange(LAngleLoc, RAngleLoc),
1677 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 }
1679
1680 /// \brief Build a new C++ const_cast expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001686 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 SourceLocation RAngleLoc,
1688 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001691 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001692 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001693 SourceRange(LAngleLoc, RAngleLoc),
1694 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 }
Mike Stump1eb44332009-09-09 15:08:12 +00001696
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// \brief Build a new C++ functional-style cast expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001701 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1702 SourceLocation LParenLoc,
1703 Expr *Sub,
1704 SourceLocation RParenLoc) {
1705 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001706 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 RParenLoc);
1708 }
Mike Stump1eb44332009-09-09 15:08:12 +00001709
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// \brief Build a new C++ typeid(type) expression.
1711 ///
1712 /// 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 RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001715 SourceLocation TypeidLoc,
1716 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001718 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001719 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Francois Pichet01b7c302010-09-08 12:20:18 +00001722
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 /// \brief Build a new C++ typeid(expr) expression.
1724 ///
1725 /// By default, performs semantic analysis to build the new expression.
1726 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001727 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001728 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001729 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001731 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001732 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001733 }
1734
Francois Pichet01b7c302010-09-08 12:20:18 +00001735 /// \brief Build a new C++ __uuidof(type) expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
1739 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1740 SourceLocation TypeidLoc,
1741 TypeSourceInfo *Operand,
1742 SourceLocation RParenLoc) {
1743 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1744 RParenLoc);
1745 }
1746
1747 /// \brief Build a new C++ __uuidof(expr) expression.
1748 ///
1749 /// By default, performs semantic analysis to build the new expression.
1750 /// Subclasses may override this routine to provide different behavior.
1751 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1752 SourceLocation TypeidLoc,
1753 Expr *Operand,
1754 SourceLocation RParenLoc) {
1755 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1756 RParenLoc);
1757 }
1758
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// \brief Build a new C++ "this" expression.
1760 ///
1761 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001762 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001765 QualType ThisType,
1766 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001768 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1769 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 }
1771
1772 /// \brief Build a new C++ throw expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001777 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 }
1779
1780 /// \brief Build a new C++ default-argument expression.
1781 ///
1782 /// By default, builds a new default-argument expression, which does not
1783 /// require any semantic analysis. Subclasses may override this routine to
1784 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001785 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001786 ParmVarDecl *Param) {
1787 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1788 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 }
1790
1791 /// \brief Build a new C++ zero-initialization expression.
1792 ///
1793 /// By default, performs semantic analysis to build the new expression.
1794 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001795 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1796 SourceLocation LParenLoc,
1797 SourceLocation RParenLoc) {
1798 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001799 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001800 RParenLoc);
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++ "new" 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 RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001808 bool UseGlobal,
1809 SourceLocation PlacementLParen,
1810 MultiExprArg PlacementArgs,
1811 SourceLocation PlacementRParen,
1812 SourceRange TypeIdParens,
1813 QualType AllocatedType,
1814 TypeSourceInfo *AllocatedTypeInfo,
1815 Expr *ArraySize,
1816 SourceLocation ConstructorLParen,
1817 MultiExprArg ConstructorArgs,
1818 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001819 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 PlacementLParen,
1821 move(PlacementArgs),
1822 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001823 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001824 AllocatedType,
1825 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001826 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 ConstructorLParen,
1828 move(ConstructorArgs),
1829 ConstructorRParen);
1830 }
Mike Stump1eb44332009-09-09 15:08:12 +00001831
Douglas Gregorb98b1992009-08-11 05:31:07 +00001832 /// \brief Build a new C++ "delete" expression.
1833 ///
1834 /// By default, performs semantic analysis to build the new expression.
1835 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 bool IsGlobalDelete,
1838 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001839 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001841 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 }
Mike Stump1eb44332009-09-09 15:08:12 +00001843
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 /// \brief Build a new unary type trait expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001848 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001849 SourceLocation StartLoc,
1850 TypeSourceInfo *T,
1851 SourceLocation RParenLoc) {
1852 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
1854
Francois Pichet6ad6f282010-12-07 00:08:36 +00001855 /// \brief Build a new binary type trait expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
1859 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1860 SourceLocation StartLoc,
1861 TypeSourceInfo *LhsT,
1862 TypeSourceInfo *RhsT,
1863 SourceLocation RParenLoc) {
1864 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1865 }
1866
Mike Stump1eb44332009-09-09 15:08:12 +00001867 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001868 /// expression.
1869 ///
1870 /// By default, performs semantic analysis to build the new expression.
1871 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001872 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001874 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001875 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 CXXScopeSpec SS;
1877 SS.setRange(QualifierRange);
1878 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001879
1880 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001881 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001882 *TemplateArgs);
1883
Abramo Bagnara25777432010-08-11 22:01:17 +00001884 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 }
1886
1887 /// \brief Build a new template-id expression.
1888 ///
1889 /// By default, performs semantic analysis to build the new expression.
1890 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001891 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001892 LookupResult &R,
1893 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001894 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001895 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 }
1897
1898 /// \brief Build a new object-construction expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001902 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001903 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 CXXConstructorDecl *Constructor,
1905 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001906 MultiExprArg Args,
1907 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001908 CXXConstructExpr::ConstructionKind ConstructKind,
1909 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001910 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001911 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001912 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001913 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001914
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001915 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001916 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001917 RequiresZeroInit, ConstructKind,
1918 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 }
1920
1921 /// \brief Build a new object-construction expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001925 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1926 SourceLocation LParenLoc,
1927 MultiExprArg Args,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 LParenLoc,
1931 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 RParenLoc);
1933 }
1934
1935 /// \brief Build a new object-construction expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001939 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1940 SourceLocation LParenLoc,
1941 MultiExprArg Args,
1942 SourceLocation RParenLoc) {
1943 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001944 LParenLoc,
1945 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 RParenLoc);
1947 }
Mike Stump1eb44332009-09-09 15:08:12 +00001948
Douglas Gregorb98b1992009-08-11 05:31:07 +00001949 /// \brief Build a new member reference expression.
1950 ///
1951 /// By default, performs semantic analysis to build the new expression.
1952 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001953 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001954 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 bool IsArrow,
1956 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001957 NestedNameSpecifier *Qualifier,
1958 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001959 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001960 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001961 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001963 SS.setRange(QualifierRange);
1964 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001965
John McCall9ae2f072010-08-23 23:25:46 +00001966 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001967 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001968 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001969 MemberNameInfo,
1970 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 }
1972
John McCall129e2df2009-11-30 22:42:35 +00001973 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001977 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001978 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001979 SourceLocation OperatorLoc,
1980 bool IsArrow,
1981 NestedNameSpecifier *Qualifier,
1982 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001983 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001984 LookupResult &R,
1985 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001986 CXXScopeSpec SS;
1987 SS.setRange(QualifierRange);
1988 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001989
John McCall9ae2f072010-08-23 23:25:46 +00001990 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001991 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001992 SS, FirstQualifierInScope,
1993 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001994 }
Mike Stump1eb44332009-09-09 15:08:12 +00001995
Sebastian Redl2e156222010-09-10 20:55:43 +00001996 /// \brief Build a new noexcept expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
2000 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2001 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2002 }
2003
Douglas Gregoree8aff02011-01-04 17:33:58 +00002004 /// \brief Build a new expression to compute the length of a parameter pack.
2005 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2006 SourceLocation PackLoc,
2007 SourceLocation RParenLoc,
2008 unsigned Length) {
2009 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2010 OperatorLoc, Pack, PackLoc,
2011 RParenLoc, Length);
2012 }
2013
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 /// \brief Build a new Objective-C @encode expression.
2015 ///
2016 /// By default, performs semantic analysis to build the new expression.
2017 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002018 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002019 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002020 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002021 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002023 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024
Douglas Gregor92e986e2010-04-22 16:44:27 +00002025 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002026 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002027 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002028 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002029 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002030 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002031 MultiExprArg Args,
2032 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002033 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2034 ReceiverTypeInfo->getType(),
2035 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002036 Sel, Method, LBracLoc, SelectorLoc,
2037 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002038 }
2039
2040 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002041 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002042 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002043 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002044 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002045 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002046 MultiExprArg Args,
2047 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002048 return SemaRef.BuildInstanceMessage(Receiver,
2049 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002050 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002051 Sel, Method, LBracLoc, SelectorLoc,
2052 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002053 }
2054
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002055 /// \brief Build a new Objective-C ivar reference expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002059 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002060 SourceLocation IvarLoc,
2061 bool IsArrow, bool IsFreeIvar) {
2062 // FIXME: We lose track of the IsFreeIvar bit.
2063 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002064 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002065 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2066 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002067 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002068 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002069 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002070 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002071 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002072 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002073
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002074 if (Result.get())
2075 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002076
John McCall9ae2f072010-08-23 23:25:46 +00002077 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002078 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002079 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002080 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002081 /*TemplateArgs=*/0);
2082 }
Douglas Gregore3303542010-04-26 20:47:02 +00002083
2084 /// \brief Build a new Objective-C property reference expression.
2085 ///
2086 /// By default, performs semantic analysis to build the new expression.
2087 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002088 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002089 ObjCPropertyDecl *Property,
2090 SourceLocation PropertyLoc) {
2091 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002092 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002093 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2094 Sema::LookupMemberName);
2095 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002097 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002098 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002099 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002100 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002101
Douglas Gregore3303542010-04-26 20:47:02 +00002102 if (Result.get())
2103 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002104
John McCall9ae2f072010-08-23 23:25:46 +00002105 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002106 /*FIXME:*/PropertyLoc, IsArrow,
2107 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002108 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002109 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002110 /*TemplateArgs=*/0);
2111 }
Sean Huntc3021132010-05-05 15:23:54 +00002112
John McCall12f78a62010-12-02 01:19:52 +00002113 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002114 ///
2115 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002116 /// Subclasses may override this routine to provide different behavior.
2117 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2118 ObjCMethodDecl *Getter,
2119 ObjCMethodDecl *Setter,
2120 SourceLocation PropertyLoc) {
2121 // Since these expressions can only be value-dependent, we do not
2122 // need to perform semantic analysis again.
2123 return Owned(
2124 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2125 VK_LValue, OK_ObjCProperty,
2126 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002127 }
2128
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002129 /// \brief Build a new Objective-C "isa" expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002133 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002134 bool IsArrow) {
2135 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002136 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002137 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2138 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002139 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002140 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002141 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002142 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002143 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002144
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002145 if (Result.get())
2146 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002147
John McCall9ae2f072010-08-23 23:25:46 +00002148 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002149 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002150 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002151 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002152 /*TemplateArgs=*/0);
2153 }
Sean Huntc3021132010-05-05 15:23:54 +00002154
Douglas Gregorb98b1992009-08-11 05:31:07 +00002155 /// \brief Build a new shuffle vector expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002159 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002160 MultiExprArg SubExprs,
2161 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002162 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002163 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2165 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2166 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2167 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregorb98b1992009-08-11 05:31:07 +00002169 // Build a reference to the __builtin_shufflevector builtin
2170 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002171 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002173 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002175
2176 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 unsigned NumSubExprs = SubExprs.size();
2178 Expr **Subs = (Expr **)SubExprs.release();
2179 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2180 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002181 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002182 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002184 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002185
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002187 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002189 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002192 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002193 }
John McCall43fed0d2010-11-12 08:19:04 +00002194
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002195 /// \brief Build a new template argument pack expansion.
2196 ///
2197 /// By default, performs semantic analysis to build a new pack expansion
2198 /// for a template argument. Subclasses may override this routine to provide
2199 /// different behavior.
2200 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002201 SourceLocation EllipsisLoc,
2202 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002203 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002204 case TemplateArgument::Expression: {
2205 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002206 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2207 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002208 if (Result.isInvalid())
2209 return TemplateArgumentLoc();
2210
2211 return TemplateArgumentLoc(Result.get(), Result.get());
2212 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002213
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002214 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002215 return TemplateArgumentLoc(TemplateArgument(
2216 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002217 NumExpansions),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002218 Pattern.getTemplateQualifierRange(),
2219 Pattern.getTemplateNameLoc(),
2220 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002221
2222 case TemplateArgument::Null:
2223 case TemplateArgument::Integral:
2224 case TemplateArgument::Declaration:
2225 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002226 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002227 llvm_unreachable("Pack expansion pattern has no parameter packs");
2228
2229 case TemplateArgument::Type:
2230 if (TypeSourceInfo *Expansion
2231 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002232 EllipsisLoc,
2233 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002234 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2235 Expansion);
2236 break;
2237 }
2238
2239 return TemplateArgumentLoc();
2240 }
2241
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002242 /// \brief Build a new expression pack expansion.
2243 ///
2244 /// By default, performs semantic analysis to build a new pack expansion
2245 /// for an expression. Subclasses may override this routine to provide
2246 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002247 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2248 llvm::Optional<unsigned> NumExpansions) {
2249 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002250 }
2251
John McCall43fed0d2010-11-12 08:19:04 +00002252private:
2253 QualType TransformTypeInObjectScope(QualType T,
2254 QualType ObjectType,
2255 NamedDecl *FirstQualifierInScope,
2256 NestedNameSpecifier *Prefix);
2257
2258 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2259 QualType ObjectType,
2260 NamedDecl *FirstQualifierInScope,
2261 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002262};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002263
Douglas Gregor43959a92009-08-20 07:17:43 +00002264template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002265StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002266 if (!S)
2267 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002268
Douglas Gregor43959a92009-08-20 07:17:43 +00002269 switch (S->getStmtClass()) {
2270 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002271
Douglas Gregor43959a92009-08-20 07:17:43 +00002272 // Transform individual statement nodes
2273#define STMT(Node, Parent) \
2274 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002275#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002276#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002277#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002278
Douglas Gregor43959a92009-08-20 07:17:43 +00002279 // Transform expressions by calling TransformExpr.
2280#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002281#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002282#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002283#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002284 {
John McCall60d7b3a2010-08-24 06:29:42 +00002285 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002286 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002287 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002288
John McCall9ae2f072010-08-23 23:25:46 +00002289 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002290 }
Mike Stump1eb44332009-09-09 15:08:12 +00002291 }
2292
John McCall3fa5cae2010-10-26 07:05:15 +00002293 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002294}
Mike Stump1eb44332009-09-09 15:08:12 +00002295
2296
Douglas Gregor670444e2009-08-04 22:27:00 +00002297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002298ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002299 if (!E)
2300 return SemaRef.Owned(E);
2301
2302 switch (E->getStmtClass()) {
2303 case Stmt::NoStmtClass: break;
2304#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002305#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002306#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002307 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002308#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002309 }
2310
John McCall3fa5cae2010-10-26 07:05:15 +00002311 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002312}
2313
2314template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002315bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2316 unsigned NumInputs,
2317 bool IsCall,
2318 llvm::SmallVectorImpl<Expr *> &Outputs,
2319 bool *ArgChanged) {
2320 for (unsigned I = 0; I != NumInputs; ++I) {
2321 // If requested, drop call arguments that need to be dropped.
2322 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2323 if (ArgChanged)
2324 *ArgChanged = true;
2325
2326 break;
2327 }
2328
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002329 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2330 Expr *Pattern = Expansion->getPattern();
2331
2332 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2333 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2334 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2335
2336 // Determine whether the set of unexpanded parameter packs can and should
2337 // be expanded.
2338 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002339 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002340 llvm::Optional<unsigned> OrigNumExpansions
2341 = Expansion->getNumExpansions();
2342 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002343 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2344 Pattern->getSourceRange(),
2345 Unexpanded.data(),
2346 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002347 Expand, RetainExpansion,
2348 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002349 return true;
2350
2351 if (!Expand) {
2352 // The transform has determined that we should perform a simple
2353 // transformation on the pack expansion, producing another pack
2354 // expansion.
2355 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2356 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2357 if (OutPattern.isInvalid())
2358 return true;
2359
2360 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002361 Expansion->getEllipsisLoc(),
2362 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002363 if (Out.isInvalid())
2364 return true;
2365
2366 if (ArgChanged)
2367 *ArgChanged = true;
2368 Outputs.push_back(Out.get());
2369 continue;
2370 }
2371
2372 // The transform has determined that we should perform an elementwise
2373 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002374 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2376 ExprResult Out = getDerived().TransformExpr(Pattern);
2377 if (Out.isInvalid())
2378 return true;
2379
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002380 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002381 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2382 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002383 if (Out.isInvalid())
2384 return true;
2385 }
2386
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002387 if (ArgChanged)
2388 *ArgChanged = true;
2389 Outputs.push_back(Out.get());
2390 }
2391
2392 continue;
2393 }
2394
Douglas Gregoraa165f82011-01-03 19:04:46 +00002395 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2396 if (Result.isInvalid())
2397 return true;
2398
2399 if (Result.get() != Inputs[I] && ArgChanged)
2400 *ArgChanged = true;
2401
2402 Outputs.push_back(Result.get());
2403 }
2404
2405 return false;
2406}
2407
2408template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002409NestedNameSpecifier *
2410TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002411 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002412 QualType ObjectType,
2413 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002414 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002415
Douglas Gregor43959a92009-08-20 07:17:43 +00002416 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002417 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002418 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002419 ObjectType,
2420 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002421 if (!Prefix)
2422 return 0;
2423 }
Mike Stump1eb44332009-09-09 15:08:12 +00002424
Douglas Gregordcee1a12009-08-06 05:28:30 +00002425 switch (NNS->getKind()) {
2426 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002427 if (Prefix) {
2428 // The object type and qualifier-in-scope really apply to the
2429 // leftmost entity.
2430 ObjectType = QualType();
2431 FirstQualifierInScope = 0;
2432 }
2433
Mike Stump1eb44332009-09-09 15:08:12 +00002434 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002435 "Identifier nested-name-specifier with no prefix or object type");
2436 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2437 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002438 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002439
2440 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002441 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002442 ObjectType,
2443 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002444
Douglas Gregordcee1a12009-08-06 05:28:30 +00002445 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002446 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002447 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002448 getDerived().TransformDecl(Range.getBegin(),
2449 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002450 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002451 Prefix == NNS->getPrefix() &&
2452 NS == NNS->getAsNamespace())
2453 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002454
Douglas Gregordcee1a12009-08-06 05:28:30 +00002455 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2456 }
Mike Stump1eb44332009-09-09 15:08:12 +00002457
Douglas Gregordcee1a12009-08-06 05:28:30 +00002458 case NestedNameSpecifier::Global:
2459 // There is no meaningful transformation that one could perform on the
2460 // global scope.
2461 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002462
Douglas Gregordcee1a12009-08-06 05:28:30 +00002463 case NestedNameSpecifier::TypeSpecWithTemplate:
2464 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002465 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002466 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2467 ObjectType,
2468 FirstQualifierInScope,
2469 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002470 if (T.isNull())
2471 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002472
Douglas Gregordcee1a12009-08-06 05:28:30 +00002473 if (!getDerived().AlwaysRebuild() &&
2474 Prefix == NNS->getPrefix() &&
2475 T == QualType(NNS->getAsType(), 0))
2476 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002477
2478 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2479 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002480 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002481 }
2482 }
Mike Stump1eb44332009-09-09 15:08:12 +00002483
Douglas Gregordcee1a12009-08-06 05:28:30 +00002484 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002485 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002486}
2487
2488template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002489DeclarationNameInfo
2490TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002491::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002492 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002493 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002494 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002495
2496 switch (Name.getNameKind()) {
2497 case DeclarationName::Identifier:
2498 case DeclarationName::ObjCZeroArgSelector:
2499 case DeclarationName::ObjCOneArgSelector:
2500 case DeclarationName::ObjCMultiArgSelector:
2501 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002502 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002503 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002504 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002505
Douglas Gregor81499bb2009-09-03 22:13:48 +00002506 case DeclarationName::CXXConstructorName:
2507 case DeclarationName::CXXDestructorName:
2508 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002509 TypeSourceInfo *NewTInfo;
2510 CanQualType NewCanTy;
2511 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002512 NewTInfo = getDerived().TransformType(OldTInfo);
2513 if (!NewTInfo)
2514 return DeclarationNameInfo();
2515 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002516 }
2517 else {
2518 NewTInfo = 0;
2519 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002520 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002521 if (NewT.isNull())
2522 return DeclarationNameInfo();
2523 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2524 }
Mike Stump1eb44332009-09-09 15:08:12 +00002525
Abramo Bagnara25777432010-08-11 22:01:17 +00002526 DeclarationName NewName
2527 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2528 NewCanTy);
2529 DeclarationNameInfo NewNameInfo(NameInfo);
2530 NewNameInfo.setName(NewName);
2531 NewNameInfo.setNamedTypeInfo(NewTInfo);
2532 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002533 }
Mike Stump1eb44332009-09-09 15:08:12 +00002534 }
2535
Abramo Bagnara25777432010-08-11 22:01:17 +00002536 assert(0 && "Unknown name kind.");
2537 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002538}
2539
2540template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002541TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002542TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002543 QualType ObjectType,
2544 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002545 SourceLocation Loc = getDerived().getBaseLocation();
2546
Douglas Gregord1067e52009-08-06 06:41:21 +00002547 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002548 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002549 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002550 /*FIXME*/ SourceRange(Loc),
2551 ObjectType,
2552 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002553 if (!NNS)
2554 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002555
Douglas Gregord1067e52009-08-06 06:41:21 +00002556 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002557 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002558 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002559 if (!TransTemplate)
2560 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002561
Douglas Gregord1067e52009-08-06 06:41:21 +00002562 if (!getDerived().AlwaysRebuild() &&
2563 NNS == QTN->getQualifier() &&
2564 TransTemplate == Template)
2565 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002566
Douglas Gregord1067e52009-08-06 06:41:21 +00002567 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2568 TransTemplate);
2569 }
Mike Stump1eb44332009-09-09 15:08:12 +00002570
John McCallf7a1a742009-11-24 19:00:30 +00002571 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002572 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002573 }
Mike Stump1eb44332009-09-09 15:08:12 +00002574
Douglas Gregord1067e52009-08-06 06:41:21 +00002575 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002576 NestedNameSpecifier *NNS = DTN->getQualifier();
2577 if (NNS) {
2578 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2579 /*FIXME:*/SourceRange(Loc),
2580 ObjectType,
2581 FirstQualifierInScope);
2582 if (!NNS) return TemplateName();
2583
2584 // These apply to the scope specifier, not the template.
2585 ObjectType = QualType();
2586 FirstQualifierInScope = 0;
2587 }
Mike Stump1eb44332009-09-09 15:08:12 +00002588
Douglas Gregord1067e52009-08-06 06:41:21 +00002589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002590 NNS == DTN->getQualifier() &&
2591 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002592 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002593
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002594 if (DTN->isIdentifier()) {
2595 // FIXME: Bad range
2596 SourceRange QualifierRange(getDerived().getBaseLocation());
2597 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2598 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002599 ObjectType,
2600 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002601 }
Sean Huntc3021132010-05-05 15:23:54 +00002602
2603 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002604 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002605 }
Mike Stump1eb44332009-09-09 15:08:12 +00002606
Douglas Gregord1067e52009-08-06 06:41:21 +00002607 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002608 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002609 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002610 if (!TransTemplate)
2611 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002612
Douglas Gregord1067e52009-08-06 06:41:21 +00002613 if (!getDerived().AlwaysRebuild() &&
2614 TransTemplate == Template)
2615 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002616
Douglas Gregord1067e52009-08-06 06:41:21 +00002617 return TemplateName(TransTemplate);
2618 }
Mike Stump1eb44332009-09-09 15:08:12 +00002619
Douglas Gregor1aee05d2011-01-15 06:45:20 +00002620 if (SubstTemplateTemplateParmPackStorage *SubstPack
2621 = Name.getAsSubstTemplateTemplateParmPack()) {
2622 TemplateTemplateParmDecl *TransParam
2623 = cast_or_null<TemplateTemplateParmDecl>(
2624 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2625 if (!TransParam)
2626 return TemplateName();
2627
2628 if (!getDerived().AlwaysRebuild() &&
2629 TransParam == SubstPack->getParameterPack())
2630 return Name;
2631
2632 return getDerived().RebuildTemplateName(TransParam,
2633 SubstPack->getArgumentPack());
2634 }
2635
John McCallf7a1a742009-11-24 19:00:30 +00002636 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002637 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002638 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002639}
2640
2641template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002642void TreeTransform<Derived>::InventTemplateArgumentLoc(
2643 const TemplateArgument &Arg,
2644 TemplateArgumentLoc &Output) {
2645 SourceLocation Loc = getDerived().getBaseLocation();
2646 switch (Arg.getKind()) {
2647 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002648 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002649 break;
2650
2651 case TemplateArgument::Type:
2652 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002653 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002654
John McCall833ca992009-10-29 08:12:44 +00002655 break;
2656
Douglas Gregor788cd062009-11-11 01:00:40 +00002657 case TemplateArgument::Template:
2658 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2659 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002660
2661 case TemplateArgument::TemplateExpansion:
2662 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2663 break;
2664
John McCall833ca992009-10-29 08:12:44 +00002665 case TemplateArgument::Expression:
2666 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2667 break;
2668
2669 case TemplateArgument::Declaration:
2670 case TemplateArgument::Integral:
2671 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002672 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002673 break;
2674 }
2675}
2676
2677template<typename Derived>
2678bool TreeTransform<Derived>::TransformTemplateArgument(
2679 const TemplateArgumentLoc &Input,
2680 TemplateArgumentLoc &Output) {
2681 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002682 switch (Arg.getKind()) {
2683 case TemplateArgument::Null:
2684 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002685 Output = Input;
2686 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002687
Douglas Gregor670444e2009-08-04 22:27:00 +00002688 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002689 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002690 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002691 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002692
2693 DI = getDerived().TransformType(DI);
2694 if (!DI) return true;
2695
2696 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2697 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002698 }
Mike Stump1eb44332009-09-09 15:08:12 +00002699
Douglas Gregor670444e2009-08-04 22:27:00 +00002700 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002701 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002702 DeclarationName Name;
2703 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2704 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002705 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002706 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002707 if (!D) return true;
2708
John McCall828bff22009-10-29 18:45:58 +00002709 Expr *SourceExpr = Input.getSourceDeclExpression();
2710 if (SourceExpr) {
2711 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002712 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002713 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002714 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002715 }
2716
2717 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002718 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002719 }
Mike Stump1eb44332009-09-09 15:08:12 +00002720
Douglas Gregor788cd062009-11-11 01:00:40 +00002721 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002722 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002723 TemplateName Template
2724 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2725 if (Template.isNull())
2726 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002727
Douglas Gregor788cd062009-11-11 01:00:40 +00002728 Output = TemplateArgumentLoc(TemplateArgument(Template),
2729 Input.getTemplateQualifierRange(),
2730 Input.getTemplateNameLoc());
2731 return false;
2732 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002733
2734 case TemplateArgument::TemplateExpansion:
2735 llvm_unreachable("Caller should expand pack expansions");
2736
Douglas Gregor670444e2009-08-04 22:27:00 +00002737 case TemplateArgument::Expression: {
2738 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002739 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002740 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002741
John McCall833ca992009-10-29 08:12:44 +00002742 Expr *InputExpr = Input.getSourceExpression();
2743 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2744
John McCall60d7b3a2010-08-24 06:29:42 +00002745 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002746 = getDerived().TransformExpr(InputExpr);
2747 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002748 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002749 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002750 }
Mike Stump1eb44332009-09-09 15:08:12 +00002751
Douglas Gregor670444e2009-08-04 22:27:00 +00002752 case TemplateArgument::Pack: {
2753 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2754 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002755 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002756 AEnd = Arg.pack_end();
2757 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002758
John McCall833ca992009-10-29 08:12:44 +00002759 // FIXME: preserve source information here when we start
2760 // caring about parameter packs.
2761
John McCall828bff22009-10-29 18:45:58 +00002762 TemplateArgumentLoc InputArg;
2763 TemplateArgumentLoc OutputArg;
2764 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2765 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002766 return true;
2767
John McCall828bff22009-10-29 18:45:58 +00002768 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002769 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002770
2771 TemplateArgument *TransformedArgsPtr
2772 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2773 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2774 TransformedArgsPtr);
2775 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2776 TransformedArgs.size()),
2777 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002778 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002779 }
2780 }
Mike Stump1eb44332009-09-09 15:08:12 +00002781
Douglas Gregor670444e2009-08-04 22:27:00 +00002782 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002783 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002784}
2785
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002786/// \brief Iterator adaptor that invents template argument location information
2787/// for each of the template arguments in its underlying iterator.
2788template<typename Derived, typename InputIterator>
2789class TemplateArgumentLocInventIterator {
2790 TreeTransform<Derived> &Self;
2791 InputIterator Iter;
2792
2793public:
2794 typedef TemplateArgumentLoc value_type;
2795 typedef TemplateArgumentLoc reference;
2796 typedef typename std::iterator_traits<InputIterator>::difference_type
2797 difference_type;
2798 typedef std::input_iterator_tag iterator_category;
2799
2800 class pointer {
2801 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002802
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002803 public:
2804 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2805
2806 const TemplateArgumentLoc *operator->() const { return &Arg; }
2807 };
2808
2809 TemplateArgumentLocInventIterator() { }
2810
2811 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2812 InputIterator Iter)
2813 : Self(Self), Iter(Iter) { }
2814
2815 TemplateArgumentLocInventIterator &operator++() {
2816 ++Iter;
2817 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002818 }
2819
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002820 TemplateArgumentLocInventIterator operator++(int) {
2821 TemplateArgumentLocInventIterator Old(*this);
2822 ++(*this);
2823 return Old;
2824 }
2825
2826 reference operator*() const {
2827 TemplateArgumentLoc Result;
2828 Self.InventTemplateArgumentLoc(*Iter, Result);
2829 return Result;
2830 }
2831
2832 pointer operator->() const { return pointer(**this); }
2833
2834 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2835 const TemplateArgumentLocInventIterator &Y) {
2836 return X.Iter == Y.Iter;
2837 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002838
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002839 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2840 const TemplateArgumentLocInventIterator &Y) {
2841 return X.Iter != Y.Iter;
2842 }
2843};
2844
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002845template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002846template<typename InputIterator>
2847bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2848 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002849 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002850 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002851 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002852 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002853
2854 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2855 // Unpack argument packs, which we translate them into separate
2856 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002857 // FIXME: We could do much better if we could guarantee that the
2858 // TemplateArgumentLocInfo for the pack expansion would be usable for
2859 // all of the template arguments in the argument pack.
2860 typedef TemplateArgumentLocInventIterator<Derived,
2861 TemplateArgument::pack_iterator>
2862 PackLocIterator;
2863 if (TransformTemplateArguments(PackLocIterator(*this,
2864 In.getArgument().pack_begin()),
2865 PackLocIterator(*this,
2866 In.getArgument().pack_end()),
2867 Outputs))
2868 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002869
2870 continue;
2871 }
2872
2873 if (In.getArgument().isPackExpansion()) {
2874 // We have a pack expansion, for which we will be substituting into
2875 // the pattern.
2876 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002877 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002878 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00002879 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2880 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002881
2882 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2883 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2884 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2885
2886 // Determine whether the set of unexpanded parameter packs can and should
2887 // be expanded.
2888 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002889 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002890 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002891 if (getDerived().TryExpandParameterPacks(Ellipsis,
2892 Pattern.getSourceRange(),
2893 Unexpanded.data(),
2894 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002895 Expand,
2896 RetainExpansion,
2897 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002898 return true;
2899
2900 if (!Expand) {
2901 // The transform has determined that we should perform a simple
2902 // transformation on the pack expansion, producing another pack
2903 // expansion.
2904 TemplateArgumentLoc OutPattern;
2905 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2906 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2907 return true;
2908
Douglas Gregorcded4f62011-01-14 17:04:44 +00002909 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2910 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002911 if (Out.getArgument().isNull())
2912 return true;
2913
2914 Outputs.addArgument(Out);
2915 continue;
2916 }
2917
2918 // The transform has determined that we should perform an elementwise
2919 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002920 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002921 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2922
2923 if (getDerived().TransformTemplateArgument(Pattern, Out))
2924 return true;
2925
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002926 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00002927 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2928 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002929 if (Out.getArgument().isNull())
2930 return true;
2931 }
2932
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002933 Outputs.addArgument(Out);
2934 }
2935
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002936 // If we're supposed to retain a pack expansion, do so by temporarily
2937 // forgetting the partially-substituted parameter pack.
2938 if (RetainExpansion) {
2939 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2940
2941 if (getDerived().TransformTemplateArgument(Pattern, Out))
2942 return true;
2943
Douglas Gregorcded4f62011-01-14 17:04:44 +00002944 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2945 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002946 if (Out.getArgument().isNull())
2947 return true;
2948
2949 Outputs.addArgument(Out);
2950 }
Douglas Gregord3731192011-01-10 07:32:04 +00002951
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002952 continue;
2953 }
2954
2955 // The simple case:
2956 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002957 return true;
2958
2959 Outputs.addArgument(Out);
2960 }
2961
2962 return false;
2963
2964}
2965
Douglas Gregor577f75a2009-08-04 16:50:30 +00002966//===----------------------------------------------------------------------===//
2967// Type transformation
2968//===----------------------------------------------------------------------===//
2969
2970template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002971QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002972 if (getDerived().AlreadyTransformed(T))
2973 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002974
John McCalla2becad2009-10-21 00:40:46 +00002975 // Temporary workaround. All of these transformations should
2976 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00002977 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2978 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002979
John McCall43fed0d2010-11-12 08:19:04 +00002980 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002981
John McCalla2becad2009-10-21 00:40:46 +00002982 if (!NewDI)
2983 return QualType();
2984
2985 return NewDI->getType();
2986}
2987
2988template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002989TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002990 if (getDerived().AlreadyTransformed(DI->getType()))
2991 return DI;
2992
2993 TypeLocBuilder TLB;
2994
2995 TypeLoc TL = DI->getTypeLoc();
2996 TLB.reserve(TL.getFullDataSize());
2997
John McCall43fed0d2010-11-12 08:19:04 +00002998 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002999 if (Result.isNull())
3000 return 0;
3001
John McCalla93c9342009-12-07 02:54:59 +00003002 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003003}
3004
3005template<typename Derived>
3006QualType
John McCall43fed0d2010-11-12 08:19:04 +00003007TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003008 switch (T.getTypeLocClass()) {
3009#define ABSTRACT_TYPELOC(CLASS, PARENT)
3010#define TYPELOC(CLASS, PARENT) \
3011 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003012 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003013#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003014 }
Mike Stump1eb44332009-09-09 15:08:12 +00003015
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003016 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003017 return QualType();
3018}
3019
3020/// FIXME: By default, this routine adds type qualifiers only to types
3021/// that can have qualifiers, and silently suppresses those qualifiers
3022/// that are not permitted (e.g., qualifiers on reference or function
3023/// types). This is the right thing for template instantiation, but
3024/// probably not for other clients.
3025template<typename Derived>
3026QualType
3027TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003028 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003029 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003030
John McCall43fed0d2010-11-12 08:19:04 +00003031 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003032 if (Result.isNull())
3033 return QualType();
3034
3035 // Silently suppress qualifiers if the result type can't be qualified.
3036 // FIXME: this is the right thing for template instantiation, but
3037 // probably not for other clients.
3038 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003039 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003040
John McCall28654742010-06-05 06:41:15 +00003041 if (!Quals.empty()) {
3042 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3043 TLB.push<QualifiedTypeLoc>(Result);
3044 // No location information to preserve.
3045 }
John McCalla2becad2009-10-21 00:40:46 +00003046
3047 return Result;
3048}
3049
John McCall43fed0d2010-11-12 08:19:04 +00003050/// \brief Transforms a type that was written in a scope specifier,
3051/// given an object type, the results of unqualified lookup, and
3052/// an already-instantiated prefix.
3053///
3054/// The object type is provided iff the scope specifier qualifies the
3055/// member of a dependent member-access expression. The prefix is
3056/// provided iff the the scope specifier in which this appears has a
3057/// prefix.
3058///
3059/// This is private to TreeTransform.
3060template<typename Derived>
3061QualType
3062TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3063 QualType ObjectType,
3064 NamedDecl *UnqualLookup,
3065 NestedNameSpecifier *Prefix) {
3066 if (getDerived().AlreadyTransformed(T))
3067 return T;
3068
3069 TypeSourceInfo *TSI =
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003070 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall43fed0d2010-11-12 08:19:04 +00003071
3072 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3073 UnqualLookup, Prefix);
3074 if (!TSI) return QualType();
3075 return TSI->getType();
3076}
3077
3078template<typename Derived>
3079TypeSourceInfo *
3080TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3081 QualType ObjectType,
3082 NamedDecl *UnqualLookup,
3083 NestedNameSpecifier *Prefix) {
3084 // TODO: in some cases, we might be some verification to do here.
3085 if (ObjectType.isNull())
3086 return getDerived().TransformType(TSI);
3087
3088 QualType T = TSI->getType();
3089 if (getDerived().AlreadyTransformed(T))
3090 return TSI;
3091
3092 TypeLocBuilder TLB;
3093 QualType Result;
3094
3095 if (isa<TemplateSpecializationType>(T)) {
3096 TemplateSpecializationTypeLoc TL
3097 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3098
3099 TemplateName Template =
3100 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3101 ObjectType, UnqualLookup);
3102 if (Template.isNull()) return 0;
3103
3104 Result = getDerived()
3105 .TransformTemplateSpecializationType(TLB, TL, Template);
3106 } else if (isa<DependentTemplateSpecializationType>(T)) {
3107 DependentTemplateSpecializationTypeLoc TL
3108 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3109
3110 Result = getDerived()
3111 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3112 } else {
3113 // Nothing special needs to be done for these.
3114 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3115 }
3116
3117 if (Result.isNull()) return 0;
3118 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3119}
3120
John McCalla2becad2009-10-21 00:40:46 +00003121template <class TyLoc> static inline
3122QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3123 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3124 NewT.setNameLoc(T.getNameLoc());
3125 return T.getType();
3126}
3127
John McCalla2becad2009-10-21 00:40:46 +00003128template<typename Derived>
3129QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003130 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003131 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3132 NewT.setBuiltinLoc(T.getBuiltinLoc());
3133 if (T.needsExtraLocalData())
3134 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3135 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003136}
Mike Stump1eb44332009-09-09 15:08:12 +00003137
Douglas Gregor577f75a2009-08-04 16:50:30 +00003138template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003139QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003140 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003141 // FIXME: recurse?
3142 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003143}
Mike Stump1eb44332009-09-09 15:08:12 +00003144
Douglas Gregor577f75a2009-08-04 16:50:30 +00003145template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003146QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003147 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003148 QualType PointeeType
3149 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003150 if (PointeeType.isNull())
3151 return QualType();
3152
3153 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003154 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003155 // A dependent pointer type 'T *' has is being transformed such
3156 // that an Objective-C class type is being replaced for 'T'. The
3157 // resulting pointer type is an ObjCObjectPointerType, not a
3158 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003159 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003160
John McCallc12c5bb2010-05-15 11:32:37 +00003161 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3162 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003163 return Result;
3164 }
John McCall43fed0d2010-11-12 08:19:04 +00003165
Douglas Gregor92e986e2010-04-22 16:44:27 +00003166 if (getDerived().AlwaysRebuild() ||
3167 PointeeType != TL.getPointeeLoc().getType()) {
3168 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3169 if (Result.isNull())
3170 return QualType();
3171 }
Sean Huntc3021132010-05-05 15:23:54 +00003172
Douglas Gregor92e986e2010-04-22 16:44:27 +00003173 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3174 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003175 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003176}
Mike Stump1eb44332009-09-09 15:08:12 +00003177
3178template<typename Derived>
3179QualType
John McCalla2becad2009-10-21 00:40:46 +00003180TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003181 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003182 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003183 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3184 if (PointeeType.isNull())
3185 return QualType();
3186
3187 QualType Result = TL.getType();
3188 if (getDerived().AlwaysRebuild() ||
3189 PointeeType != TL.getPointeeLoc().getType()) {
3190 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003191 TL.getSigilLoc());
3192 if (Result.isNull())
3193 return QualType();
3194 }
3195
Douglas Gregor39968ad2010-04-22 16:50:51 +00003196 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003197 NewT.setSigilLoc(TL.getSigilLoc());
3198 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003199}
3200
John McCall85737a72009-10-30 00:06:24 +00003201/// Transforms a reference type. Note that somewhat paradoxically we
3202/// don't care whether the type itself is an l-value type or an r-value
3203/// type; we only care if the type was *written* as an l-value type
3204/// or an r-value type.
3205template<typename Derived>
3206QualType
3207TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003208 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003209 const ReferenceType *T = TL.getTypePtr();
3210
3211 // Note that this works with the pointee-as-written.
3212 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3213 if (PointeeType.isNull())
3214 return QualType();
3215
3216 QualType Result = TL.getType();
3217 if (getDerived().AlwaysRebuild() ||
3218 PointeeType != T->getPointeeTypeAsWritten()) {
3219 Result = getDerived().RebuildReferenceType(PointeeType,
3220 T->isSpelledAsLValue(),
3221 TL.getSigilLoc());
3222 if (Result.isNull())
3223 return QualType();
3224 }
3225
3226 // r-value references can be rebuilt as l-value references.
3227 ReferenceTypeLoc NewTL;
3228 if (isa<LValueReferenceType>(Result))
3229 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3230 else
3231 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3232 NewTL.setSigilLoc(TL.getSigilLoc());
3233
3234 return Result;
3235}
3236
Mike Stump1eb44332009-09-09 15:08:12 +00003237template<typename Derived>
3238QualType
John McCalla2becad2009-10-21 00:40:46 +00003239TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003240 LValueReferenceTypeLoc TL) {
3241 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003242}
3243
Mike Stump1eb44332009-09-09 15:08:12 +00003244template<typename Derived>
3245QualType
John McCalla2becad2009-10-21 00:40:46 +00003246TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003247 RValueReferenceTypeLoc TL) {
3248 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003249}
Mike Stump1eb44332009-09-09 15:08:12 +00003250
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003252QualType
John McCalla2becad2009-10-21 00:40:46 +00003253TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003254 MemberPointerTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003255 const MemberPointerType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003256
3257 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003258 if (PointeeType.isNull())
3259 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003260
John McCalla2becad2009-10-21 00:40:46 +00003261 // TODO: preserve source information for this.
3262 QualType ClassType
3263 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003264 if (ClassType.isNull())
3265 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003266
John McCalla2becad2009-10-21 00:40:46 +00003267 QualType Result = TL.getType();
3268 if (getDerived().AlwaysRebuild() ||
3269 PointeeType != T->getPointeeType() ||
3270 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003271 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3272 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003273 if (Result.isNull())
3274 return QualType();
3275 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003276
John McCalla2becad2009-10-21 00:40:46 +00003277 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3278 NewTL.setSigilLoc(TL.getSigilLoc());
3279
3280 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003281}
3282
Mike Stump1eb44332009-09-09 15:08:12 +00003283template<typename Derived>
3284QualType
John McCalla2becad2009-10-21 00:40:46 +00003285TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003286 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003287 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003288 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003289 if (ElementType.isNull())
3290 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003291
John McCalla2becad2009-10-21 00:40:46 +00003292 QualType Result = TL.getType();
3293 if (getDerived().AlwaysRebuild() ||
3294 ElementType != T->getElementType()) {
3295 Result = getDerived().RebuildConstantArrayType(ElementType,
3296 T->getSizeModifier(),
3297 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003298 T->getIndexTypeCVRQualifiers(),
3299 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003300 if (Result.isNull())
3301 return QualType();
3302 }
Sean Huntc3021132010-05-05 15:23:54 +00003303
John McCalla2becad2009-10-21 00:40:46 +00003304 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3305 NewTL.setLBracketLoc(TL.getLBracketLoc());
3306 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003307
John McCalla2becad2009-10-21 00:40:46 +00003308 Expr *Size = TL.getSizeExpr();
3309 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003310 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003311 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3312 }
3313 NewTL.setSizeExpr(Size);
3314
3315 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003316}
Mike Stump1eb44332009-09-09 15:08:12 +00003317
Douglas Gregor577f75a2009-08-04 16:50:30 +00003318template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003319QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003320 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003321 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003322 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003323 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003324 if (ElementType.isNull())
3325 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003326
John McCalla2becad2009-10-21 00:40:46 +00003327 QualType Result = TL.getType();
3328 if (getDerived().AlwaysRebuild() ||
3329 ElementType != T->getElementType()) {
3330 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003331 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003332 T->getIndexTypeCVRQualifiers(),
3333 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003334 if (Result.isNull())
3335 return QualType();
3336 }
Sean Huntc3021132010-05-05 15:23:54 +00003337
John McCalla2becad2009-10-21 00:40:46 +00003338 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3339 NewTL.setLBracketLoc(TL.getLBracketLoc());
3340 NewTL.setRBracketLoc(TL.getRBracketLoc());
3341 NewTL.setSizeExpr(0);
3342
3343 return Result;
3344}
3345
3346template<typename Derived>
3347QualType
3348TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003349 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003350 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003351 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3352 if (ElementType.isNull())
3353 return QualType();
3354
3355 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003356 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003357
John McCall60d7b3a2010-08-24 06:29:42 +00003358 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003359 = getDerived().TransformExpr(T->getSizeExpr());
3360 if (SizeResult.isInvalid())
3361 return QualType();
3362
John McCall9ae2f072010-08-23 23:25:46 +00003363 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003364
3365 QualType Result = TL.getType();
3366 if (getDerived().AlwaysRebuild() ||
3367 ElementType != T->getElementType() ||
3368 Size != T->getSizeExpr()) {
3369 Result = getDerived().RebuildVariableArrayType(ElementType,
3370 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003371 Size,
John McCalla2becad2009-10-21 00:40:46 +00003372 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003373 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003374 if (Result.isNull())
3375 return QualType();
3376 }
Sean Huntc3021132010-05-05 15:23:54 +00003377
John McCalla2becad2009-10-21 00:40:46 +00003378 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3379 NewTL.setLBracketLoc(TL.getLBracketLoc());
3380 NewTL.setRBracketLoc(TL.getRBracketLoc());
3381 NewTL.setSizeExpr(Size);
3382
3383 return Result;
3384}
3385
3386template<typename Derived>
3387QualType
3388TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003389 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003390 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003391 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3392 if (ElementType.isNull())
3393 return QualType();
3394
3395 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003396 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003397
John McCall3b657512011-01-19 10:06:00 +00003398 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3399 Expr *origSize = TL.getSizeExpr();
3400 if (!origSize) origSize = T->getSizeExpr();
3401
3402 ExprResult sizeResult
3403 = getDerived().TransformExpr(origSize);
3404 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003405 return QualType();
3406
John McCall3b657512011-01-19 10:06:00 +00003407 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003408
3409 QualType Result = TL.getType();
3410 if (getDerived().AlwaysRebuild() ||
3411 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003412 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003413 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3414 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003415 size,
John McCalla2becad2009-10-21 00:40:46 +00003416 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003417 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003418 if (Result.isNull())
3419 return QualType();
3420 }
John McCalla2becad2009-10-21 00:40:46 +00003421
3422 // We might have any sort of array type now, but fortunately they
3423 // all have the same location layout.
3424 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3425 NewTL.setLBracketLoc(TL.getLBracketLoc());
3426 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003427 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003428
3429 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003430}
Mike Stump1eb44332009-09-09 15:08:12 +00003431
3432template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003433QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003434 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003435 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003436 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003437
3438 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003439 QualType ElementType = getDerived().TransformType(T->getElementType());
3440 if (ElementType.isNull())
3441 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003442
Douglas Gregor670444e2009-08-04 22:27:00 +00003443 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003444 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003445
John McCall60d7b3a2010-08-24 06:29:42 +00003446 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003447 if (Size.isInvalid())
3448 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003449
John McCalla2becad2009-10-21 00:40:46 +00003450 QualType Result = TL.getType();
3451 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003452 ElementType != T->getElementType() ||
3453 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003454 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003455 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003456 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003457 if (Result.isNull())
3458 return QualType();
3459 }
John McCalla2becad2009-10-21 00:40:46 +00003460
3461 // Result might be dependent or not.
3462 if (isa<DependentSizedExtVectorType>(Result)) {
3463 DependentSizedExtVectorTypeLoc NewTL
3464 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3465 NewTL.setNameLoc(TL.getNameLoc());
3466 } else {
3467 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3468 NewTL.setNameLoc(TL.getNameLoc());
3469 }
3470
3471 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003472}
Mike Stump1eb44332009-09-09 15:08:12 +00003473
3474template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003475QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003476 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003477 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003478 QualType ElementType = getDerived().TransformType(T->getElementType());
3479 if (ElementType.isNull())
3480 return QualType();
3481
John McCalla2becad2009-10-21 00:40:46 +00003482 QualType Result = TL.getType();
3483 if (getDerived().AlwaysRebuild() ||
3484 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003485 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003486 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003487 if (Result.isNull())
3488 return QualType();
3489 }
Sean Huntc3021132010-05-05 15:23:54 +00003490
John McCalla2becad2009-10-21 00:40:46 +00003491 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3492 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003493
John McCalla2becad2009-10-21 00:40:46 +00003494 return Result;
3495}
3496
3497template<typename Derived>
3498QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003499 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003500 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003501 QualType ElementType = getDerived().TransformType(T->getElementType());
3502 if (ElementType.isNull())
3503 return QualType();
3504
3505 QualType Result = TL.getType();
3506 if (getDerived().AlwaysRebuild() ||
3507 ElementType != T->getElementType()) {
3508 Result = getDerived().RebuildExtVectorType(ElementType,
3509 T->getNumElements(),
3510 /*FIXME*/ SourceLocation());
3511 if (Result.isNull())
3512 return QualType();
3513 }
Sean Huntc3021132010-05-05 15:23:54 +00003514
John McCalla2becad2009-10-21 00:40:46 +00003515 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3516 NewTL.setNameLoc(TL.getNameLoc());
3517
3518 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003519}
Mike Stump1eb44332009-09-09 15:08:12 +00003520
3521template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003522ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003523TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3524 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003525 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003526 TypeSourceInfo *NewDI = 0;
3527
3528 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3529 // If we're substituting into a pack expansion type and we know the
3530 TypeLoc OldTL = OldDI->getTypeLoc();
3531 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3532
3533 TypeLocBuilder TLB;
3534 TypeLoc NewTL = OldDI->getTypeLoc();
3535 TLB.reserve(NewTL.getFullDataSize());
3536
3537 QualType Result = getDerived().TransformType(TLB,
3538 OldExpansionTL.getPatternLoc());
3539 if (Result.isNull())
3540 return 0;
3541
3542 Result = RebuildPackExpansionType(Result,
3543 OldExpansionTL.getPatternLoc().getSourceRange(),
3544 OldExpansionTL.getEllipsisLoc(),
3545 NumExpansions);
3546 if (Result.isNull())
3547 return 0;
3548
3549 PackExpansionTypeLoc NewExpansionTL
3550 = TLB.push<PackExpansionTypeLoc>(Result);
3551 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3552 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3553 } else
3554 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003555 if (!NewDI)
3556 return 0;
3557
3558 if (NewDI == OldDI)
3559 return OldParm;
3560 else
3561 return ParmVarDecl::Create(SemaRef.Context,
3562 OldParm->getDeclContext(),
3563 OldParm->getLocation(),
3564 OldParm->getIdentifier(),
3565 NewDI->getType(),
3566 NewDI,
3567 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003568 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003569 /* DefArg */ NULL);
3570}
3571
3572template<typename Derived>
3573bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003574 TransformFunctionTypeParams(SourceLocation Loc,
3575 ParmVarDecl **Params, unsigned NumParams,
3576 const QualType *ParamTypes,
3577 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3578 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3579 for (unsigned i = 0; i != NumParams; ++i) {
3580 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003581 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003582 if (OldParm->isParameterPack()) {
3583 // We have a function parameter pack that may need to be expanded.
3584 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003585
Douglas Gregor603cfb42011-01-05 23:12:31 +00003586 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003587 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3588 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3589 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3590 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003591
3592 // Determine whether we should expand the parameter packs.
3593 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003594 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003595 llvm::Optional<unsigned> OrigNumExpansions
3596 = ExpansionTL.getTypePtr()->getNumExpansions();
3597 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003598 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3599 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003600 Unexpanded.data(),
3601 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003602 ShouldExpand,
3603 RetainExpansion,
3604 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003605 return true;
3606 }
3607
3608 if (ShouldExpand) {
3609 // Expand the function parameter pack into multiple, separate
3610 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003611 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003612 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003613 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3614 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003615 = getDerived().TransformFunctionTypeParam(OldParm,
3616 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003617 if (!NewParm)
3618 return true;
3619
Douglas Gregora009b592011-01-07 00:20:55 +00003620 OutParamTypes.push_back(NewParm->getType());
3621 if (PVars)
3622 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003623 }
Douglas Gregord3731192011-01-10 07:32:04 +00003624
3625 // If we're supposed to retain a pack expansion, do so by temporarily
3626 // forgetting the partially-substituted parameter pack.
3627 if (RetainExpansion) {
3628 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3629 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003630 = getDerived().TransformFunctionTypeParam(OldParm,
3631 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003632 if (!NewParm)
3633 return true;
3634
3635 OutParamTypes.push_back(NewParm->getType());
3636 if (PVars)
3637 PVars->push_back(NewParm);
3638 }
3639
Douglas Gregor603cfb42011-01-05 23:12:31 +00003640 // We're done with the pack expansion.
3641 continue;
3642 }
3643
3644 // We'll substitute the parameter now without expanding the pack
3645 // expansion.
3646 }
3647
3648 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003649 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3650 NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +00003651 if (!NewParm)
3652 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003653
Douglas Gregora009b592011-01-07 00:20:55 +00003654 OutParamTypes.push_back(NewParm->getType());
3655 if (PVars)
3656 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003657 continue;
3658 }
John McCall21ef0fa2010-03-11 09:03:00 +00003659
3660 // Deal with the possibility that we don't have a parameter
3661 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003662 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003663 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003664 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003665 if (const PackExpansionType *Expansion
3666 = dyn_cast<PackExpansionType>(OldType)) {
3667 // We have a function parameter pack that may need to be expanded.
3668 QualType Pattern = Expansion->getPattern();
3669 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3670 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3671
3672 // Determine whether we should expand the parameter packs.
3673 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003674 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003675 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003676 Unexpanded.data(),
3677 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003678 ShouldExpand,
3679 RetainExpansion,
3680 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003681 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003682 }
3683
3684 if (ShouldExpand) {
3685 // Expand the function parameter pack into multiple, separate
3686 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003687 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003688 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3689 QualType NewType = getDerived().TransformType(Pattern);
3690 if (NewType.isNull())
3691 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003692
Douglas Gregora009b592011-01-07 00:20:55 +00003693 OutParamTypes.push_back(NewType);
3694 if (PVars)
3695 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003696 }
3697
3698 // We're done with the pack expansion.
3699 continue;
3700 }
3701
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003702 // If we're supposed to retain a pack expansion, do so by temporarily
3703 // forgetting the partially-substituted parameter pack.
3704 if (RetainExpansion) {
3705 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3706 QualType NewType = getDerived().TransformType(Pattern);
3707 if (NewType.isNull())
3708 return true;
3709
3710 OutParamTypes.push_back(NewType);
3711 if (PVars)
3712 PVars->push_back(0);
3713 }
Douglas Gregord3731192011-01-10 07:32:04 +00003714
Douglas Gregor603cfb42011-01-05 23:12:31 +00003715 // We'll substitute the parameter now without expanding the pack
3716 // expansion.
3717 OldType = Expansion->getPattern();
3718 IsPackExpansion = true;
3719 }
3720
3721 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3722 QualType NewType = getDerived().TransformType(OldType);
3723 if (NewType.isNull())
3724 return true;
3725
3726 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003727 NewType = getSema().Context.getPackExpansionType(NewType,
3728 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003729
Douglas Gregora009b592011-01-07 00:20:55 +00003730 OutParamTypes.push_back(NewType);
3731 if (PVars)
3732 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003733 }
3734
3735 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003736 }
John McCall21ef0fa2010-03-11 09:03:00 +00003737
3738template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003739QualType
John McCalla2becad2009-10-21 00:40:46 +00003740TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003741 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003742 // Transform the parameters and return type.
3743 //
3744 // We instantiate in source order, with the return type first followed by
3745 // the parameters, because users tend to expect this (even if they shouldn't
3746 // rely on it!).
3747 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003748 // When the function has a trailing return type, we instantiate the
3749 // parameters before the return type, since the return type can then refer
3750 // to the parameters themselves (via decltype, sizeof, etc.).
3751 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003752 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003753 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003754 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003755
Douglas Gregordab60ad2010-10-01 18:44:50 +00003756 QualType ResultType;
3757
3758 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003759 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3760 TL.getParmArray(),
3761 TL.getNumArgs(),
3762 TL.getTypePtr()->arg_type_begin(),
3763 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003764 return QualType();
3765
3766 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3767 if (ResultType.isNull())
3768 return QualType();
3769 }
3770 else {
3771 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3772 if (ResultType.isNull())
3773 return QualType();
3774
Douglas Gregora009b592011-01-07 00:20:55 +00003775 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3776 TL.getParmArray(),
3777 TL.getNumArgs(),
3778 TL.getTypePtr()->arg_type_begin(),
3779 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003780 return QualType();
3781 }
3782
John McCalla2becad2009-10-21 00:40:46 +00003783 QualType Result = TL.getType();
3784 if (getDerived().AlwaysRebuild() ||
3785 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003786 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003787 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3788 Result = getDerived().RebuildFunctionProtoType(ResultType,
3789 ParamTypes.data(),
3790 ParamTypes.size(),
3791 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003792 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00003793 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003794 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003795 if (Result.isNull())
3796 return QualType();
3797 }
Mike Stump1eb44332009-09-09 15:08:12 +00003798
John McCalla2becad2009-10-21 00:40:46 +00003799 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3800 NewTL.setLParenLoc(TL.getLParenLoc());
3801 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003802 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003803 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3804 NewTL.setArg(i, ParamDecls[i]);
3805
3806 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807}
Mike Stump1eb44332009-09-09 15:08:12 +00003808
Douglas Gregor577f75a2009-08-04 16:50:30 +00003809template<typename Derived>
3810QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003811 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003812 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003813 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003814 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3815 if (ResultType.isNull())
3816 return QualType();
3817
3818 QualType Result = TL.getType();
3819 if (getDerived().AlwaysRebuild() ||
3820 ResultType != T->getResultType())
3821 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3822
3823 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3824 NewTL.setLParenLoc(TL.getLParenLoc());
3825 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003826 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
John McCalled976492009-12-04 22:46:56 +00003831template<typename Derived> QualType
3832TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003833 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003834 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003835 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003836 if (!D)
3837 return QualType();
3838
3839 QualType Result = TL.getType();
3840 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3841 Result = getDerived().RebuildUnresolvedUsingType(D);
3842 if (Result.isNull())
3843 return QualType();
3844 }
3845
3846 // We might get an arbitrary type spec type back. We should at
3847 // least always get a type spec type, though.
3848 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3849 NewTL.setNameLoc(TL.getNameLoc());
3850
3851 return Result;
3852}
3853
Douglas Gregor577f75a2009-08-04 16:50:30 +00003854template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003855QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003856 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003857 const TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003858 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003859 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3860 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003861 if (!Typedef)
3862 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003863
John McCalla2becad2009-10-21 00:40:46 +00003864 QualType Result = TL.getType();
3865 if (getDerived().AlwaysRebuild() ||
3866 Typedef != T->getDecl()) {
3867 Result = getDerived().RebuildTypedefType(Typedef);
3868 if (Result.isNull())
3869 return QualType();
3870 }
Mike Stump1eb44332009-09-09 15:08:12 +00003871
John McCalla2becad2009-10-21 00:40:46 +00003872 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3873 NewTL.setNameLoc(TL.getNameLoc());
3874
3875 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003876}
Mike Stump1eb44332009-09-09 15:08:12 +00003877
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003879QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003880 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003881 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003882 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003883
John McCall60d7b3a2010-08-24 06:29:42 +00003884 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003885 if (E.isInvalid())
3886 return QualType();
3887
John McCalla2becad2009-10-21 00:40:46 +00003888 QualType Result = TL.getType();
3889 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003890 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003891 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003892 if (Result.isNull())
3893 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003894 }
John McCalla2becad2009-10-21 00:40:46 +00003895 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003896
John McCalla2becad2009-10-21 00:40:46 +00003897 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003898 NewTL.setTypeofLoc(TL.getTypeofLoc());
3899 NewTL.setLParenLoc(TL.getLParenLoc());
3900 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003901
3902 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003903}
Mike Stump1eb44332009-09-09 15:08:12 +00003904
3905template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003906QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003907 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003908 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3909 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3910 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003911 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003912
John McCalla2becad2009-10-21 00:40:46 +00003913 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003914 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3915 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003916 if (Result.isNull())
3917 return QualType();
3918 }
Mike Stump1eb44332009-09-09 15:08:12 +00003919
John McCalla2becad2009-10-21 00:40:46 +00003920 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003921 NewTL.setTypeofLoc(TL.getTypeofLoc());
3922 NewTL.setLParenLoc(TL.getLParenLoc());
3923 NewTL.setRParenLoc(TL.getRParenLoc());
3924 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003925
3926 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003927}
Mike Stump1eb44332009-09-09 15:08:12 +00003928
3929template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003930QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003931 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003932 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003933
Douglas Gregor670444e2009-08-04 22:27:00 +00003934 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003935 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003936
John McCall60d7b3a2010-08-24 06:29:42 +00003937 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003938 if (E.isInvalid())
3939 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003940
John McCalla2becad2009-10-21 00:40:46 +00003941 QualType Result = TL.getType();
3942 if (getDerived().AlwaysRebuild() ||
3943 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003944 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003945 if (Result.isNull())
3946 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003947 }
John McCalla2becad2009-10-21 00:40:46 +00003948 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003949
John McCalla2becad2009-10-21 00:40:46 +00003950 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3951 NewTL.setNameLoc(TL.getNameLoc());
3952
3953 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003954}
3955
3956template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003957QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003958 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003959 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003960 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003961 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3962 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003963 if (!Record)
3964 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003965
John McCalla2becad2009-10-21 00:40:46 +00003966 QualType Result = TL.getType();
3967 if (getDerived().AlwaysRebuild() ||
3968 Record != T->getDecl()) {
3969 Result = getDerived().RebuildRecordType(Record);
3970 if (Result.isNull())
3971 return QualType();
3972 }
Mike Stump1eb44332009-09-09 15:08:12 +00003973
John McCalla2becad2009-10-21 00:40:46 +00003974 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3975 NewTL.setNameLoc(TL.getNameLoc());
3976
3977 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003978}
Mike Stump1eb44332009-09-09 15:08:12 +00003979
3980template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003981QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003982 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003983 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003984 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003985 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3986 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003987 if (!Enum)
3988 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003989
John McCalla2becad2009-10-21 00:40:46 +00003990 QualType Result = TL.getType();
3991 if (getDerived().AlwaysRebuild() ||
3992 Enum != T->getDecl()) {
3993 Result = getDerived().RebuildEnumType(Enum);
3994 if (Result.isNull())
3995 return QualType();
3996 }
Mike Stump1eb44332009-09-09 15:08:12 +00003997
John McCalla2becad2009-10-21 00:40:46 +00003998 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3999 NewTL.setNameLoc(TL.getNameLoc());
4000
4001 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004002}
John McCall7da24312009-09-05 00:15:47 +00004003
John McCall3cb0ebd2010-03-10 03:28:59 +00004004template<typename Derived>
4005QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4006 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004007 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004008 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4009 TL.getTypePtr()->getDecl());
4010 if (!D) return QualType();
4011
4012 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4013 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4014 return T;
4015}
4016
Douglas Gregor577f75a2009-08-04 16:50:30 +00004017template<typename Derived>
4018QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004019 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004020 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004021 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004022}
4023
Mike Stump1eb44332009-09-09 15:08:12 +00004024template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004025QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004026 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004027 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004028 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00004029}
4030
4031template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004032QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4033 TypeLocBuilder &TLB,
4034 SubstTemplateTypeParmPackTypeLoc TL) {
4035 return TransformTypeSpecType(TLB, TL);
4036}
4037
4038template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004039QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004040 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004041 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004042 const TemplateSpecializationType *T = TL.getTypePtr();
4043
Mike Stump1eb44332009-09-09 15:08:12 +00004044 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00004045 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004046 if (Template.isNull())
4047 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004048
John McCall43fed0d2010-11-12 08:19:04 +00004049 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4050}
4051
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004052namespace {
4053 /// \brief Simple iterator that traverses the template arguments in a
4054 /// container that provides a \c getArgLoc() member function.
4055 ///
4056 /// This iterator is intended to be used with the iterator form of
4057 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4058 template<typename ArgLocContainer>
4059 class TemplateArgumentLocContainerIterator {
4060 ArgLocContainer *Container;
4061 unsigned Index;
4062
4063 public:
4064 typedef TemplateArgumentLoc value_type;
4065 typedef TemplateArgumentLoc reference;
4066 typedef int difference_type;
4067 typedef std::input_iterator_tag iterator_category;
4068
4069 class pointer {
4070 TemplateArgumentLoc Arg;
4071
4072 public:
4073 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4074
4075 const TemplateArgumentLoc *operator->() const {
4076 return &Arg;
4077 }
4078 };
4079
4080
4081 TemplateArgumentLocContainerIterator() {}
4082
4083 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4084 unsigned Index)
4085 : Container(&Container), Index(Index) { }
4086
4087 TemplateArgumentLocContainerIterator &operator++() {
4088 ++Index;
4089 return *this;
4090 }
4091
4092 TemplateArgumentLocContainerIterator operator++(int) {
4093 TemplateArgumentLocContainerIterator Old(*this);
4094 ++(*this);
4095 return Old;
4096 }
4097
4098 TemplateArgumentLoc operator*() const {
4099 return Container->getArgLoc(Index);
4100 }
4101
4102 pointer operator->() const {
4103 return pointer(Container->getArgLoc(Index));
4104 }
4105
4106 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004107 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004108 return X.Container == Y.Container && X.Index == Y.Index;
4109 }
4110
4111 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004112 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004113 return !(X == Y);
4114 }
4115 };
4116}
4117
4118
John McCall43fed0d2010-11-12 08:19:04 +00004119template <typename Derived>
4120QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4121 TypeLocBuilder &TLB,
4122 TemplateSpecializationTypeLoc TL,
4123 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004124 TemplateArgumentListInfo NewTemplateArgs;
4125 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4126 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004127 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4128 ArgIterator;
4129 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4130 ArgIterator(TL, TL.getNumArgs()),
4131 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004132 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004133
John McCall833ca992009-10-29 08:12:44 +00004134 // FIXME: maybe don't rebuild if all the template arguments are the same.
4135
4136 QualType Result =
4137 getDerived().RebuildTemplateSpecializationType(Template,
4138 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004139 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004140
4141 if (!Result.isNull()) {
4142 TemplateSpecializationTypeLoc NewTL
4143 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4144 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4145 NewTL.setLAngleLoc(TL.getLAngleLoc());
4146 NewTL.setRAngleLoc(TL.getRAngleLoc());
4147 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4148 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004149 }
Mike Stump1eb44332009-09-09 15:08:12 +00004150
John McCall833ca992009-10-29 08:12:44 +00004151 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004152}
Mike Stump1eb44332009-09-09 15:08:12 +00004153
4154template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004155QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004156TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004157 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004158 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004159
4160 NestedNameSpecifier *NNS = 0;
4161 // NOTE: the qualifier in an ElaboratedType is optional.
4162 if (T->getQualifier() != 0) {
4163 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004164 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004165 if (!NNS)
4166 return QualType();
4167 }
Mike Stump1eb44332009-09-09 15:08:12 +00004168
John McCall43fed0d2010-11-12 08:19:04 +00004169 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4170 if (NamedT.isNull())
4171 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004172
John McCalla2becad2009-10-21 00:40:46 +00004173 QualType Result = TL.getType();
4174 if (getDerived().AlwaysRebuild() ||
4175 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004176 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004177 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4178 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004179 if (Result.isNull())
4180 return QualType();
4181 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004182
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004183 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004184 NewTL.setKeywordLoc(TL.getKeywordLoc());
4185 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004186
4187 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004188}
Mike Stump1eb44332009-09-09 15:08:12 +00004189
4190template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004191QualType TreeTransform<Derived>::TransformAttributedType(
4192 TypeLocBuilder &TLB,
4193 AttributedTypeLoc TL) {
4194 const AttributedType *oldType = TL.getTypePtr();
4195 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4196 if (modifiedType.isNull())
4197 return QualType();
4198
4199 QualType result = TL.getType();
4200
4201 // FIXME: dependent operand expressions?
4202 if (getDerived().AlwaysRebuild() ||
4203 modifiedType != oldType->getModifiedType()) {
4204 // TODO: this is really lame; we should really be rebuilding the
4205 // equivalent type from first principles.
4206 QualType equivalentType
4207 = getDerived().TransformType(oldType->getEquivalentType());
4208 if (equivalentType.isNull())
4209 return QualType();
4210 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4211 modifiedType,
4212 equivalentType);
4213 }
4214
4215 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4216 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4217 if (TL.hasAttrOperand())
4218 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4219 if (TL.hasAttrExprOperand())
4220 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4221 else if (TL.hasAttrEnumOperand())
4222 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4223
4224 return result;
4225}
4226
4227template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004228QualType
4229TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4230 ParenTypeLoc TL) {
4231 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4232 if (Inner.isNull())
4233 return QualType();
4234
4235 QualType Result = TL.getType();
4236 if (getDerived().AlwaysRebuild() ||
4237 Inner != TL.getInnerLoc().getType()) {
4238 Result = getDerived().RebuildParenType(Inner);
4239 if (Result.isNull())
4240 return QualType();
4241 }
4242
4243 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4244 NewTL.setLParenLoc(TL.getLParenLoc());
4245 NewTL.setRParenLoc(TL.getRParenLoc());
4246 return Result;
4247}
4248
4249template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004250QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004251 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004252 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004253
Douglas Gregor577f75a2009-08-04 16:50:30 +00004254 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004255 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004256 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004257 if (!NNS)
4258 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004259
John McCall33500952010-06-11 00:33:02 +00004260 QualType Result
4261 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4262 T->getIdentifier(),
4263 TL.getKeywordLoc(),
4264 TL.getQualifierRange(),
4265 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004266 if (Result.isNull())
4267 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004268
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004269 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4270 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004271 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4272
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004273 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4274 NewTL.setKeywordLoc(TL.getKeywordLoc());
4275 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004276 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004277 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4278 NewTL.setKeywordLoc(TL.getKeywordLoc());
4279 NewTL.setQualifierRange(TL.getQualifierRange());
4280 NewTL.setNameLoc(TL.getNameLoc());
4281 }
John McCalla2becad2009-10-21 00:40:46 +00004282 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
Douglas Gregor577f75a2009-08-04 16:50:30 +00004285template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004286QualType TreeTransform<Derived>::
4287 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004288 DependentTemplateSpecializationTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004289 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall33500952010-06-11 00:33:02 +00004290
4291 NestedNameSpecifier *NNS
4292 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004293 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004294 if (!NNS)
4295 return QualType();
4296
John McCall43fed0d2010-11-12 08:19:04 +00004297 return getDerived()
4298 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4299}
4300
4301template<typename Derived>
4302QualType TreeTransform<Derived>::
4303 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4304 DependentTemplateSpecializationTypeLoc TL,
4305 NestedNameSpecifier *NNS) {
John McCallf4c73712011-01-19 06:33:43 +00004306 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall43fed0d2010-11-12 08:19:04 +00004307
John McCall33500952010-06-11 00:33:02 +00004308 TemplateArgumentListInfo NewTemplateArgs;
4309 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4310 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004311
4312 typedef TemplateArgumentLocContainerIterator<
4313 DependentTemplateSpecializationTypeLoc> ArgIterator;
4314 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4315 ArgIterator(TL, TL.getNumArgs()),
4316 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004317 return QualType();
John McCall33500952010-06-11 00:33:02 +00004318
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004319 QualType Result
4320 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4321 NNS,
4322 TL.getQualifierRange(),
4323 T->getIdentifier(),
4324 TL.getNameLoc(),
4325 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004326 if (Result.isNull())
4327 return QualType();
4328
4329 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4330 QualType NamedT = ElabT->getNamedType();
4331
4332 // Copy information relevant to the template specialization.
4333 TemplateSpecializationTypeLoc NamedTL
4334 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4335 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4336 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4337 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4338 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4339
4340 // Copy information relevant to the elaborated type.
4341 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4342 NewTL.setKeywordLoc(TL.getKeywordLoc());
4343 NewTL.setQualifierRange(TL.getQualifierRange());
4344 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004345 TypeLoc NewTL(Result, TL.getOpaqueData());
4346 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004347 }
4348 return Result;
4349}
4350
4351template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004352QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4353 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004354 QualType Pattern
4355 = getDerived().TransformType(TLB, TL.getPatternLoc());
4356 if (Pattern.isNull())
4357 return QualType();
4358
4359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() ||
4361 Pattern != TL.getPatternLoc().getType()) {
4362 Result = getDerived().RebuildPackExpansionType(Pattern,
4363 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004364 TL.getEllipsisLoc(),
4365 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004366 if (Result.isNull())
4367 return QualType();
4368 }
4369
4370 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4371 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4372 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004373}
4374
4375template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004376QualType
4377TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004378 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004379 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004380 TLB.pushFullCopy(TL);
4381 return TL.getType();
4382}
4383
4384template<typename Derived>
4385QualType
4386TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004387 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004388 // ObjCObjectType is never dependent.
4389 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004390 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004391}
Mike Stump1eb44332009-09-09 15:08:12 +00004392
4393template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004394QualType
4395TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004396 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004397 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004398 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004399 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004400}
4401
Douglas Gregor577f75a2009-08-04 16:50:30 +00004402//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004403// Statement transformation
4404//===----------------------------------------------------------------------===//
4405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004406StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004407TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004408 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004409}
4410
4411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004412StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004413TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4414 return getDerived().TransformCompoundStmt(S, false);
4415}
4416
4417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004418StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004419TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004420 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004421 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004422 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004423 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004424 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4425 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004426 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004427 if (Result.isInvalid()) {
4428 // Immediately fail if this was a DeclStmt, since it's very
4429 // likely that this will cause problems for future statements.
4430 if (isa<DeclStmt>(*B))
4431 return StmtError();
4432
4433 // Otherwise, just keep processing substatements and fail later.
4434 SubStmtInvalid = true;
4435 continue;
4436 }
Mike Stump1eb44332009-09-09 15:08:12 +00004437
Douglas Gregor43959a92009-08-20 07:17:43 +00004438 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4439 Statements.push_back(Result.takeAs<Stmt>());
4440 }
Mike Stump1eb44332009-09-09 15:08:12 +00004441
John McCall7114cba2010-08-27 19:56:05 +00004442 if (SubStmtInvalid)
4443 return StmtError();
4444
Douglas Gregor43959a92009-08-20 07:17:43 +00004445 if (!getDerived().AlwaysRebuild() &&
4446 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004447 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004448
4449 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4450 move_arg(Statements),
4451 S->getRBracLoc(),
4452 IsStmtExpr);
4453}
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregor43959a92009-08-20 07:17:43 +00004455template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004456StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004457TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004458 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004459 {
4460 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004461 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004462
Eli Friedman264c1f82009-11-19 03:14:00 +00004463 // Transform the left-hand case value.
4464 LHS = getDerived().TransformExpr(S->getLHS());
4465 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004466 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004467
Eli Friedman264c1f82009-11-19 03:14:00 +00004468 // Transform the right-hand case value (for the GNU case-range extension).
4469 RHS = getDerived().TransformExpr(S->getRHS());
4470 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004471 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004472 }
Mike Stump1eb44332009-09-09 15:08:12 +00004473
Douglas Gregor43959a92009-08-20 07:17:43 +00004474 // Build the case statement.
4475 // Case statements are always rebuilt so that they will attached to their
4476 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004477 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004478 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004479 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004480 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004481 S->getColonLoc());
4482 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004483 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004484
Douglas Gregor43959a92009-08-20 07:17:43 +00004485 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004486 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004487 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004488 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004489
Douglas Gregor43959a92009-08-20 07:17:43 +00004490 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004491 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004492}
4493
4494template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004495StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004496TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004497 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004498 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004499 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004500 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004501
Douglas Gregor43959a92009-08-20 07:17:43 +00004502 // Default statements are always rebuilt
4503 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004504 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004505}
Mike Stump1eb44332009-09-09 15:08:12 +00004506
Douglas Gregor43959a92009-08-20 07:17:43 +00004507template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004508StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004509TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004510 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004511 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004512 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004513
Douglas Gregor43959a92009-08-20 07:17:43 +00004514 // FIXME: Pass the real colon location in.
4515 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004516 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
4517 S->getDecl()->getIdentifier(), ColonLoc,
4518 SubStmt.get(),
4519 S->getDecl()->hasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004520}
Mike Stump1eb44332009-09-09 15:08:12 +00004521
Douglas Gregor43959a92009-08-20 07:17:43 +00004522template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004523StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004524TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004525 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004526 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004527 VarDecl *ConditionVar = 0;
4528 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004529 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004530 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004531 getDerived().TransformDefinition(
4532 S->getConditionVariable()->getLocation(),
4533 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004534 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004535 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004536 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004537 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004538
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004539 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004540 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004541
4542 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004543 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004544 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4545 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004546 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004547 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004548
John McCall9ae2f072010-08-23 23:25:46 +00004549 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004550 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004551 }
Sean Huntc3021132010-05-05 15:23:54 +00004552
John McCall9ae2f072010-08-23 23:25:46 +00004553 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4554 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004555 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004556
Douglas Gregor43959a92009-08-20 07:17:43 +00004557 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004558 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004559 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004560 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004561
Douglas Gregor43959a92009-08-20 07:17:43 +00004562 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004563 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004564 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004565 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004566
Douglas Gregor43959a92009-08-20 07:17:43 +00004567 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004568 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004569 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004570 Then.get() == S->getThen() &&
4571 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004572 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004573
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004574 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004575 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004576 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004577}
4578
4579template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004580StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004581TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004582 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004583 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004584 VarDecl *ConditionVar = 0;
4585 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004586 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004587 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004588 getDerived().TransformDefinition(
4589 S->getConditionVariable()->getLocation(),
4590 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004591 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004592 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004593 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004594 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004595
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004596 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004597 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004598 }
Mike Stump1eb44332009-09-09 15:08:12 +00004599
Douglas Gregor43959a92009-08-20 07:17:43 +00004600 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004601 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004602 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004603 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004604 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004605 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004606
Douglas Gregor43959a92009-08-20 07:17:43 +00004607 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004608 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004609 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004610 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004611
Douglas Gregor43959a92009-08-20 07:17:43 +00004612 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004613 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4614 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004615}
Mike Stump1eb44332009-09-09 15:08:12 +00004616
Douglas Gregor43959a92009-08-20 07:17:43 +00004617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004618StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004619TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004620 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004621 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004622 VarDecl *ConditionVar = 0;
4623 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004624 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004625 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004626 getDerived().TransformDefinition(
4627 S->getConditionVariable()->getLocation(),
4628 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004629 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004630 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004631 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004632 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004633
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004634 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004635 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004636
4637 if (S->getCond()) {
4638 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004639 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4640 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004641 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004642 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004643 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004644 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004645 }
Mike Stump1eb44332009-09-09 15:08:12 +00004646
John McCall9ae2f072010-08-23 23:25:46 +00004647 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4648 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004649 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004650
Douglas Gregor43959a92009-08-20 07:17:43 +00004651 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004652 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004653 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004654 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004655
Douglas Gregor43959a92009-08-20 07:17:43 +00004656 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004657 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004658 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004659 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004660 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004661
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004662 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004663 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004664}
Mike Stump1eb44332009-09-09 15:08:12 +00004665
Douglas Gregor43959a92009-08-20 07:17:43 +00004666template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004667StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004668TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004669 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004670 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004671 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004672 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004673
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004674 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004675 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004676 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004677 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004678
Douglas Gregor43959a92009-08-20 07:17:43 +00004679 if (!getDerived().AlwaysRebuild() &&
4680 Cond.get() == S->getCond() &&
4681 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004682 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004683
John McCall9ae2f072010-08-23 23:25:46 +00004684 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4685 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004686 S->getRParenLoc());
4687}
Mike Stump1eb44332009-09-09 15:08:12 +00004688
Douglas Gregor43959a92009-08-20 07:17:43 +00004689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004690StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004691TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004692 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004693 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004694 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004695 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004696
Douglas Gregor43959a92009-08-20 07:17:43 +00004697 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004698 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004699 VarDecl *ConditionVar = 0;
4700 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004701 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004702 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004703 getDerived().TransformDefinition(
4704 S->getConditionVariable()->getLocation(),
4705 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004706 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004707 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004708 } else {
4709 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004710
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004711 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004712 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004713
4714 if (S->getCond()) {
4715 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004716 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4717 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004718 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004719 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004720
John McCall9ae2f072010-08-23 23:25:46 +00004721 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004722 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004723 }
Mike Stump1eb44332009-09-09 15:08:12 +00004724
John McCall9ae2f072010-08-23 23:25:46 +00004725 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4726 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004727 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004728
Douglas Gregor43959a92009-08-20 07:17:43 +00004729 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004730 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004731 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004732 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004733
John McCall9ae2f072010-08-23 23:25:46 +00004734 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4735 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004736 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004737
Douglas Gregor43959a92009-08-20 07:17:43 +00004738 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004739 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004740 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004741 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004742
Douglas Gregor43959a92009-08-20 07:17:43 +00004743 if (!getDerived().AlwaysRebuild() &&
4744 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004745 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004746 Inc.get() == S->getInc() &&
4747 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004748 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004749
Douglas Gregor43959a92009-08-20 07:17:43 +00004750 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004751 Init.get(), FullCond, ConditionVar,
4752 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004753}
4754
4755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004756StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004757TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004758 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004759 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004760 S->getLabel());
4761}
4762
4763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004764StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004765TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004766 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004767 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004768 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004769
Douglas Gregor43959a92009-08-20 07:17:43 +00004770 if (!getDerived().AlwaysRebuild() &&
4771 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004772 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004773
4774 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004775 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004776}
4777
4778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004779StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004780TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004781 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004782}
Mike Stump1eb44332009-09-09 15:08:12 +00004783
Douglas Gregor43959a92009-08-20 07:17:43 +00004784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004785StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004786TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004787 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004788}
Mike Stump1eb44332009-09-09 15:08:12 +00004789
Douglas Gregor43959a92009-08-20 07:17:43 +00004790template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004791StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004792TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004793 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004794 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004795 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004796
Mike Stump1eb44332009-09-09 15:08:12 +00004797 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004798 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004799 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004800}
Mike Stump1eb44332009-09-09 15:08:12 +00004801
Douglas Gregor43959a92009-08-20 07:17:43 +00004802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004803StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004804TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004805 bool DeclChanged = false;
4806 llvm::SmallVector<Decl *, 4> Decls;
4807 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4808 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004809 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4810 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004811 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004812 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004813
Douglas Gregor43959a92009-08-20 07:17:43 +00004814 if (Transformed != *D)
4815 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004816
Douglas Gregor43959a92009-08-20 07:17:43 +00004817 Decls.push_back(Transformed);
4818 }
Mike Stump1eb44332009-09-09 15:08:12 +00004819
Douglas Gregor43959a92009-08-20 07:17:43 +00004820 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004821 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004822
4823 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004824 S->getStartLoc(), S->getEndLoc());
4825}
Mike Stump1eb44332009-09-09 15:08:12 +00004826
Douglas Gregor43959a92009-08-20 07:17:43 +00004827template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004828StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004829TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004830
John McCallca0408f2010-08-23 06:44:23 +00004831 ASTOwningVector<Expr*> Constraints(getSema());
4832 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004833 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004834
John McCall60d7b3a2010-08-24 06:29:42 +00004835 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004836 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004837
4838 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004839
Anders Carlsson703e3942010-01-24 05:50:09 +00004840 // Go through the outputs.
4841 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004842 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004843
Anders Carlsson703e3942010-01-24 05:50:09 +00004844 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004845 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004846
Anders Carlsson703e3942010-01-24 05:50:09 +00004847 // Transform the output expr.
4848 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004849 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004850 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004851 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004852
Anders Carlsson703e3942010-01-24 05:50:09 +00004853 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004854
John McCall9ae2f072010-08-23 23:25:46 +00004855 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004856 }
Sean Huntc3021132010-05-05 15:23:54 +00004857
Anders Carlsson703e3942010-01-24 05:50:09 +00004858 // Go through the inputs.
4859 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004860 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004861
Anders Carlsson703e3942010-01-24 05:50:09 +00004862 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004863 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004864
Anders Carlsson703e3942010-01-24 05:50:09 +00004865 // Transform the input expr.
4866 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004867 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004868 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004869 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004870
Anders Carlsson703e3942010-01-24 05:50:09 +00004871 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004872
John McCall9ae2f072010-08-23 23:25:46 +00004873 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004874 }
Sean Huntc3021132010-05-05 15:23:54 +00004875
Anders Carlsson703e3942010-01-24 05:50:09 +00004876 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004877 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004878
4879 // Go through the clobbers.
4880 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004881 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004882
4883 // No need to transform the asm string literal.
4884 AsmString = SemaRef.Owned(S->getAsmString());
4885
4886 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4887 S->isSimple(),
4888 S->isVolatile(),
4889 S->getNumOutputs(),
4890 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004891 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004892 move_arg(Constraints),
4893 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004894 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004895 move_arg(Clobbers),
4896 S->getRParenLoc(),
4897 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004898}
4899
4900
4901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004902StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004903TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004904 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004905 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004906 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004907 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004908
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004909 // Transform the @catch statements (if present).
4910 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004911 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004912 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004913 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004914 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004915 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004916 if (Catch.get() != S->getCatchStmt(I))
4917 AnyCatchChanged = true;
4918 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004919 }
Sean Huntc3021132010-05-05 15:23:54 +00004920
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004921 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004922 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004923 if (S->getFinallyStmt()) {
4924 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4925 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004926 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004927 }
4928
4929 // If nothing changed, just retain this statement.
4930 if (!getDerived().AlwaysRebuild() &&
4931 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004932 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004933 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004934 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004935
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004936 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004937 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4938 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004939}
Mike Stump1eb44332009-09-09 15:08:12 +00004940
Douglas Gregor43959a92009-08-20 07:17:43 +00004941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004942StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004943TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004944 // Transform the @catch parameter, if there is one.
4945 VarDecl *Var = 0;
4946 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4947 TypeSourceInfo *TSInfo = 0;
4948 if (FromVar->getTypeSourceInfo()) {
4949 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4950 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004951 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004952 }
Sean Huntc3021132010-05-05 15:23:54 +00004953
Douglas Gregorbe270a02010-04-26 17:57:08 +00004954 QualType T;
4955 if (TSInfo)
4956 T = TSInfo->getType();
4957 else {
4958 T = getDerived().TransformType(FromVar->getType());
4959 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004960 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004961 }
Sean Huntc3021132010-05-05 15:23:54 +00004962
Douglas Gregorbe270a02010-04-26 17:57:08 +00004963 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4964 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004965 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004966 }
Sean Huntc3021132010-05-05 15:23:54 +00004967
John McCall60d7b3a2010-08-24 06:29:42 +00004968 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004969 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004970 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004971
4972 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004973 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004974 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004975}
Mike Stump1eb44332009-09-09 15:08:12 +00004976
Douglas Gregor43959a92009-08-20 07:17:43 +00004977template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004978StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004979TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004980 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004981 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004982 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004983 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004984
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004985 // If nothing changed, just retain this statement.
4986 if (!getDerived().AlwaysRebuild() &&
4987 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004988 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004989
4990 // Build a new statement.
4991 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004992 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004993}
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Douglas Gregor43959a92009-08-20 07:17:43 +00004995template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004996StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004997TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004998 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004999 if (S->getThrowExpr()) {
5000 Operand = getDerived().TransformExpr(S->getThrowExpr());
5001 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005002 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005003 }
Sean Huntc3021132010-05-05 15:23:54 +00005004
Douglas Gregord1377b22010-04-22 21:44:01 +00005005 if (!getDerived().AlwaysRebuild() &&
5006 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005007 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005008
John McCall9ae2f072010-08-23 23:25:46 +00005009 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005010}
Mike Stump1eb44332009-09-09 15:08:12 +00005011
Douglas Gregor43959a92009-08-20 07:17:43 +00005012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005013StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005014TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005015 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005016 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005017 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005018 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005019 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005020
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005021 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005022 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005023 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005024 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005025
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005026 // If nothing change, just retain the current statement.
5027 if (!getDerived().AlwaysRebuild() &&
5028 Object.get() == S->getSynchExpr() &&
5029 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005030 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005031
5032 // Build a new statement.
5033 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005034 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005035}
5036
5037template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005038StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005039TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005040 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005041 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005042 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005043 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005044 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005045
Douglas Gregorc3203e72010-04-22 23:10:45 +00005046 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005047 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005048 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005049 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005050
Douglas Gregorc3203e72010-04-22 23:10:45 +00005051 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005052 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005053 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005054 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005055
Douglas Gregorc3203e72010-04-22 23:10:45 +00005056 // If nothing changed, just retain this statement.
5057 if (!getDerived().AlwaysRebuild() &&
5058 Element.get() == S->getElement() &&
5059 Collection.get() == S->getCollection() &&
5060 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005061 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005062
Douglas Gregorc3203e72010-04-22 23:10:45 +00005063 // Build a new statement.
5064 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5065 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005066 Element.get(),
5067 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005068 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005069 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005070}
5071
5072
5073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005074StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005075TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5076 // Transform the exception declaration, if any.
5077 VarDecl *Var = 0;
5078 if (S->getExceptionDecl()) {
5079 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005080 TypeSourceInfo *T = getDerived().TransformType(
5081 ExceptionDecl->getTypeSourceInfo());
5082 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005083 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005084
Douglas Gregor83cb9422010-09-09 17:09:21 +00005085 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005087 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005088 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005089 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005090 }
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregor43959a92009-08-20 07:17:43 +00005092 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005093 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005094 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005095 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 if (!getDerived().AlwaysRebuild() &&
5098 !Var &&
5099 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005100 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005101
5102 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5103 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005104 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005105}
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregor43959a92009-08-20 07:17:43 +00005107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005108StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005109TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5110 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005111 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 = getDerived().TransformCompoundStmt(S->getTryBlock());
5113 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005114 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 // Transform the handlers.
5117 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005118 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005120 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5122 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005123 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5126 Handlers.push_back(Handler.takeAs<Stmt>());
5127 }
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregor43959a92009-08-20 07:17:43 +00005129 if (!getDerived().AlwaysRebuild() &&
5130 TryBlock.get() == S->getTryBlock() &&
5131 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005132 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005133
John McCall9ae2f072010-08-23 23:25:46 +00005134 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005135 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005136}
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005139// Expression transformation
5140//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005142ExprResult
John McCall454feb92009-12-08 09:21:05 +00005143TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005144 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005145}
Mike Stump1eb44332009-09-09 15:08:12 +00005146
5147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005148ExprResult
John McCall454feb92009-12-08 09:21:05 +00005149TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005150 NestedNameSpecifier *Qualifier = 0;
5151 if (E->getQualifier()) {
5152 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005153 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005154 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005155 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005156 }
John McCalldbd872f2009-12-08 09:08:17 +00005157
5158 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005159 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5160 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005162 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005163
John McCallec8045d2010-08-17 21:27:17 +00005164 DeclarationNameInfo NameInfo = E->getNameInfo();
5165 if (NameInfo.getName()) {
5166 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5167 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005168 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005169 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005170
5171 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005172 Qualifier == E->getQualifier() &&
5173 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005174 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005175 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005176
5177 // Mark it referenced in the new context regardless.
5178 // FIXME: this is a bit instantiation-specific.
5179 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5180
John McCall3fa5cae2010-10-26 07:05:15 +00005181 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005182 }
John McCalldbd872f2009-12-08 09:08:17 +00005183
5184 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005185 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005186 TemplateArgs = &TransArgs;
5187 TransArgs.setLAngleLoc(E->getLAngleLoc());
5188 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005189 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5190 E->getNumTemplateArgs(),
5191 TransArgs))
5192 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005193 }
5194
Douglas Gregora2813ce2009-10-23 18:54:35 +00005195 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005196 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005197}
Mike Stump1eb44332009-09-09 15:08:12 +00005198
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005200ExprResult
John McCall454feb92009-12-08 09:21:05 +00005201TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005202 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203}
Mike Stump1eb44332009-09-09 15:08:12 +00005204
Douglas Gregorb98b1992009-08-11 05:31:07 +00005205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005206ExprResult
John McCall454feb92009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005208 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209}
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005212ExprResult
John McCall454feb92009-12-08 09:21:05 +00005213TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005214 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005215}
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregorb98b1992009-08-11 05:31:07 +00005217template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005218ExprResult
John McCall454feb92009-12-08 09:21:05 +00005219TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005220 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221}
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005224ExprResult
John McCall454feb92009-12-08 09:21:05 +00005225TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005226 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005227}
5228
5229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005230ExprResult
John McCall454feb92009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005232 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005234 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005235
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005237 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005238
John McCall9ae2f072010-08-23 23:25:46 +00005239 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005240 E->getRParen());
5241}
5242
Mike Stump1eb44332009-09-09 15:08:12 +00005243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005244ExprResult
John McCall454feb92009-12-08 09:21:05 +00005245TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregorb98b1992009-08-11 05:31:07 +00005250 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005251 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005252
Douglas Gregorb98b1992009-08-11 05:31:07 +00005253 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5254 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005255 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005256}
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregorb98b1992009-08-11 05:31:07 +00005258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005259ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005260TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5261 // Transform the type.
5262 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5263 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005264 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005265
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005266 // Transform all of the components into components similar to what the
5267 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005268 // FIXME: It would be slightly more efficient in the non-dependent case to
5269 // just map FieldDecls, rather than requiring the rebuilder to look for
5270 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005271 // template code that we don't care.
5272 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005273 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005274 typedef OffsetOfExpr::OffsetOfNode Node;
5275 llvm::SmallVector<Component, 4> Components;
5276 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5277 const Node &ON = E->getComponent(I);
5278 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005279 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005280 Comp.LocStart = ON.getRange().getBegin();
5281 Comp.LocEnd = ON.getRange().getEnd();
5282 switch (ON.getKind()) {
5283 case Node::Array: {
5284 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005286 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005287 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005288
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005289 ExprChanged = ExprChanged || Index.get() != FromIndex;
5290 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005291 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005292 break;
5293 }
Sean Huntc3021132010-05-05 15:23:54 +00005294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005295 case Node::Field:
5296 case Node::Identifier:
5297 Comp.isBrackets = false;
5298 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005299 if (!Comp.U.IdentInfo)
5300 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005301
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005302 break;
Sean Huntc3021132010-05-05 15:23:54 +00005303
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005304 case Node::Base:
5305 // Will be recomputed during the rebuild.
5306 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005307 }
Sean Huntc3021132010-05-05 15:23:54 +00005308
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005309 Components.push_back(Comp);
5310 }
Sean Huntc3021132010-05-05 15:23:54 +00005311
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005312 // If nothing changed, retain the existing expression.
5313 if (!getDerived().AlwaysRebuild() &&
5314 Type == E->getTypeSourceInfo() &&
5315 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005316 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005317
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005318 // Build a new offsetof expression.
5319 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5320 Components.data(), Components.size(),
5321 E->getRParenLoc());
5322}
5323
5324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005325ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005326TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5327 assert(getDerived().AlreadyTransformed(E->getType()) &&
5328 "opaque value expression requires transformation");
5329 return SemaRef.Owned(E);
5330}
5331
5332template<typename Derived>
5333ExprResult
John McCall454feb92009-12-08 09:21:05 +00005334TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005335 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005336 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005337
John McCalla93c9342009-12-07 02:54:59 +00005338 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005339 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005341
John McCall5ab75172009-11-04 07:28:41 +00005342 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005343 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005344
John McCall5ab75172009-11-04 07:28:41 +00005345 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005346 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005347 E->getSourceRange());
5348 }
Mike Stump1eb44332009-09-09 15:08:12 +00005349
John McCall60d7b3a2010-08-24 06:29:42 +00005350 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005351 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005352 // C++0x [expr.sizeof]p1:
5353 // The operand is either an expression, which is an unevaluated operand
5354 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005355 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregorb98b1992009-08-11 05:31:07 +00005357 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5358 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005359 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005360
Douglas Gregorb98b1992009-08-11 05:31:07 +00005361 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005362 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363 }
Mike Stump1eb44332009-09-09 15:08:12 +00005364
John McCall9ae2f072010-08-23 23:25:46 +00005365 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005366 E->isSizeOf(),
5367 E->getSourceRange());
5368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregorb98b1992009-08-11 05:31:07 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371ExprResult
John McCall454feb92009-12-08 09:21:05 +00005372TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005373 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005374 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005375 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005376
John McCall60d7b3a2010-08-24 06:29:42 +00005377 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005378 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005379 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005380
5381
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382 if (!getDerived().AlwaysRebuild() &&
5383 LHS.get() == E->getLHS() &&
5384 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005385 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005386
John McCall9ae2f072010-08-23 23:25:46 +00005387 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005388 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005389 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005390 E->getRBracketLoc());
5391}
Mike Stump1eb44332009-09-09 15:08:12 +00005392
5393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005394ExprResult
John McCall454feb92009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005396 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005398 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005400
5401 // Transform arguments.
5402 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005403 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005404 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5405 &ArgChanged))
5406 return ExprError();
5407
Douglas Gregorb98b1992009-08-11 05:31:07 +00005408 if (!getDerived().AlwaysRebuild() &&
5409 Callee.get() == E->getCallee() &&
5410 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005411 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregorb98b1992009-08-11 05:31:07 +00005413 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005414 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005415 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005416 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005417 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005418 E->getRParenLoc());
5419}
Mike Stump1eb44332009-09-09 15:08:12 +00005420
5421template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005422ExprResult
John McCall454feb92009-12-08 09:21:05 +00005423TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005424 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005425 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005426 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005427
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005428 NestedNameSpecifier *Qualifier = 0;
5429 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005430 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005431 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005432 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005433 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005434 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005435 }
Mike Stump1eb44332009-09-09 15:08:12 +00005436
Eli Friedmanf595cc42009-12-04 06:40:45 +00005437 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005438 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5439 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005440 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005441 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005442
John McCall6bb80172010-03-30 21:47:33 +00005443 NamedDecl *FoundDecl = E->getFoundDecl();
5444 if (FoundDecl == E->getMemberDecl()) {
5445 FoundDecl = Member;
5446 } else {
5447 FoundDecl = cast_or_null<NamedDecl>(
5448 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5449 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005450 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005451 }
5452
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453 if (!getDerived().AlwaysRebuild() &&
5454 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005455 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005456 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005457 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005458 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005459
Anders Carlsson1f240322009-12-22 05:24:09 +00005460 // Mark it referenced in the new context regardless.
5461 // FIXME: this is a bit instantiation-specific.
5462 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005463 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005464 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005465
John McCalld5532b62009-11-23 01:53:49 +00005466 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005467 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005468 TransArgs.setLAngleLoc(E->getLAngleLoc());
5469 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005470 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5471 E->getNumTemplateArgs(),
5472 TransArgs))
5473 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005474 }
Sean Huntc3021132010-05-05 15:23:54 +00005475
Douglas Gregorb98b1992009-08-11 05:31:07 +00005476 // FIXME: Bogus source location for the operator
5477 SourceLocation FakeOperatorLoc
5478 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5479
John McCallc2233c52010-01-15 08:34:02 +00005480 // FIXME: to do this check properly, we will need to preserve the
5481 // first-qualifier-in-scope here, just in case we had a dependent
5482 // base (and therefore couldn't do the check) and a
5483 // nested-name-qualifier (and therefore could do the lookup).
5484 NamedDecl *FirstQualifierInScope = 0;
5485
John McCall9ae2f072010-08-23 23:25:46 +00005486 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005487 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005488 Qualifier,
5489 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005490 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005491 Member,
John McCall6bb80172010-03-30 21:47:33 +00005492 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005493 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005494 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005495 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005496}
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregorb98b1992009-08-11 05:31:07 +00005498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499ExprResult
John McCall454feb92009-12-08 09:21:05 +00005500TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005501 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005502 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005503 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005504
John McCall60d7b3a2010-08-24 06:29:42 +00005505 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005506 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005507 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509 if (!getDerived().AlwaysRebuild() &&
5510 LHS.get() == E->getLHS() &&
5511 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005512 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005513
Douglas Gregorb98b1992009-08-11 05:31:07 +00005514 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005515 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005516}
5517
Mike Stump1eb44332009-09-09 15:08:12 +00005518template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005519ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005520TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005521 CompoundAssignOperator *E) {
5522 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005523}
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregorb98b1992009-08-11 05:31:07 +00005525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005526ExprResult
John McCall454feb92009-12-08 09:21:05 +00005527TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005528 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005529 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005531
John McCall60d7b3a2010-08-24 06:29:42 +00005532 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005533 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005534 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005535
John McCall60d7b3a2010-08-24 06:29:42 +00005536 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005537 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005539
Douglas Gregorb98b1992009-08-11 05:31:07 +00005540 if (!getDerived().AlwaysRebuild() &&
5541 Cond.get() == E->getCond() &&
5542 LHS.get() == E->getLHS() &&
5543 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005544 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005545
John McCall9ae2f072010-08-23 23:25:46 +00005546 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005547 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005548 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005549 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005550 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551}
Mike Stump1eb44332009-09-09 15:08:12 +00005552
5553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005554ExprResult
John McCall454feb92009-12-08 09:21:05 +00005555TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005556 // Implicit casts are eliminated during transformation, since they
5557 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005558 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559}
Mike Stump1eb44332009-09-09 15:08:12 +00005560
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005562ExprResult
John McCall454feb92009-12-08 09:21:05 +00005563TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005564 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5565 if (!Type)
5566 return ExprError();
5567
John McCall60d7b3a2010-08-24 06:29:42 +00005568 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005569 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005570 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005571 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005572
Douglas Gregorb98b1992009-08-11 05:31:07 +00005573 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005574 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005575 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005576 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005577
John McCall9d125032010-01-15 18:39:57 +00005578 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005579 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005580 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005581 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005582}
Mike Stump1eb44332009-09-09 15:08:12 +00005583
Douglas Gregorb98b1992009-08-11 05:31:07 +00005584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005585ExprResult
John McCall454feb92009-12-08 09:21:05 +00005586TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005587 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5588 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5589 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005590 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005591
John McCall60d7b3a2010-08-24 06:29:42 +00005592 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005593 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005594 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005595
Douglas Gregorb98b1992009-08-11 05:31:07 +00005596 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005597 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005598 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005599 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005600
John McCall1d7d8d62010-01-19 22:33:45 +00005601 // Note: the expression type doesn't necessarily match the
5602 // type-as-written, but that's okay, because it should always be
5603 // derivable from the initializer.
5604
John McCall42f56b52010-01-18 19:35:47 +00005605 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005606 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005607 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608}
Mike Stump1eb44332009-09-09 15:08:12 +00005609
Douglas Gregorb98b1992009-08-11 05:31:07 +00005610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005611ExprResult
John McCall454feb92009-12-08 09:21:05 +00005612TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005613 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005614 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005615 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005616
Douglas Gregorb98b1992009-08-11 05:31:07 +00005617 if (!getDerived().AlwaysRebuild() &&
5618 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005619 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005620
Douglas Gregorb98b1992009-08-11 05:31:07 +00005621 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005622 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005624 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 E->getAccessorLoc(),
5626 E->getAccessor());
5627}
Mike Stump1eb44332009-09-09 15:08:12 +00005628
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005630ExprResult
John McCall454feb92009-12-08 09:21:05 +00005631TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005633
John McCallca0408f2010-08-23 06:44:23 +00005634 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005635 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5636 Inits, &InitChanged))
5637 return ExprError();
5638
Douglas Gregorb98b1992009-08-11 05:31:07 +00005639 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005640 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005641
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005643 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644}
Mike Stump1eb44332009-09-09 15:08:12 +00005645
Douglas Gregorb98b1992009-08-11 05:31:07 +00005646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005647ExprResult
John McCall454feb92009-12-08 09:21:05 +00005648TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005649 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005650
Douglas Gregor43959a92009-08-20 07:17:43 +00005651 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005652 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregor43959a92009-08-20 07:17:43 +00005656 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005657 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658 bool ExprChanged = false;
5659 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5660 DEnd = E->designators_end();
5661 D != DEnd; ++D) {
5662 if (D->isFieldDesignator()) {
5663 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5664 D->getDotLoc(),
5665 D->getFieldLoc()));
5666 continue;
5667 }
Mike Stump1eb44332009-09-09 15:08:12 +00005668
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005670 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005671 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005673
5674 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5678 ArrayExprs.push_back(Index.release());
5679 continue;
5680 }
Mike Stump1eb44332009-09-09 15:08:12 +00005681
Douglas Gregorb98b1992009-08-11 05:31:07 +00005682 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005683 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5685 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005686 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005687
John McCall60d7b3a2010-08-24 06:29:42 +00005688 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005689 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005690 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005691
5692 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005693 End.get(),
5694 D->getLBracketLoc(),
5695 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5698 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700 ArrayExprs.push_back(Start.release());
5701 ArrayExprs.push_back(End.release());
5702 }
Mike Stump1eb44332009-09-09 15:08:12 +00005703
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704 if (!getDerived().AlwaysRebuild() &&
5705 Init.get() == E->getInit() &&
5706 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005707 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5710 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005711 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712}
Mike Stump1eb44332009-09-09 15:08:12 +00005713
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005715ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005717 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005718 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005719
Douglas Gregor5557b252009-10-28 00:29:27 +00005720 // FIXME: Will we ever have proper type location here? Will we actually
5721 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005722 QualType T = getDerived().TransformType(E->getType());
5723 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregorb98b1992009-08-11 05:31:07 +00005726 if (!getDerived().AlwaysRebuild() &&
5727 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005728 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005729
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 return getDerived().RebuildImplicitValueInitExpr(T);
5731}
Mike Stump1eb44332009-09-09 15:08:12 +00005732
Douglas Gregorb98b1992009-08-11 05:31:07 +00005733template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005734ExprResult
John McCall454feb92009-12-08 09:21:05 +00005735TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005736 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5737 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005739
John McCall60d7b3a2010-08-24 06:29:42 +00005740 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005741 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005742 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005743
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005745 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005747 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005748
John McCall9ae2f072010-08-23 23:25:46 +00005749 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005750 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751}
5752
5753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005754ExprResult
John McCall454feb92009-12-08 09:21:05 +00005755TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005756 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005757 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005758 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5759 &ArgumentChanged))
5760 return ExprError();
5761
Douglas Gregorb98b1992009-08-11 05:31:07 +00005762 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5763 move_arg(Inits),
5764 E->getRParenLoc());
5765}
Mike Stump1eb44332009-09-09 15:08:12 +00005766
Douglas Gregorb98b1992009-08-11 05:31:07 +00005767/// \brief Transform an address-of-label expression.
5768///
5769/// By default, the transformation of an address-of-label expression always
5770/// rebuilds the expression, so that the label identifier can be resolved to
5771/// the corresponding label statement by semantic analysis.
5772template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005773ExprResult
John McCall454feb92009-12-08 09:21:05 +00005774TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5776 E->getLabel());
5777}
Mike Stump1eb44332009-09-09 15:08:12 +00005778
5779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005780ExprResult
John McCall454feb92009-12-08 09:21:05 +00005781TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005782 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005783 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5784 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005785 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 if (!getDerived().AlwaysRebuild() &&
5788 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005789 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005790
5791 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005792 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 E->getRParenLoc());
5794}
Mike Stump1eb44332009-09-09 15:08:12 +00005795
Douglas Gregorb98b1992009-08-11 05:31:07 +00005796template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005797ExprResult
John McCall454feb92009-12-08 09:21:05 +00005798TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005799 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005800 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005801 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005802
John McCall60d7b3a2010-08-24 06:29:42 +00005803 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005805 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005806
John McCall60d7b3a2010-08-24 06:29:42 +00005807 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005808 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005810
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811 if (!getDerived().AlwaysRebuild() &&
5812 Cond.get() == E->getCond() &&
5813 LHS.get() == E->getLHS() &&
5814 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005815 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005816
Douglas Gregorb98b1992009-08-11 05:31:07 +00005817 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005818 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819 E->getRParenLoc());
5820}
Mike Stump1eb44332009-09-09 15:08:12 +00005821
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005823ExprResult
John McCall454feb92009-12-08 09:21:05 +00005824TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005825 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005826}
5827
5828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005829ExprResult
John McCall454feb92009-12-08 09:21:05 +00005830TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005831 switch (E->getOperator()) {
5832 case OO_New:
5833 case OO_Delete:
5834 case OO_Array_New:
5835 case OO_Array_Delete:
5836 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005837 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005838
Douglas Gregor668d6d92009-12-13 20:44:55 +00005839 case OO_Call: {
5840 // This is a call to an object's operator().
5841 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5842
5843 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005844 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005845 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005846 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005847
5848 // FIXME: Poor location information
5849 SourceLocation FakeLParenLoc
5850 = SemaRef.PP.getLocForEndOfToken(
5851 static_cast<Expr *>(Object.get())->getLocEnd());
5852
5853 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005854 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005855 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5856 Args))
5857 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005858
John McCall9ae2f072010-08-23 23:25:46 +00005859 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005860 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005861 E->getLocEnd());
5862 }
5863
5864#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5865 case OO_##Name:
5866#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5867#include "clang/Basic/OperatorKinds.def"
5868 case OO_Subscript:
5869 // Handled below.
5870 break;
5871
5872 case OO_Conditional:
5873 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005874 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005875
5876 case OO_None:
5877 case NUM_OVERLOADED_OPERATORS:
5878 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005879 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005880 }
5881
John McCall60d7b3a2010-08-24 06:29:42 +00005882 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005883 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005884 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005885
John McCall60d7b3a2010-08-24 06:29:42 +00005886 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005887 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005888 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005889
John McCall60d7b3a2010-08-24 06:29:42 +00005890 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005891 if (E->getNumArgs() == 2) {
5892 Second = getDerived().TransformExpr(E->getArg(1));
5893 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005894 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005895 }
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 if (!getDerived().AlwaysRebuild() &&
5898 Callee.get() == E->getCallee() &&
5899 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005900 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005901 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005902
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5904 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005905 Callee.get(),
5906 First.get(),
5907 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005908}
Mike Stump1eb44332009-09-09 15:08:12 +00005909
Douglas Gregorb98b1992009-08-11 05:31:07 +00005910template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005911ExprResult
John McCall454feb92009-12-08 09:21:05 +00005912TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5913 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005914}
Mike Stump1eb44332009-09-09 15:08:12 +00005915
Douglas Gregorb98b1992009-08-11 05:31:07 +00005916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005917ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00005918TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
5919 // Transform the callee.
5920 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5921 if (Callee.isInvalid())
5922 return ExprError();
5923
5924 // Transform exec config.
5925 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
5926 if (EC.isInvalid())
5927 return ExprError();
5928
5929 // Transform arguments.
5930 bool ArgChanged = false;
5931 ASTOwningVector<Expr*> Args(SemaRef);
5932 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5933 &ArgChanged))
5934 return ExprError();
5935
5936 if (!getDerived().AlwaysRebuild() &&
5937 Callee.get() == E->getCallee() &&
5938 !ArgChanged)
5939 return SemaRef.Owned(E);
5940
5941 // FIXME: Wrong source location information for the '('.
5942 SourceLocation FakeLParenLoc
5943 = ((Expr *)Callee.get())->getSourceRange().getBegin();
5944 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
5945 move_arg(Args),
5946 E->getRParenLoc(), EC.get());
5947}
5948
5949template<typename Derived>
5950ExprResult
John McCall454feb92009-12-08 09:21:05 +00005951TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005952 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5953 if (!Type)
5954 return ExprError();
5955
John McCall60d7b3a2010-08-24 06:29:42 +00005956 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005957 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005958 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005959 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005960
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005962 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005963 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005964 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005965
Douglas Gregorb98b1992009-08-11 05:31:07 +00005966 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005967 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005968 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5969 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5970 SourceLocation FakeRParenLoc
5971 = SemaRef.PP.getLocForEndOfToken(
5972 E->getSubExpr()->getSourceRange().getEnd());
5973 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005974 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005975 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005976 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005977 FakeRAngleLoc,
5978 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005979 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005980 FakeRParenLoc);
5981}
Mike Stump1eb44332009-09-09 15:08:12 +00005982
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005984ExprResult
John McCall454feb92009-12-08 09:21:05 +00005985TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5986 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005987}
Mike Stump1eb44332009-09-09 15:08:12 +00005988
5989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005990ExprResult
John McCall454feb92009-12-08 09:21:05 +00005991TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5992 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005993}
5994
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005996ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005998 CXXReinterpretCastExpr *E) {
5999 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000}
Mike Stump1eb44332009-09-09 15:08:12 +00006001
Douglas Gregorb98b1992009-08-11 05:31:07 +00006002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006003ExprResult
John McCall454feb92009-12-08 09:21:05 +00006004TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6005 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006006}
Mike Stump1eb44332009-09-09 15:08:12 +00006007
Douglas Gregorb98b1992009-08-11 05:31:07 +00006008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006009ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006010TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006011 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006012 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6013 if (!Type)
6014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006015
John McCall60d7b3a2010-08-24 06:29:42 +00006016 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006017 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006018 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006019 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006020
Douglas Gregorb98b1992009-08-11 05:31:07 +00006021 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006022 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006023 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006024 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006025
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006026 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006027 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006028 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029 E->getRParenLoc());
6030}
Mike Stump1eb44332009-09-09 15:08:12 +00006031
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006033ExprResult
John McCall454feb92009-12-08 09:21:05 +00006034TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006035 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006036 TypeSourceInfo *TInfo
6037 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6038 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006039 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006040
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006042 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006043 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006044
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006045 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6046 E->getLocStart(),
6047 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006048 E->getLocEnd());
6049 }
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051 // We don't know whether the expression is potentially evaluated until
6052 // after we perform semantic analysis, so the expression is potentially
6053 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006054 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006055 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006056
John McCall60d7b3a2010-08-24 06:29:42 +00006057 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006059 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006060
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061 if (!getDerived().AlwaysRebuild() &&
6062 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006063 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006064
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006065 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6066 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006067 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068 E->getLocEnd());
6069}
6070
6071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006072ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006073TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6074 if (E->isTypeOperand()) {
6075 TypeSourceInfo *TInfo
6076 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6077 if (!TInfo)
6078 return ExprError();
6079
6080 if (!getDerived().AlwaysRebuild() &&
6081 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006082 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006083
6084 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6085 E->getLocStart(),
6086 TInfo,
6087 E->getLocEnd());
6088 }
6089
6090 // We don't know whether the expression is potentially evaluated until
6091 // after we perform semantic analysis, so the expression is potentially
6092 // potentially evaluated.
6093 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6094
6095 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6096 if (SubExpr.isInvalid())
6097 return ExprError();
6098
6099 if (!getDerived().AlwaysRebuild() &&
6100 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006101 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006102
6103 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6104 E->getLocStart(),
6105 SubExpr.get(),
6106 E->getLocEnd());
6107}
6108
6109template<typename Derived>
6110ExprResult
John McCall454feb92009-12-08 09:21:05 +00006111TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113}
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006116ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006118 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120}
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006123ExprResult
John McCall454feb92009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006125 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6126 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6127 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006129 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006130 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006131
Douglas Gregor828a1972010-01-07 23:12:05 +00006132 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133}
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCall454feb92009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006138 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006140 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006141
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 if (!getDerived().AlwaysRebuild() &&
6143 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006144 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145
John McCall9ae2f072010-08-23 23:25:46 +00006146 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006147}
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006150ExprResult
John McCall454feb92009-12-08 09:21:05 +00006151TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006152 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006153 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6154 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006156 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006157
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006158 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006161
Douglas Gregor036aed12009-12-23 23:03:06 +00006162 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163}
Mike Stump1eb44332009-09-09 15:08:12 +00006164
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006166ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006167TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6168 CXXScalarValueInitExpr *E) {
6169 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6170 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006171 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006172
Douglas Gregorb98b1992009-08-11 05:31:07 +00006173 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006174 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006175 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006176
Douglas Gregorab6677e2010-09-08 00:15:04 +00006177 return getDerived().RebuildCXXScalarValueInitExpr(T,
6178 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006179 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180}
Mike Stump1eb44332009-09-09 15:08:12 +00006181
Douglas Gregorb98b1992009-08-11 05:31:07 +00006182template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006183ExprResult
John McCall454feb92009-12-08 09:21:05 +00006184TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006186 TypeSourceInfo *AllocTypeInfo
6187 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6188 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006189 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006190
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006192 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006194 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006195
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 // Transform the placement arguments (if any).
6197 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006198 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006199 if (getDerived().TransformExprs(E->getPlacementArgs(),
6200 E->getNumPlacementArgs(), true,
6201 PlacementArgs, &ArgumentChanged))
6202 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Douglas Gregor43959a92009-08-20 07:17:43 +00006204 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006205 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006206 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6207 ConstructorArgs, &ArgumentChanged))
6208 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006209
Douglas Gregor1af74512010-02-26 00:38:10 +00006210 // Transform constructor, new operator, and delete operator.
6211 CXXConstructorDecl *Constructor = 0;
6212 if (E->getConstructor()) {
6213 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006214 getDerived().TransformDecl(E->getLocStart(),
6215 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006216 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006217 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006218 }
6219
6220 FunctionDecl *OperatorNew = 0;
6221 if (E->getOperatorNew()) {
6222 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006223 getDerived().TransformDecl(E->getLocStart(),
6224 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006225 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006226 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006227 }
6228
6229 FunctionDecl *OperatorDelete = 0;
6230 if (E->getOperatorDelete()) {
6231 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006232 getDerived().TransformDecl(E->getLocStart(),
6233 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006234 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006235 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006236 }
Sean Huntc3021132010-05-05 15:23:54 +00006237
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006239 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006241 Constructor == E->getConstructor() &&
6242 OperatorNew == E->getOperatorNew() &&
6243 OperatorDelete == E->getOperatorDelete() &&
6244 !ArgumentChanged) {
6245 // Mark any declarations we need as referenced.
6246 // FIXME: instantiation-specific.
6247 if (Constructor)
6248 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6249 if (OperatorNew)
6250 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6251 if (OperatorDelete)
6252 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006253 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006254 }
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006256 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006257 if (!ArraySize.get()) {
6258 // If no array size was specified, but the new expression was
6259 // instantiated with an array type (e.g., "new T" where T is
6260 // instantiated with "int[4]"), extract the outer bound from the
6261 // array type as our array size. We do this with constant and
6262 // dependently-sized array types.
6263 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6264 if (!ArrayT) {
6265 // Do nothing
6266 } else if (const ConstantArrayType *ConsArrayT
6267 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006268 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006269 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6270 ConsArrayT->getSize(),
6271 SemaRef.Context.getSizeType(),
6272 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006273 AllocType = ConsArrayT->getElementType();
6274 } else if (const DependentSizedArrayType *DepArrayT
6275 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6276 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006277 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006278 AllocType = DepArrayT->getElementType();
6279 }
6280 }
6281 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006282
Douglas Gregorb98b1992009-08-11 05:31:07 +00006283 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6284 E->isGlobalNew(),
6285 /*FIXME:*/E->getLocStart(),
6286 move_arg(PlacementArgs),
6287 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006288 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006290 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006291 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006292 /*FIXME:*/E->getLocStart(),
6293 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006294 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295}
Mike Stump1eb44332009-09-09 15:08:12 +00006296
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006298ExprResult
John McCall454feb92009-12-08 09:21:05 +00006299TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006300 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006302 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006303
Douglas Gregor1af74512010-02-26 00:38:10 +00006304 // Transform the delete operator, if known.
6305 FunctionDecl *OperatorDelete = 0;
6306 if (E->getOperatorDelete()) {
6307 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006308 getDerived().TransformDecl(E->getLocStart(),
6309 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006310 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006311 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006312 }
Sean Huntc3021132010-05-05 15:23:54 +00006313
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006315 Operand.get() == E->getArgument() &&
6316 OperatorDelete == E->getOperatorDelete()) {
6317 // Mark any declarations we need as referenced.
6318 // FIXME: instantiation-specific.
6319 if (OperatorDelete)
6320 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006321
6322 if (!E->getArgument()->isTypeDependent()) {
6323 QualType Destroyed = SemaRef.Context.getBaseElementType(
6324 E->getDestroyedType());
6325 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6326 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6327 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6328 SemaRef.LookupDestructor(Record));
6329 }
6330 }
6331
John McCall3fa5cae2010-10-26 07:05:15 +00006332 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006333 }
Mike Stump1eb44332009-09-09 15:08:12 +00006334
Douglas Gregorb98b1992009-08-11 05:31:07 +00006335 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6336 E->isGlobalDelete(),
6337 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006338 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339}
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006342ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006343TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006344 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006345 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006346 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006348
John McCallb3d87482010-08-24 05:47:05 +00006349 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006350 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006351 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006352 E->getOperatorLoc(),
6353 E->isArrow()? tok::arrow : tok::period,
6354 ObjectTypePtr,
6355 MayBePseudoDestructor);
6356 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006357 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006358
John McCallb3d87482010-08-24 05:47:05 +00006359 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006360 NestedNameSpecifier *Qualifier = E->getQualifier();
6361 if (Qualifier) {
6362 Qualifier
6363 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6364 E->getQualifierRange(),
6365 ObjectType);
6366 if (!Qualifier)
6367 return ExprError();
6368 }
Mike Stump1eb44332009-09-09 15:08:12 +00006369
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006370 PseudoDestructorTypeStorage Destroyed;
6371 if (E->getDestroyedTypeInfo()) {
6372 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006373 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6374 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006375 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006376 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006377 Destroyed = DestroyedTypeInfo;
6378 } else if (ObjectType->isDependentType()) {
6379 // We aren't likely to be able to resolve the identifier down to a type
6380 // now anyway, so just retain the identifier.
6381 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6382 E->getDestroyedTypeLoc());
6383 } else {
6384 // Look for a destructor known with the given name.
6385 CXXScopeSpec SS;
6386 if (Qualifier) {
6387 SS.setScopeRep(Qualifier);
6388 SS.setRange(E->getQualifierRange());
6389 }
Sean Huntc3021132010-05-05 15:23:54 +00006390
John McCallb3d87482010-08-24 05:47:05 +00006391 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006392 *E->getDestroyedTypeIdentifier(),
6393 E->getDestroyedTypeLoc(),
6394 /*Scope=*/0,
6395 SS, ObjectTypePtr,
6396 false);
6397 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006398 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006399
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006400 Destroyed
6401 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6402 E->getDestroyedTypeLoc());
6403 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006404
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006405 TypeSourceInfo *ScopeTypeInfo = 0;
6406 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006407 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006408 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006409 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006410 }
Sean Huntc3021132010-05-05 15:23:54 +00006411
John McCall9ae2f072010-08-23 23:25:46 +00006412 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006413 E->getOperatorLoc(),
6414 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006415 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006416 E->getQualifierRange(),
6417 ScopeTypeInfo,
6418 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006419 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006420 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006421}
Mike Stump1eb44332009-09-09 15:08:12 +00006422
Douglas Gregora71d8192009-09-04 17:36:40 +00006423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006424ExprResult
John McCallba135432009-11-21 08:51:07 +00006425TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006426 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006427 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6428
6429 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6430 Sema::LookupOrdinaryName);
6431
6432 // Transform all the decls.
6433 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6434 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006435 NamedDecl *InstD = static_cast<NamedDecl*>(
6436 getDerived().TransformDecl(Old->getNameLoc(),
6437 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006438 if (!InstD) {
6439 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6440 // This can happen because of dependent hiding.
6441 if (isa<UsingShadowDecl>(*I))
6442 continue;
6443 else
John McCallf312b1e2010-08-26 23:41:50 +00006444 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006445 }
John McCallf7a1a742009-11-24 19:00:30 +00006446
6447 // Expand using declarations.
6448 if (isa<UsingDecl>(InstD)) {
6449 UsingDecl *UD = cast<UsingDecl>(InstD);
6450 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6451 E = UD->shadow_end(); I != E; ++I)
6452 R.addDecl(*I);
6453 continue;
6454 }
6455
6456 R.addDecl(InstD);
6457 }
6458
6459 // Resolve a kind, but don't do any further analysis. If it's
6460 // ambiguous, the callee needs to deal with it.
6461 R.resolveKind();
6462
6463 // Rebuild the nested-name qualifier, if present.
6464 CXXScopeSpec SS;
6465 NestedNameSpecifier *Qualifier = 0;
6466 if (Old->getQualifier()) {
6467 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006468 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006469 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006470 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006471
John McCallf7a1a742009-11-24 19:00:30 +00006472 SS.setScopeRep(Qualifier);
6473 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006474 }
6475
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006476 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006477 CXXRecordDecl *NamingClass
6478 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6479 Old->getNameLoc(),
6480 Old->getNamingClass()));
6481 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006482 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006483
Douglas Gregor66c45152010-04-27 16:10:10 +00006484 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006485 }
6486
6487 // If we have no template arguments, it's a normal declaration name.
6488 if (!Old->hasExplicitTemplateArgs())
6489 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6490
6491 // If we have template arguments, rebuild them, then rebuild the
6492 // templateid expression.
6493 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006494 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6495 Old->getNumTemplateArgs(),
6496 TransArgs))
6497 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006498
6499 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6500 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501}
Mike Stump1eb44332009-09-09 15:08:12 +00006502
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006504ExprResult
John McCall454feb92009-12-08 09:21:05 +00006505TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006506 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6507 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006511 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Mike Stump1eb44332009-09-09 15:08:12 +00006514 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516 T,
6517 E->getLocEnd());
6518}
Mike Stump1eb44332009-09-09 15:08:12 +00006519
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006521ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006522TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6523 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6524 if (!LhsT)
6525 return ExprError();
6526
6527 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6528 if (!RhsT)
6529 return ExprError();
6530
6531 if (!getDerived().AlwaysRebuild() &&
6532 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6533 return SemaRef.Owned(E);
6534
6535 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6536 E->getLocStart(),
6537 LhsT, RhsT,
6538 E->getLocEnd());
6539}
6540
6541template<typename Derived>
6542ExprResult
John McCall865d4472009-11-19 22:55:06 +00006543TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006544 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006546 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006547 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006549 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006550
John McCall43fed0d2010-11-12 08:19:04 +00006551 // TODO: If this is a conversion-function-id, verify that the
6552 // destination type name (if present) resolves the same way after
6553 // instantiation as it did in the local scope.
6554
Abramo Bagnara25777432010-08-11 22:01:17 +00006555 DeclarationNameInfo NameInfo
6556 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6557 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006558 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006559
John McCallf7a1a742009-11-24 19:00:30 +00006560 if (!E->hasExplicitTemplateArgs()) {
6561 if (!getDerived().AlwaysRebuild() &&
6562 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006563 // Note: it is sufficient to compare the Name component of NameInfo:
6564 // if name has not changed, DNLoc has not changed either.
6565 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006566 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006567
John McCallf7a1a742009-11-24 19:00:30 +00006568 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6569 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006570 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006571 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006572 }
John McCalld5532b62009-11-23 01:53:49 +00006573
6574 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006575 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6576 E->getNumTemplateArgs(),
6577 TransArgs))
6578 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579
John McCallf7a1a742009-11-24 19:00:30 +00006580 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6581 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006582 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006583 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584}
6585
6586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006587ExprResult
John McCall454feb92009-12-08 09:21:05 +00006588TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006589 // CXXConstructExprs are always implicit, so when we have a
6590 // 1-argument construction we just transform that argument.
6591 if (E->getNumArgs() == 1 ||
6592 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6593 return getDerived().TransformExpr(E->getArg(0));
6594
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6596
6597 QualType T = getDerived().TransformType(E->getType());
6598 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600
6601 CXXConstructorDecl *Constructor
6602 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006603 getDerived().TransformDecl(E->getLocStart(),
6604 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006609 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006610 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6611 &ArgumentChanged))
6612 return ExprError();
6613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 if (!getDerived().AlwaysRebuild() &&
6615 T == E->getType() &&
6616 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006617 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006618 // Mark the constructor as referenced.
6619 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006620 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006621 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006622 }
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006624 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6625 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006626 move_arg(Args),
6627 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006628 E->getConstructionKind(),
6629 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630}
Mike Stump1eb44332009-09-09 15:08:12 +00006631
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632/// \brief Transform a C++ temporary-binding expression.
6633///
Douglas Gregor51326552009-12-24 18:51:59 +00006634/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6635/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006636template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006637ExprResult
John McCall454feb92009-12-08 09:21:05 +00006638TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006639 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640}
Mike Stump1eb44332009-09-09 15:08:12 +00006641
John McCall4765fa02010-12-06 08:20:24 +00006642/// \brief Transform a C++ expression that contains cleanups that should
6643/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644///
John McCall4765fa02010-12-06 08:20:24 +00006645/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006646/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006648ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006649TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006650 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651}
Mike Stump1eb44332009-09-09 15:08:12 +00006652
Douglas Gregorb98b1992009-08-11 05:31:07 +00006653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006654ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006656 CXXTemporaryObjectExpr *E) {
6657 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6658 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006659 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006660
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 CXXConstructorDecl *Constructor
6662 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006663 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006664 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006669 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006671 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6672 &ArgumentChanged))
6673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006674
Douglas Gregorb98b1992009-08-11 05:31:07 +00006675 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006676 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006678 !ArgumentChanged) {
6679 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006680 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006681 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006682 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006683
6684 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6685 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 E->getLocEnd());
6688}
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006691ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006693 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006694 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6695 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006697
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006699 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006700 Args.reserve(E->arg_size());
6701 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6702 &ArgumentChanged))
6703 return ExprError();
6704
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006706 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006708 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006709
Douglas Gregorb98b1992009-08-11 05:31:07 +00006710 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006711 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 E->getLParenLoc(),
6713 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 E->getRParenLoc());
6715}
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006718ExprResult
John McCall865d4472009-11-19 22:55:06 +00006719TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006720 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006722 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006723 Expr *OldBase;
6724 QualType BaseType;
6725 QualType ObjectType;
6726 if (!E->isImplicitAccess()) {
6727 OldBase = E->getBase();
6728 Base = getDerived().TransformExpr(OldBase);
6729 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006731
John McCallaa81e162009-12-01 22:10:20 +00006732 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006733 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006734 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006735 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006736 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006737 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006738 ObjectTy,
6739 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006740 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006741 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006742
John McCallb3d87482010-08-24 05:47:05 +00006743 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006744 BaseType = ((Expr*) Base.get())->getType();
6745 } else {
6746 OldBase = 0;
6747 BaseType = getDerived().TransformType(E->getBaseType());
6748 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6749 }
Mike Stump1eb44332009-09-09 15:08:12 +00006750
Douglas Gregor6cd21982009-10-20 05:58:46 +00006751 // Transform the first part of the nested-name-specifier that qualifies
6752 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006753 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006754 = getDerived().TransformFirstQualifierInScope(
6755 E->getFirstQualifierFoundInScope(),
6756 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006757
Douglas Gregora38c6872009-09-03 16:14:30 +00006758 NestedNameSpecifier *Qualifier = 0;
6759 if (E->getQualifier()) {
6760 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6761 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006762 ObjectType,
6763 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006764 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006765 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006766 }
Mike Stump1eb44332009-09-09 15:08:12 +00006767
John McCall43fed0d2010-11-12 08:19:04 +00006768 // TODO: If this is a conversion-function-id, verify that the
6769 // destination type name (if present) resolves the same way after
6770 // instantiation as it did in the local scope.
6771
Abramo Bagnara25777432010-08-11 22:01:17 +00006772 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006773 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006774 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006775 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006776
John McCallaa81e162009-12-01 22:10:20 +00006777 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006778 // This is a reference to a member without an explicitly-specified
6779 // template argument list. Optimize for this common case.
6780 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006781 Base.get() == OldBase &&
6782 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006783 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006784 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006785 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006786 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006787
John McCall9ae2f072010-08-23 23:25:46 +00006788 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006789 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006790 E->isArrow(),
6791 E->getOperatorLoc(),
6792 Qualifier,
6793 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006794 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006795 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006796 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006797 }
6798
John McCalld5532b62009-11-23 01:53:49 +00006799 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006800 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6801 E->getNumTemplateArgs(),
6802 TransArgs))
6803 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006804
John McCall9ae2f072010-08-23 23:25:46 +00006805 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006806 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 E->isArrow(),
6808 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006809 Qualifier,
6810 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006811 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006812 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006813 &TransArgs);
6814}
6815
6816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006817ExprResult
John McCall454feb92009-12-08 09:21:05 +00006818TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006819 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006820 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006821 QualType BaseType;
6822 if (!Old->isImplicitAccess()) {
6823 Base = getDerived().TransformExpr(Old->getBase());
6824 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006825 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006826 BaseType = ((Expr*) Base.get())->getType();
6827 } else {
6828 BaseType = getDerived().TransformType(Old->getBaseType());
6829 }
John McCall129e2df2009-11-30 22:42:35 +00006830
6831 NestedNameSpecifier *Qualifier = 0;
6832 if (Old->getQualifier()) {
6833 Qualifier
6834 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006835 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006836 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006837 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006838 }
6839
Abramo Bagnara25777432010-08-11 22:01:17 +00006840 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006841 Sema::LookupOrdinaryName);
6842
6843 // Transform all the decls.
6844 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6845 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006846 NamedDecl *InstD = static_cast<NamedDecl*>(
6847 getDerived().TransformDecl(Old->getMemberLoc(),
6848 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006849 if (!InstD) {
6850 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6851 // This can happen because of dependent hiding.
6852 if (isa<UsingShadowDecl>(*I))
6853 continue;
6854 else
John McCallf312b1e2010-08-26 23:41:50 +00006855 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006856 }
John McCall129e2df2009-11-30 22:42:35 +00006857
6858 // Expand using declarations.
6859 if (isa<UsingDecl>(InstD)) {
6860 UsingDecl *UD = cast<UsingDecl>(InstD);
6861 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6862 E = UD->shadow_end(); I != E; ++I)
6863 R.addDecl(*I);
6864 continue;
6865 }
6866
6867 R.addDecl(InstD);
6868 }
6869
6870 R.resolveKind();
6871
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006872 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006873 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006874 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006875 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006876 Old->getMemberLoc(),
6877 Old->getNamingClass()));
6878 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006880
Douglas Gregor66c45152010-04-27 16:10:10 +00006881 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006882 }
Sean Huntc3021132010-05-05 15:23:54 +00006883
John McCall129e2df2009-11-30 22:42:35 +00006884 TemplateArgumentListInfo TransArgs;
6885 if (Old->hasExplicitTemplateArgs()) {
6886 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6887 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006888 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6889 Old->getNumTemplateArgs(),
6890 TransArgs))
6891 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006892 }
John McCallc2233c52010-01-15 08:34:02 +00006893
6894 // FIXME: to do this check properly, we will need to preserve the
6895 // first-qualifier-in-scope here, just in case we had a dependent
6896 // base (and therefore couldn't do the check) and a
6897 // nested-name-qualifier (and therefore could do the lookup).
6898 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006899
John McCall9ae2f072010-08-23 23:25:46 +00006900 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006901 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006902 Old->getOperatorLoc(),
6903 Old->isArrow(),
6904 Qualifier,
6905 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006906 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006907 R,
6908 (Old->hasExplicitTemplateArgs()
6909 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006910}
6911
6912template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006913ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006914TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6915 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6916 if (SubExpr.isInvalid())
6917 return ExprError();
6918
6919 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006920 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006921
6922 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6923}
6924
6925template<typename Derived>
6926ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006927TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00006928 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6929 if (Pattern.isInvalid())
6930 return ExprError();
6931
6932 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6933 return SemaRef.Owned(E);
6934
Douglas Gregor67fd1252011-01-14 21:20:45 +00006935 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6936 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00006937}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006938
6939template<typename Derived>
6940ExprResult
6941TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6942 // If E is not value-dependent, then nothing will change when we transform it.
6943 // Note: This is an instantiation-centric view.
6944 if (!E->isValueDependent())
6945 return SemaRef.Owned(E);
6946
6947 // Note: None of the implementations of TryExpandParameterPacks can ever
6948 // produce a diagnostic when given only a single unexpanded parameter pack,
6949 // so
6950 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6951 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00006952 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00006953 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00006954 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6955 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00006956 ShouldExpand, RetainExpansion,
6957 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00006958 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006959
Douglas Gregord3731192011-01-10 07:32:04 +00006960 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00006961 return SemaRef.Owned(E);
6962
6963 // We now know the length of the parameter pack, so build a new expression
6964 // that stores that length.
6965 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6966 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00006967 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00006968}
6969
Douglas Gregorbe230c32011-01-03 17:17:50 +00006970template<typename Derived>
6971ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00006972TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6973 SubstNonTypeTemplateParmPackExpr *E) {
6974 // Default behavior is to do nothing with this transformation.
6975 return SemaRef.Owned(E);
6976}
6977
6978template<typename Derived>
6979ExprResult
John McCall454feb92009-12-08 09:21:05 +00006980TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006981 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982}
6983
Mike Stump1eb44332009-09-09 15:08:12 +00006984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006985ExprResult
John McCall454feb92009-12-08 09:21:05 +00006986TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006987 TypeSourceInfo *EncodedTypeInfo
6988 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6989 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006990 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006993 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006994 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995
6996 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006997 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 E->getRParenLoc());
6999}
Mike Stump1eb44332009-09-09 15:08:12 +00007000
Douglas Gregorb98b1992009-08-11 05:31:07 +00007001template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007002ExprResult
John McCall454feb92009-12-08 09:21:05 +00007003TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007004 // Transform arguments.
7005 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007006 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007007 Args.reserve(E->getNumArgs());
7008 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7009 &ArgChanged))
7010 return ExprError();
7011
Douglas Gregor92e986e2010-04-22 16:44:27 +00007012 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7013 // Class message: transform the receiver type.
7014 TypeSourceInfo *ReceiverTypeInfo
7015 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7016 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007017 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007018
Douglas Gregor92e986e2010-04-22 16:44:27 +00007019 // If nothing changed, just retain the existing message send.
7020 if (!getDerived().AlwaysRebuild() &&
7021 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007022 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007023
7024 // Build a new class message send.
7025 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7026 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007027 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007028 E->getMethodDecl(),
7029 E->getLeftLoc(),
7030 move_arg(Args),
7031 E->getRightLoc());
7032 }
7033
7034 // Instance message: transform the receiver
7035 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7036 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007037 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007038 = getDerived().TransformExpr(E->getInstanceReceiver());
7039 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007040 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007041
7042 // If nothing changed, just retain the existing message send.
7043 if (!getDerived().AlwaysRebuild() &&
7044 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007046
Douglas Gregor92e986e2010-04-22 16:44:27 +00007047 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007048 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007049 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007050 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007051 E->getMethodDecl(),
7052 E->getLeftLoc(),
7053 move_arg(Args),
7054 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055}
7056
Mike Stump1eb44332009-09-09 15:08:12 +00007057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007058ExprResult
John McCall454feb92009-12-08 09:21:05 +00007059TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007060 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061}
7062
Mike Stump1eb44332009-09-09 15:08:12 +00007063template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007064ExprResult
John McCall454feb92009-12-08 09:21:05 +00007065TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007066 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067}
7068
Mike Stump1eb44332009-09-09 15:08:12 +00007069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007070ExprResult
John McCall454feb92009-12-08 09:21:05 +00007071TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007072 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007073 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007074 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007075 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007076
7077 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007078
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007079 // If nothing changed, just retain the existing expression.
7080 if (!getDerived().AlwaysRebuild() &&
7081 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007083
John McCall9ae2f072010-08-23 23:25:46 +00007084 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007085 E->getLocation(),
7086 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087}
7088
Mike Stump1eb44332009-09-09 15:08:12 +00007089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007090ExprResult
John McCall454feb92009-12-08 09:21:05 +00007091TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007092 // 'super' and types never change. Property never changes. Just
7093 // retain the existing expression.
7094 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007095 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007096
Douglas Gregore3303542010-04-26 20:47:02 +00007097 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007098 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007099 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007100 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007101
Douglas Gregore3303542010-04-26 20:47:02 +00007102 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007103
Douglas Gregore3303542010-04-26 20:47:02 +00007104 // If nothing changed, just retain the existing expression.
7105 if (!getDerived().AlwaysRebuild() &&
7106 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007108
John McCall12f78a62010-12-02 01:19:52 +00007109 if (E->isExplicitProperty())
7110 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7111 E->getExplicitProperty(),
7112 E->getLocation());
7113
7114 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7115 E->getType(),
7116 E->getImplicitPropertyGetter(),
7117 E->getImplicitPropertySetter(),
7118 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119}
7120
Mike Stump1eb44332009-09-09 15:08:12 +00007121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007122ExprResult
John McCall454feb92009-12-08 09:21:05 +00007123TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007124 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007125 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007126 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007127 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007128
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007129 // If nothing changed, just retain the existing expression.
7130 if (!getDerived().AlwaysRebuild() &&
7131 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007132 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007133
John McCall9ae2f072010-08-23 23:25:46 +00007134 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007135 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136}
7137
Mike Stump1eb44332009-09-09 15:08:12 +00007138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007139ExprResult
John McCall454feb92009-12-08 09:21:05 +00007140TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007142 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007143 SubExprs.reserve(E->getNumSubExprs());
7144 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7145 SubExprs, &ArgumentChanged))
7146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregorb98b1992009-08-11 05:31:07 +00007148 if (!getDerived().AlwaysRebuild() &&
7149 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007150 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007151
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7153 move_arg(SubExprs),
7154 E->getRParenLoc());
7155}
7156
Mike Stump1eb44332009-09-09 15:08:12 +00007157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007158ExprResult
John McCall454feb92009-12-08 09:21:05 +00007159TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007160 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007161
John McCallc6ac9c32011-02-04 18:33:18 +00007162 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7163 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7164
7165 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7166 llvm::SmallVector<ParmVarDecl*, 4> params;
7167 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007168
7169 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007170 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7171 oldBlock->param_begin(),
7172 oldBlock->param_size(),
7173 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007174 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007175
7176 const FunctionType *exprFunctionType = E->getFunctionType();
7177 QualType exprResultType = exprFunctionType->getResultType();
7178 if (!exprResultType.isNull()) {
7179 if (!exprResultType->isDependentType())
7180 blockScope->ReturnType = exprResultType;
7181 else if (exprResultType != getSema().Context.DependentTy)
7182 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007183 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007184
7185 // If the return type has not been determined yet, leave it as a dependent
7186 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007187 if (blockScope->ReturnType.isNull())
7188 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007189
7190 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007191 if (blockScope->ReturnType->isObjCObjectType()) {
7192 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007193 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007194 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007195 return ExprError();
7196 }
John McCall711c52b2011-01-05 12:14:39 +00007197
John McCallc6ac9c32011-02-04 18:33:18 +00007198 QualType functionType = getDerived().RebuildFunctionProtoType(
7199 blockScope->ReturnType,
7200 paramTypes.data(),
7201 paramTypes.size(),
7202 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007203 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007204 exprFunctionType->getExtInfo());
7205 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007206
7207 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007208 if (!params.empty())
7209 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007210
7211 // If the return type wasn't explicitly set, it will have been marked as a
7212 // dependent type (DependentTy); clear out the return type setting so
7213 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007214 if (blockScope->ReturnType == getSema().Context.DependentTy)
7215 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007216
John McCall711c52b2011-01-05 12:14:39 +00007217 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007218 StmtResult body = getDerived().TransformStmt(E->getBody());
7219 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007220 return ExprError();
7221
John McCallc6ac9c32011-02-04 18:33:18 +00007222#ifndef NDEBUG
7223 // In builds with assertions, make sure that we captured everything we
7224 // captured before.
7225
7226 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7227
7228 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7229 e = oldBlock->capture_end(); i != e; ++i) {
John McCall6b5a61b2011-02-07 10:33:21 +00007230 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007231
7232 // Ignore parameter packs.
7233 if (isa<ParmVarDecl>(oldCapture) &&
7234 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7235 continue;
7236
7237 VarDecl *newCapture =
7238 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7239 oldCapture));
John McCall6b5a61b2011-02-07 10:33:21 +00007240 assert(blockScope->CaptureMap.count(newCapture));
John McCallc6ac9c32011-02-04 18:33:18 +00007241 }
7242#endif
7243
7244 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7245 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007246}
7247
Mike Stump1eb44332009-09-09 15:08:12 +00007248template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007249ExprResult
John McCall454feb92009-12-08 09:21:05 +00007250TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007251 NestedNameSpecifier *Qualifier = 0;
7252
7253 ValueDecl *ND
7254 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7255 E->getDecl()));
7256 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007257 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007258
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007259 if (!getDerived().AlwaysRebuild() &&
7260 ND == E->getDecl()) {
7261 // Mark it referenced in the new context regardless.
7262 // FIXME: this is a bit instantiation-specific.
7263 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7264
John McCall3fa5cae2010-10-26 07:05:15 +00007265 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007266 }
7267
Abramo Bagnara25777432010-08-11 22:01:17 +00007268 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007269 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007270 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007271}
Mike Stump1eb44332009-09-09 15:08:12 +00007272
Douglas Gregorb98b1992009-08-11 05:31:07 +00007273//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007274// Type reconstruction
7275//===----------------------------------------------------------------------===//
7276
Mike Stump1eb44332009-09-09 15:08:12 +00007277template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007278QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7279 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007280 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007281 getDerived().getBaseEntity());
7282}
7283
Mike Stump1eb44332009-09-09 15:08:12 +00007284template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007285QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7286 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007287 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007288 getDerived().getBaseEntity());
7289}
7290
Mike Stump1eb44332009-09-09 15:08:12 +00007291template<typename Derived>
7292QualType
John McCall85737a72009-10-30 00:06:24 +00007293TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7294 bool WrittenAsLValue,
7295 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007296 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007297 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007298}
7299
7300template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007301QualType
John McCall85737a72009-10-30 00:06:24 +00007302TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7303 QualType ClassType,
7304 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007305 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007306 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007307}
7308
7309template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007310QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007311TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7312 ArrayType::ArraySizeModifier SizeMod,
7313 const llvm::APInt *Size,
7314 Expr *SizeExpr,
7315 unsigned IndexTypeQuals,
7316 SourceRange BracketsRange) {
7317 if (SizeExpr || !Size)
7318 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7319 IndexTypeQuals, BracketsRange,
7320 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007321
7322 QualType Types[] = {
7323 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7324 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7325 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007326 };
7327 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7328 QualType SizeType;
7329 for (unsigned I = 0; I != NumTypes; ++I)
7330 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7331 SizeType = Types[I];
7332 break;
7333 }
Mike Stump1eb44332009-09-09 15:08:12 +00007334
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007335 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7336 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007337 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007338 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007339 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007340}
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregor577f75a2009-08-04 16:50:30 +00007342template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007343QualType
7344TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007345 ArrayType::ArraySizeModifier SizeMod,
7346 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007347 unsigned IndexTypeQuals,
7348 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007349 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007350 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007351}
7352
7353template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007354QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007355TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007356 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007357 unsigned IndexTypeQuals,
7358 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007359 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007360 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007361}
Mike Stump1eb44332009-09-09 15:08:12 +00007362
Douglas Gregor577f75a2009-08-04 16:50:30 +00007363template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007364QualType
7365TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007366 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007367 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007368 unsigned IndexTypeQuals,
7369 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007370 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007371 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007372 IndexTypeQuals, BracketsRange);
7373}
7374
7375template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007376QualType
7377TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007378 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007379 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007380 unsigned IndexTypeQuals,
7381 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007382 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007383 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007384 IndexTypeQuals, BracketsRange);
7385}
7386
7387template<typename Derived>
7388QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007389 unsigned NumElements,
7390 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007391 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007392 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007393}
Mike Stump1eb44332009-09-09 15:08:12 +00007394
Douglas Gregor577f75a2009-08-04 16:50:30 +00007395template<typename Derived>
7396QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7397 unsigned NumElements,
7398 SourceLocation AttributeLoc) {
7399 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7400 NumElements, true);
7401 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007402 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7403 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007404 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007405}
Mike Stump1eb44332009-09-09 15:08:12 +00007406
Douglas Gregor577f75a2009-08-04 16:50:30 +00007407template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007408QualType
7409TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007410 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007411 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007412 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007413}
Mike Stump1eb44332009-09-09 15:08:12 +00007414
Douglas Gregor577f75a2009-08-04 16:50:30 +00007415template<typename Derived>
7416QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007417 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007418 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007419 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007420 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007421 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007422 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007423 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007424 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007425 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007426 getDerived().getBaseEntity(),
7427 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007428}
Mike Stump1eb44332009-09-09 15:08:12 +00007429
Douglas Gregor577f75a2009-08-04 16:50:30 +00007430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007431QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7432 return SemaRef.Context.getFunctionNoProtoType(T);
7433}
7434
7435template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007436QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7437 assert(D && "no decl found");
7438 if (D->isInvalidDecl()) return QualType();
7439
Douglas Gregor92e986e2010-04-22 16:44:27 +00007440 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007441 TypeDecl *Ty;
7442 if (isa<UsingDecl>(D)) {
7443 UsingDecl *Using = cast<UsingDecl>(D);
7444 assert(Using->isTypeName() &&
7445 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7446
7447 // A valid resolved using typename decl points to exactly one type decl.
7448 assert(++Using->shadow_begin() == Using->shadow_end());
7449 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007450
John McCalled976492009-12-04 22:46:56 +00007451 } else {
7452 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7453 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7454 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7455 }
7456
7457 return SemaRef.Context.getTypeDeclType(Ty);
7458}
7459
7460template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007461QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7462 SourceLocation Loc) {
7463 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007464}
7465
7466template<typename Derived>
7467QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7468 return SemaRef.Context.getTypeOfType(Underlying);
7469}
7470
7471template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007472QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7473 SourceLocation Loc) {
7474 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007475}
7476
7477template<typename Derived>
7478QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007479 TemplateName Template,
7480 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007481 const TemplateArgumentListInfo &TemplateArgs) {
7482 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007483}
Mike Stump1eb44332009-09-09 15:08:12 +00007484
Douglas Gregordcee1a12009-08-06 05:28:30 +00007485template<typename Derived>
7486NestedNameSpecifier *
7487TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7488 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007489 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007490 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007491 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007492 CXXScopeSpec SS;
7493 // FIXME: The source location information is all wrong.
7494 SS.setRange(Range);
7495 SS.setScopeRep(Prefix);
7496 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007497 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007498 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007499 ObjectType,
7500 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007501 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007502}
7503
7504template<typename Derived>
7505NestedNameSpecifier *
7506TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7507 SourceRange Range,
7508 NamespaceDecl *NS) {
7509 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7510}
7511
7512template<typename Derived>
7513NestedNameSpecifier *
7514TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7515 SourceRange Range,
7516 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007517 QualType T) {
7518 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007519 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007520 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007521 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7522 T.getTypePtr());
7523 }
Mike Stump1eb44332009-09-09 15:08:12 +00007524
Douglas Gregordcee1a12009-08-06 05:28:30 +00007525 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7526 return 0;
7527}
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Douglas Gregord1067e52009-08-06 06:41:21 +00007529template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007530TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007531TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7532 bool TemplateKW,
7533 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007534 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007535 Template);
7536}
7537
7538template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007539TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007540TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007541 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007542 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007543 QualType ObjectType,
7544 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007545 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007546 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007547 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007548 UnqualifiedId Name;
7549 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007550 Sema::TemplateTy Template;
7551 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7552 /*FIXME:*/getDerived().getBaseLocation(),
7553 SS,
7554 Name,
John McCallb3d87482010-08-24 05:47:05 +00007555 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007556 /*EnteringContext=*/false,
7557 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007558 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007559}
Mike Stump1eb44332009-09-09 15:08:12 +00007560
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007562TemplateName
7563TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7564 OverloadedOperatorKind Operator,
7565 QualType ObjectType) {
7566 CXXScopeSpec SS;
7567 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7568 SS.setScopeRep(Qualifier);
7569 UnqualifiedId Name;
7570 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7571 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7572 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007573 Sema::TemplateTy Template;
7574 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007575 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007576 SS,
7577 Name,
John McCallb3d87482010-08-24 05:47:05 +00007578 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007579 /*EnteringContext=*/false,
7580 Template);
7581 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007582}
Sean Huntc3021132010-05-05 15:23:54 +00007583
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007585ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007586TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7587 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007588 Expr *OrigCallee,
7589 Expr *First,
7590 Expr *Second) {
7591 Expr *Callee = OrigCallee->IgnoreParenCasts();
7592 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007593
Douglas Gregorb98b1992009-08-11 05:31:07 +00007594 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007595 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007596 if (!First->getType()->isOverloadableType() &&
7597 !Second->getType()->isOverloadableType())
7598 return getSema().CreateBuiltinArraySubscriptExpr(First,
7599 Callee->getLocStart(),
7600 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007601 } else if (Op == OO_Arrow) {
7602 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007603 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7604 } else if (Second == 0 || isPostIncDec) {
7605 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007606 // The argument is not of overloadable type, so try to create a
7607 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007608 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007609 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007610
John McCall9ae2f072010-08-23 23:25:46 +00007611 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007612 }
7613 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007614 if (!First->getType()->isOverloadableType() &&
7615 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007616 // Neither of the arguments is an overloadable type, so try to
7617 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007618 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007619 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007620 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007621 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007622 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007623
Douglas Gregorb98b1992009-08-11 05:31:07 +00007624 return move(Result);
7625 }
7626 }
Mike Stump1eb44332009-09-09 15:08:12 +00007627
7628 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007629 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007630 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007631
John McCall9ae2f072010-08-23 23:25:46 +00007632 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007633 assert(ULE->requiresADL());
7634
7635 // FIXME: Do we have to check
7636 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007637 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007638 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007639 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007640 }
Mike Stump1eb44332009-09-09 15:08:12 +00007641
Douglas Gregorb98b1992009-08-11 05:31:07 +00007642 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007643 Expr *Args[2] = { First, Second };
7644 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007645
Douglas Gregorb98b1992009-08-11 05:31:07 +00007646 // Create the overloaded operator invocation for unary operators.
7647 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007648 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007650 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007651 }
Mike Stump1eb44332009-09-09 15:08:12 +00007652
Sebastian Redlf322ed62009-10-29 20:17:01 +00007653 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007654 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007655 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007656 First,
7657 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007658
Douglas Gregorb98b1992009-08-11 05:31:07 +00007659 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007660 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007661 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007662 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7663 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007664 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007665
Mike Stump1eb44332009-09-09 15:08:12 +00007666 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007667}
Mike Stump1eb44332009-09-09 15:08:12 +00007668
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007670ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007671TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007672 SourceLocation OperatorLoc,
7673 bool isArrow,
7674 NestedNameSpecifier *Qualifier,
7675 SourceRange QualifierRange,
7676 TypeSourceInfo *ScopeType,
7677 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007678 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007679 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007680 CXXScopeSpec SS;
7681 if (Qualifier) {
7682 SS.setRange(QualifierRange);
7683 SS.setScopeRep(Qualifier);
7684 }
7685
John McCall9ae2f072010-08-23 23:25:46 +00007686 QualType BaseType = Base->getType();
7687 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007688 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007689 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007690 !BaseType->getAs<PointerType>()->getPointeeType()
7691 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007692 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007693 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007694 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007695 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007696 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007697 /*FIXME?*/true);
7698 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007699
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007700 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007701 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7702 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7703 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7704 NameInfo.setNamedTypeInfo(DestroyedType);
7705
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007706 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007707
John McCall9ae2f072010-08-23 23:25:46 +00007708 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007709 OperatorLoc, isArrow,
7710 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007711 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007712 /*TemplateArgs*/ 0);
7713}
7714
Douglas Gregor577f75a2009-08-04 16:50:30 +00007715} // end namespace clang
7716
7717#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H