blob: 472e281553886d407a0faedd642eb81fe1e28858 [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.
John McCall60d7b3a2010-08-24 06:29:42 +0000978 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 IdentifierInfo *Id,
980 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000981 Stmt *SubStmt, bool HasUnusedAttr) {
982 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
983 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 }
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 /// \brief Build a new "if" statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000990 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000991 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000992 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000993 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000994 }
Mike Stump1eb44332009-09-09 15:08:12 +0000995
Douglas Gregor43959a92009-08-20 07:17:43 +0000996 /// \brief Start building a new switch statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001000 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001001 Expr *Cond, VarDecl *CondVar) {
1002 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001003 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 /// \brief Attach the body to the switch statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001010 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001011 Stmt *Switch, Stmt *Body) {
1012 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 }
1014
1015 /// \brief Build a new while statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001019 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +00001020 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001021 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +00001022 Stmt *Body) {
1023 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001024 }
Mike Stump1eb44332009-09-09 15:08:12 +00001025
Douglas Gregor43959a92009-08-20 07:17:43 +00001026 /// \brief Build a new do-while statement.
1027 ///
1028 /// By default, performs semantic analysis to build the new statement.
1029 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001030 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 SourceLocation WhileLoc,
1032 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001033 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001035 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1036 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 }
1038
1039 /// \brief Build a new for statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001043 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001045 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001046 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 SourceLocation RParenLoc, Stmt *Body) {
1048 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +00001049 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +00001050 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /// \brief Build a new goto statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001058 SourceLocation LabelLoc,
1059 LabelStmt *Label) {
1060 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1061 }
1062
1063 /// \brief Build a new indirect goto statement.
1064 ///
1065 /// By default, performs semantic analysis to build the new statement.
1066 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001067 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001068 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001069 Expr *Target) {
1070 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001071 }
Mike Stump1eb44332009-09-09 15:08:12 +00001072
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 /// \brief Build a new return statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001077 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001078 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +00001079
John McCall9ae2f072010-08-23 23:25:46 +00001080 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 }
Mike Stump1eb44332009-09-09 15:08:12 +00001082
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 /// \brief Build a new declaration statement.
1084 ///
1085 /// By default, performs semantic analysis to build the new statement.
1086 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001087 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001088 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 SourceLocation EndLoc) {
1090 return getSema().Owned(
1091 new (getSema().Context) DeclStmt(
1092 DeclGroupRef::Create(getSema().Context,
1093 Decls, NumDecls),
1094 StartLoc, EndLoc));
1095 }
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Anders Carlsson703e3942010-01-24 05:50:09 +00001097 /// \brief Build a new inline asm statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001101 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001102 bool IsSimple,
1103 bool IsVolatile,
1104 unsigned NumOutputs,
1105 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001106 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001107 MultiExprArg Constraints,
1108 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001109 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001110 MultiExprArg Clobbers,
1111 SourceLocation RParenLoc,
1112 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001113 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001114 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001115 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001116 RParenLoc, MSAsm);
1117 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001118
1119 /// \brief Build a new Objective-C @try statement.
1120 ///
1121 /// By default, performs semantic analysis to build the new statement.
1122 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001123 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001124 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001125 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001126 Stmt *Finally) {
1127 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1128 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001129 }
1130
Douglas Gregorbe270a02010-04-26 17:57:08 +00001131 /// \brief Rebuild an Objective-C exception declaration.
1132 ///
1133 /// By default, performs semantic analysis to build the new declaration.
1134 /// Subclasses may override this routine to provide different behavior.
1135 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1136 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001137 return getSema().BuildObjCExceptionDecl(TInfo, T,
1138 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001139 ExceptionDecl->getLocation());
1140 }
Sean Huntc3021132010-05-05 15:23:54 +00001141
Douglas Gregorbe270a02010-04-26 17:57:08 +00001142 /// \brief Build a new Objective-C @catch statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001146 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001147 SourceLocation RParenLoc,
1148 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001149 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001150 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001151 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001152 }
Sean Huntc3021132010-05-05 15:23:54 +00001153
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001154 /// \brief Build a new Objective-C @finally statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001159 Stmt *Body) {
1160 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001161 }
Sean Huntc3021132010-05-05 15:23:54 +00001162
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001163 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001167 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001168 Expr *Operand) {
1169 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001170 }
Sean Huntc3021132010-05-05 15:23:54 +00001171
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001172 /// \brief Build a new Objective-C @synchronized statement.
1173 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001177 Expr *Object,
1178 Stmt *Body) {
1179 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1180 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001181 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001182
1183 /// \brief Build a new Objective-C fast enumeration statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001187 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001188 SourceLocation LParenLoc,
1189 Stmt *Element,
1190 Expr *Collection,
1191 SourceLocation RParenLoc,
1192 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001193 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001194 Element,
1195 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001196 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001197 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001198 }
Sean Huntc3021132010-05-05 15:23:54 +00001199
Douglas Gregor43959a92009-08-20 07:17:43 +00001200 /// \brief Build a new C++ exception declaration.
1201 ///
1202 /// By default, performs semantic analysis to build the new decaration.
1203 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001204 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001205 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001206 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001207 SourceLocation Loc) {
1208 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001209 }
1210
1211 /// \brief Build a new C++ catch statement.
1212 ///
1213 /// By default, performs semantic analysis to build the new statement.
1214 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001215 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001216 VarDecl *ExceptionDecl,
1217 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001218 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1219 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001220 }
Mike Stump1eb44332009-09-09 15:08:12 +00001221
Douglas Gregor43959a92009-08-20 07:17:43 +00001222 /// \brief Build a new C++ try statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001226 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001227 Stmt *TryBlock,
1228 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001229 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001230 }
Mike Stump1eb44332009-09-09 15:08:12 +00001231
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 /// \brief Build a new expression that references a declaration.
1233 ///
1234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001236 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001237 LookupResult &R,
1238 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001239 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1240 }
1241
1242
1243 /// \brief Build a new expression that references a declaration.
1244 ///
1245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001247 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001248 SourceRange QualifierRange,
1249 ValueDecl *VD,
1250 const DeclarationNameInfo &NameInfo,
1251 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001252 CXXScopeSpec SS;
1253 SS.setScopeRep(Qualifier);
1254 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001255
1256 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001257
1258 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001259 }
Mike Stump1eb44332009-09-09 15:08:12 +00001260
Douglas Gregorb98b1992009-08-11 05:31:07 +00001261 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001262 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001265 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001266 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001267 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001268 }
1269
Douglas Gregora71d8192009-09-04 17:36:40 +00001270 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001271 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001272 /// By default, performs semantic analysis to build the new expression.
1273 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001274 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001275 SourceLocation OperatorLoc,
1276 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001277 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001278 SourceRange QualifierRange,
1279 TypeSourceInfo *ScopeType,
1280 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001281 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001282 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001283
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001285 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 /// By default, performs semantic analysis to build the new expression.
1287 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001288 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001289 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001290 Expr *SubExpr) {
1291 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 }
Mike Stump1eb44332009-09-09 15:08:12 +00001293
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001294 /// \brief Build a new builtin offsetof expression.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001298 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001299 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001300 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001301 unsigned NumComponents,
1302 SourceLocation RParenLoc) {
1303 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1304 NumComponents, RParenLoc);
1305 }
Sean Huntc3021132010-05-05 15:23:54 +00001306
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001308 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001311 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001312 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001314 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 }
1316
Mike Stump1eb44332009-09-09 15:08:12 +00001317 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001318 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001319 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001322 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001323 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001324 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001325 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001327 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001328
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 return move(Result);
1330 }
Mike Stump1eb44332009-09-09 15:08:12 +00001331
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001333 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001336 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001338 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001340 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1341 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001342 RBracketLoc);
1343 }
1344
1345 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001346 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001349 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001352 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001353 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 }
1355
1356 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001357 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001360 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001361 bool isArrow,
1362 NestedNameSpecifier *Qualifier,
1363 SourceRange QualifierRange,
1364 const DeclarationNameInfo &MemberNameInfo,
1365 ValueDecl *Member,
1366 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001367 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001368 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001369 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001370 // We have a reference to an unnamed field. This is always the
1371 // base of an anonymous struct/union member access, i.e. the
1372 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001373 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001374 assert(Member->getType()->isRecordType() &&
1375 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001376
John McCall9ae2f072010-08-23 23:25:46 +00001377 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001378 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001379 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001380
John McCallf89e55a2010-11-18 06:31:45 +00001381 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001382 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001383 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001384 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001385 cast<FieldDecl>(Member)->getType(),
1386 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001387 return getSema().Owned(ME);
1388 }
Mike Stump1eb44332009-09-09 15:08:12 +00001389
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001390 CXXScopeSpec SS;
1391 if (Qualifier) {
1392 SS.setRange(QualifierRange);
1393 SS.setScopeRep(Qualifier);
1394 }
1395
John McCall9ae2f072010-08-23 23:25:46 +00001396 getSema().DefaultFunctionArrayConversion(Base);
1397 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001398
John McCall6bb80172010-03-30 21:47:33 +00001399 // FIXME: this involves duplicating earlier analysis in a lot of
1400 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001401 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001402 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001403 R.resolveKind();
1404
John McCall9ae2f072010-08-23 23:25:46 +00001405 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001406 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001407 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 }
Mike Stump1eb44332009-09-09 15:08:12 +00001409
Douglas Gregorb98b1992009-08-11 05:31:07 +00001410 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001411 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001414 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001415 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001416 Expr *LHS, Expr *RHS) {
1417 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 }
1419
1420 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001421 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001424 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001426 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001427 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001428 Expr *RHS) {
1429 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1430 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 }
1432
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001434 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// By default, performs semantic analysis to build the new expression.
1436 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001437 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001438 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001440 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001441 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001442 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001443 }
Mike Stump1eb44332009-09-09 15:08:12 +00001444
Douglas Gregorb98b1992009-08-11 05:31:07 +00001445 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001446 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001449 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001450 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001452 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001453 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001454 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 }
Mike Stump1eb44332009-09-09 15:08:12 +00001456
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001458 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001461 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001462 SourceLocation OpLoc,
1463 SourceLocation AccessorLoc,
1464 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001465
John McCall129e2df2009-11-30 22:42:35 +00001466 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001467 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001468 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001469 OpLoc, /*IsArrow*/ false,
1470 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001471 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001472 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 }
Mike Stump1eb44332009-09-09 15:08:12 +00001474
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001481 SourceLocation RBraceLoc,
1482 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001483 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001484 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1485 if (Result.isInvalid() || ResultTy->isDependentType())
1486 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001487
Douglas Gregore48319a2009-11-09 17:16:50 +00001488 // Patch in the result type we were given, which may have been computed
1489 // when the initial InitListExpr was built.
1490 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1491 ILE->setType(ResultTy);
1492 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 }
Mike Stump1eb44332009-09-09 15:08:12 +00001494
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001496 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001499 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 MultiExprArg ArrayExprs,
1501 SourceLocation EqualOrColonLoc,
1502 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001503 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001504 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001506 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001509
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 ArrayExprs.release();
1511 return move(Result);
1512 }
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001515 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// By default, builds the implicit value initialization without performing
1517 /// any semantic analysis. Subclasses may override this routine to provide
1518 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001524 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001528 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001529 SourceLocation RParenLoc) {
1530 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001531 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001532 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 }
1534
1535 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001536 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001539 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 MultiExprArg SubExprs,
1541 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001542 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001543 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 }
Mike Stump1eb44332009-09-09 15:08:12 +00001545
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001547 ///
1548 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 /// rather than attempting to map the label statement itself.
1550 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001551 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 SourceLocation LabelLoc,
1553 LabelStmt *Label) {
1554 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1555 }
Mike Stump1eb44332009-09-09 15:08:12 +00001556
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001558 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001561 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001562 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001564 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new __builtin_choose_expr expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001572 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 SourceLocation RParenLoc) {
1574 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001575 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 RParenLoc);
1577 }
Mike Stump1eb44332009-09-09 15:08:12 +00001578
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// \brief Build a new overloaded operator call expression.
1580 ///
1581 /// By default, performs semantic analysis to build the new expression.
1582 /// The semantic analysis provides the behavior of template instantiation,
1583 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001584 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 /// argument-dependent lookup, etc. Subclasses may override this routine to
1586 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 Expr *Callee,
1590 Expr *First,
1591 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001592
1593 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// reinterpret_cast.
1595 ///
1596 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001597 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001599 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 Stmt::StmtClass Class,
1601 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001602 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 SourceLocation RAngleLoc,
1604 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001605 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 SourceLocation RParenLoc) {
1607 switch (Class) {
1608 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001609 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001610 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001611 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612
1613 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001614 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001615 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001616 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001619 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001620 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001621 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001623
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001625 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001626 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001627 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001628
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 default:
1630 assert(false && "Invalid C++ named cast");
1631 break;
1632 }
Mike Stump1eb44332009-09-09 15:08:12 +00001633
John McCallf312b1e2010-08-26 23:41:50 +00001634 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 }
Mike Stump1eb44332009-09-09 15:08:12 +00001636
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 /// \brief Build a new C++ static_cast expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001643 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 SourceLocation RAngleLoc,
1645 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001646 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001648 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001649 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001650 SourceRange(LAngleLoc, RAngleLoc),
1651 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
1653
1654 /// \brief Build a new C++ dynamic_cast expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001660 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 SourceLocation RAngleLoc,
1662 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001665 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001666 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001667 SourceRange(LAngleLoc, RAngleLoc),
1668 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new C++ reinterpret_cast expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001677 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 SourceLocation RAngleLoc,
1679 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001682 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001683 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001684 SourceRange(LAngleLoc, RAngleLoc),
1685 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new C++ const_cast expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001692 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001694 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 SourceLocation RAngleLoc,
1696 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001697 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001699 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001700 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001701 SourceRange(LAngleLoc, RAngleLoc),
1702 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
Mike Stump1eb44332009-09-09 15:08:12 +00001704
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// \brief Build a new C++ functional-style cast expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001709 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1710 SourceLocation LParenLoc,
1711 Expr *Sub,
1712 SourceLocation RParenLoc) {
1713 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001714 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 RParenLoc);
1716 }
Mike Stump1eb44332009-09-09 15:08:12 +00001717
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// \brief Build a new C++ typeid(type) expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001723 SourceLocation TypeidLoc,
1724 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001726 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001727 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 }
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Francois Pichet01b7c302010-09-08 12:20:18 +00001730
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 /// \brief Build a new C++ typeid(expr) expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001735 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001736 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001737 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001739 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001740 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001741 }
1742
Francois Pichet01b7c302010-09-08 12:20:18 +00001743 /// \brief Build a new C++ __uuidof(type) expression.
1744 ///
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
1747 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1748 SourceLocation TypeidLoc,
1749 TypeSourceInfo *Operand,
1750 SourceLocation RParenLoc) {
1751 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1752 RParenLoc);
1753 }
1754
1755 /// \brief Build a new C++ __uuidof(expr) expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
1759 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1760 SourceLocation TypeidLoc,
1761 Expr *Operand,
1762 SourceLocation RParenLoc) {
1763 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1764 RParenLoc);
1765 }
1766
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 /// \brief Build a new C++ "this" expression.
1768 ///
1769 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001770 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001772 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001773 QualType ThisType,
1774 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001776 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1777 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 }
1779
1780 /// \brief Build a new C++ throw expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001784 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001785 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 }
1787
1788 /// \brief Build a new C++ default-argument expression.
1789 ///
1790 /// By default, builds a new default-argument expression, which does not
1791 /// require any semantic analysis. Subclasses may override this routine to
1792 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001794 ParmVarDecl *Param) {
1795 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1796 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 }
1798
1799 /// \brief Build a new C++ zero-initialization expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001803 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1804 SourceLocation LParenLoc,
1805 SourceLocation RParenLoc) {
1806 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001807 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001808 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 /// \brief Build a new C++ "new" expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001816 bool UseGlobal,
1817 SourceLocation PlacementLParen,
1818 MultiExprArg PlacementArgs,
1819 SourceLocation PlacementRParen,
1820 SourceRange TypeIdParens,
1821 QualType AllocatedType,
1822 TypeSourceInfo *AllocatedTypeInfo,
1823 Expr *ArraySize,
1824 SourceLocation ConstructorLParen,
1825 MultiExprArg ConstructorArgs,
1826 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001827 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 PlacementLParen,
1829 move(PlacementArgs),
1830 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001831 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001832 AllocatedType,
1833 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001834 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 ConstructorLParen,
1836 move(ConstructorArgs),
1837 ConstructorRParen);
1838 }
Mike Stump1eb44332009-09-09 15:08:12 +00001839
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 /// \brief Build a new C++ "delete" expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001844 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 bool IsGlobalDelete,
1846 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001847 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001849 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
Mike Stump1eb44332009-09-09 15:08:12 +00001851
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 /// \brief Build a new unary type trait expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001856 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001857 SourceLocation StartLoc,
1858 TypeSourceInfo *T,
1859 SourceLocation RParenLoc) {
1860 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 }
1862
Francois Pichet6ad6f282010-12-07 00:08:36 +00001863 /// \brief Build a new binary type trait expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
1867 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1868 SourceLocation StartLoc,
1869 TypeSourceInfo *LhsT,
1870 TypeSourceInfo *RhsT,
1871 SourceLocation RParenLoc) {
1872 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1873 }
1874
Mike Stump1eb44332009-09-09 15:08:12 +00001875 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 /// expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001880 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001882 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001883 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 CXXScopeSpec SS;
1885 SS.setRange(QualifierRange);
1886 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001887
1888 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001889 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001890 *TemplateArgs);
1891
Abramo Bagnara25777432010-08-11 22:01:17 +00001892 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new template-id expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001899 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001900 LookupResult &R,
1901 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001902 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001903 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new object-construction expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001910 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001911 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 CXXConstructorDecl *Constructor,
1913 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001914 MultiExprArg Args,
1915 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001916 CXXConstructExpr::ConstructionKind ConstructKind,
1917 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001918 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001919 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001920 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001921 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001922
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001923 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001924 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001925 RequiresZeroInit, ConstructKind,
1926 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001927 }
1928
1929 /// \brief Build a new object-construction expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001933 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1934 SourceLocation LParenLoc,
1935 MultiExprArg Args,
1936 SourceLocation RParenLoc) {
1937 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001938 LParenLoc,
1939 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 RParenLoc);
1941 }
1942
1943 /// \brief Build a new object-construction expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001947 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1948 SourceLocation LParenLoc,
1949 MultiExprArg Args,
1950 SourceLocation RParenLoc) {
1951 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 LParenLoc,
1953 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 RParenLoc);
1955 }
Mike Stump1eb44332009-09-09 15:08:12 +00001956
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 /// \brief Build a new member reference expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001961 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001962 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 bool IsArrow,
1964 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001965 NestedNameSpecifier *Qualifier,
1966 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001967 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001968 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001969 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001971 SS.setRange(QualifierRange);
1972 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001973
John McCall9ae2f072010-08-23 23:25:46 +00001974 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001975 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001976 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001977 MemberNameInfo,
1978 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 }
1980
John McCall129e2df2009-11-30 22:42:35 +00001981 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001985 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001986 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001987 SourceLocation OperatorLoc,
1988 bool IsArrow,
1989 NestedNameSpecifier *Qualifier,
1990 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001991 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001992 LookupResult &R,
1993 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001994 CXXScopeSpec SS;
1995 SS.setRange(QualifierRange);
1996 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001997
John McCall9ae2f072010-08-23 23:25:46 +00001998 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001999 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002000 SS, FirstQualifierInScope,
2001 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002002 }
Mike Stump1eb44332009-09-09 15:08:12 +00002003
Sebastian Redl2e156222010-09-10 20:55:43 +00002004 /// \brief Build a new noexcept expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
2008 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2009 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2010 }
2011
Douglas Gregoree8aff02011-01-04 17:33:58 +00002012 /// \brief Build a new expression to compute the length of a parameter pack.
2013 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2014 SourceLocation PackLoc,
2015 SourceLocation RParenLoc,
2016 unsigned Length) {
2017 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2018 OperatorLoc, Pack, PackLoc,
2019 RParenLoc, Length);
2020 }
2021
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 /// \brief Build a new Objective-C @encode expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002026 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002027 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002028 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002029 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002030 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002031 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032
Douglas Gregor92e986e2010-04-22 16:44:27 +00002033 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002034 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002035 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002036 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002037 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002038 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002039 MultiExprArg Args,
2040 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002041 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2042 ReceiverTypeInfo->getType(),
2043 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002044 Sel, Method, LBracLoc, SelectorLoc,
2045 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002046 }
2047
2048 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002049 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002050 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002051 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002052 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002053 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002054 MultiExprArg Args,
2055 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002056 return SemaRef.BuildInstanceMessage(Receiver,
2057 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002058 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002059 Sel, Method, LBracLoc, SelectorLoc,
2060 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002061 }
2062
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002063 /// \brief Build a new Objective-C ivar reference expression.
2064 ///
2065 /// By default, performs semantic analysis to build the new expression.
2066 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002067 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002068 SourceLocation IvarLoc,
2069 bool IsArrow, bool IsFreeIvar) {
2070 // FIXME: We lose track of the IsFreeIvar bit.
2071 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002072 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002073 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2074 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002075 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002076 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002077 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002078 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002079 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002080 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002081
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002082 if (Result.get())
2083 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002084
John McCall9ae2f072010-08-23 23:25:46 +00002085 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002086 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002087 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002088 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002089 /*TemplateArgs=*/0);
2090 }
Douglas Gregore3303542010-04-26 20:47:02 +00002091
2092 /// \brief Build a new Objective-C property reference expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002097 ObjCPropertyDecl *Property,
2098 SourceLocation PropertyLoc) {
2099 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002100 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002101 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2102 Sema::LookupMemberName);
2103 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002104 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002105 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002106 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002107 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002108 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002109
Douglas Gregore3303542010-04-26 20:47:02 +00002110 if (Result.get())
2111 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002112
John McCall9ae2f072010-08-23 23:25:46 +00002113 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002114 /*FIXME:*/PropertyLoc, IsArrow,
2115 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002116 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002117 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002118 /*TemplateArgs=*/0);
2119 }
Sean Huntc3021132010-05-05 15:23:54 +00002120
John McCall12f78a62010-12-02 01:19:52 +00002121 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002122 ///
2123 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002124 /// Subclasses may override this routine to provide different behavior.
2125 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2126 ObjCMethodDecl *Getter,
2127 ObjCMethodDecl *Setter,
2128 SourceLocation PropertyLoc) {
2129 // Since these expressions can only be value-dependent, we do not
2130 // need to perform semantic analysis again.
2131 return Owned(
2132 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2133 VK_LValue, OK_ObjCProperty,
2134 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002135 }
2136
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002137 /// \brief Build a new Objective-C "isa" expression.
2138 ///
2139 /// By default, performs semantic analysis to build the new expression.
2140 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002141 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002142 bool IsArrow) {
2143 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002144 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002145 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2146 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002147 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002148 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002149 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002150 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002151 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002152
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002153 if (Result.get())
2154 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002155
John McCall9ae2f072010-08-23 23:25:46 +00002156 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002157 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002158 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002159 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002160 /*TemplateArgs=*/0);
2161 }
Sean Huntc3021132010-05-05 15:23:54 +00002162
Douglas Gregorb98b1992009-08-11 05:31:07 +00002163 /// \brief Build a new shuffle vector expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002167 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002168 MultiExprArg SubExprs,
2169 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002170 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002171 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2173 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2174 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2175 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002176
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 // Build a reference to the __builtin_shufflevector builtin
2178 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002179 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002180 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002181 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002182 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002183
2184 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 unsigned NumSubExprs = SubExprs.size();
2186 Expr **Subs = (Expr **)SubExprs.release();
2187 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2188 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002189 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002190 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002192 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002193
Douglas Gregorb98b1992009-08-11 05:31:07 +00002194 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002195 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002196 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002198
Douglas Gregorb98b1992009-08-11 05:31:07 +00002199 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002200 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002201 }
John McCall43fed0d2010-11-12 08:19:04 +00002202
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002203 /// \brief Build a new template argument pack expansion.
2204 ///
2205 /// By default, performs semantic analysis to build a new pack expansion
2206 /// for a template argument. Subclasses may override this routine to provide
2207 /// different behavior.
2208 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002209 SourceLocation EllipsisLoc,
2210 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002211 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002212 case TemplateArgument::Expression: {
2213 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002214 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2215 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002216 if (Result.isInvalid())
2217 return TemplateArgumentLoc();
2218
2219 return TemplateArgumentLoc(Result.get(), Result.get());
2220 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002221
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002222 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002223 return TemplateArgumentLoc(TemplateArgument(
2224 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002225 NumExpansions),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002226 Pattern.getTemplateQualifierRange(),
2227 Pattern.getTemplateNameLoc(),
2228 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002229
2230 case TemplateArgument::Null:
2231 case TemplateArgument::Integral:
2232 case TemplateArgument::Declaration:
2233 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002234 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002235 llvm_unreachable("Pack expansion pattern has no parameter packs");
2236
2237 case TemplateArgument::Type:
2238 if (TypeSourceInfo *Expansion
2239 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002240 EllipsisLoc,
2241 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002242 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2243 Expansion);
2244 break;
2245 }
2246
2247 return TemplateArgumentLoc();
2248 }
2249
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002250 /// \brief Build a new expression pack expansion.
2251 ///
2252 /// By default, performs semantic analysis to build a new pack expansion
2253 /// for an expression. Subclasses may override this routine to provide
2254 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002255 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2256 llvm::Optional<unsigned> NumExpansions) {
2257 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002258 }
2259
John McCall43fed0d2010-11-12 08:19:04 +00002260private:
2261 QualType TransformTypeInObjectScope(QualType T,
2262 QualType ObjectType,
2263 NamedDecl *FirstQualifierInScope,
2264 NestedNameSpecifier *Prefix);
2265
2266 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2267 QualType ObjectType,
2268 NamedDecl *FirstQualifierInScope,
2269 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002270};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002271
Douglas Gregor43959a92009-08-20 07:17:43 +00002272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002273StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002274 if (!S)
2275 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002276
Douglas Gregor43959a92009-08-20 07:17:43 +00002277 switch (S->getStmtClass()) {
2278 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregor43959a92009-08-20 07:17:43 +00002280 // Transform individual statement nodes
2281#define STMT(Node, Parent) \
2282 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2283#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002284#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002285
Douglas Gregor43959a92009-08-20 07:17:43 +00002286 // Transform expressions by calling TransformExpr.
2287#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002288#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002289#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002290#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002291 {
John McCall60d7b3a2010-08-24 06:29:42 +00002292 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002293 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002294 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002295
John McCall9ae2f072010-08-23 23:25:46 +00002296 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002297 }
Mike Stump1eb44332009-09-09 15:08:12 +00002298 }
2299
John McCall3fa5cae2010-10-26 07:05:15 +00002300 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002301}
Mike Stump1eb44332009-09-09 15:08:12 +00002302
2303
Douglas Gregor670444e2009-08-04 22:27:00 +00002304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002305ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002306 if (!E)
2307 return SemaRef.Owned(E);
2308
2309 switch (E->getStmtClass()) {
2310 case Stmt::NoStmtClass: break;
2311#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002312#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002313#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002314 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002315#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002316 }
2317
John McCall3fa5cae2010-10-26 07:05:15 +00002318 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002319}
2320
2321template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002322bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2323 unsigned NumInputs,
2324 bool IsCall,
2325 llvm::SmallVectorImpl<Expr *> &Outputs,
2326 bool *ArgChanged) {
2327 for (unsigned I = 0; I != NumInputs; ++I) {
2328 // If requested, drop call arguments that need to be dropped.
2329 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2330 if (ArgChanged)
2331 *ArgChanged = true;
2332
2333 break;
2334 }
2335
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002336 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2337 Expr *Pattern = Expansion->getPattern();
2338
2339 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2340 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2341 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2342
2343 // Determine whether the set of unexpanded parameter packs can and should
2344 // be expanded.
2345 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002346 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002347 llvm::Optional<unsigned> OrigNumExpansions
2348 = Expansion->getNumExpansions();
2349 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002350 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2351 Pattern->getSourceRange(),
2352 Unexpanded.data(),
2353 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002354 Expand, RetainExpansion,
2355 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002356 return true;
2357
2358 if (!Expand) {
2359 // The transform has determined that we should perform a simple
2360 // transformation on the pack expansion, producing another pack
2361 // expansion.
2362 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2363 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2364 if (OutPattern.isInvalid())
2365 return true;
2366
2367 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002368 Expansion->getEllipsisLoc(),
2369 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002370 if (Out.isInvalid())
2371 return true;
2372
2373 if (ArgChanged)
2374 *ArgChanged = true;
2375 Outputs.push_back(Out.get());
2376 continue;
2377 }
2378
2379 // The transform has determined that we should perform an elementwise
2380 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002381 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2383 ExprResult Out = getDerived().TransformExpr(Pattern);
2384 if (Out.isInvalid())
2385 return true;
2386
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002387 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002388 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2389 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002390 if (Out.isInvalid())
2391 return true;
2392 }
2393
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002394 if (ArgChanged)
2395 *ArgChanged = true;
2396 Outputs.push_back(Out.get());
2397 }
2398
2399 continue;
2400 }
2401
Douglas Gregoraa165f82011-01-03 19:04:46 +00002402 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2403 if (Result.isInvalid())
2404 return true;
2405
2406 if (Result.get() != Inputs[I] && ArgChanged)
2407 *ArgChanged = true;
2408
2409 Outputs.push_back(Result.get());
2410 }
2411
2412 return false;
2413}
2414
2415template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002416NestedNameSpecifier *
2417TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002418 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002419 QualType ObjectType,
2420 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002421 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002422
Douglas Gregor43959a92009-08-20 07:17:43 +00002423 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002424 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002425 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002426 ObjectType,
2427 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002428 if (!Prefix)
2429 return 0;
2430 }
Mike Stump1eb44332009-09-09 15:08:12 +00002431
Douglas Gregordcee1a12009-08-06 05:28:30 +00002432 switch (NNS->getKind()) {
2433 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002434 if (Prefix) {
2435 // The object type and qualifier-in-scope really apply to the
2436 // leftmost entity.
2437 ObjectType = QualType();
2438 FirstQualifierInScope = 0;
2439 }
2440
Mike Stump1eb44332009-09-09 15:08:12 +00002441 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002442 "Identifier nested-name-specifier with no prefix or object type");
2443 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2444 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002445 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002446
2447 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002448 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002449 ObjectType,
2450 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002451
Douglas Gregordcee1a12009-08-06 05:28:30 +00002452 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002453 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002454 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002455 getDerived().TransformDecl(Range.getBegin(),
2456 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002457 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002458 Prefix == NNS->getPrefix() &&
2459 NS == NNS->getAsNamespace())
2460 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002461
Douglas Gregordcee1a12009-08-06 05:28:30 +00002462 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2463 }
Mike Stump1eb44332009-09-09 15:08:12 +00002464
Douglas Gregordcee1a12009-08-06 05:28:30 +00002465 case NestedNameSpecifier::Global:
2466 // There is no meaningful transformation that one could perform on the
2467 // global scope.
2468 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002469
Douglas Gregordcee1a12009-08-06 05:28:30 +00002470 case NestedNameSpecifier::TypeSpecWithTemplate:
2471 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002472 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002473 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2474 ObjectType,
2475 FirstQualifierInScope,
2476 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002477 if (T.isNull())
2478 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002479
Douglas Gregordcee1a12009-08-06 05:28:30 +00002480 if (!getDerived().AlwaysRebuild() &&
2481 Prefix == NNS->getPrefix() &&
2482 T == QualType(NNS->getAsType(), 0))
2483 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002484
2485 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2486 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002487 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002488 }
2489 }
Mike Stump1eb44332009-09-09 15:08:12 +00002490
Douglas Gregordcee1a12009-08-06 05:28:30 +00002491 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002492 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002493}
2494
2495template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002496DeclarationNameInfo
2497TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002498::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002499 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002500 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002501 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002502
2503 switch (Name.getNameKind()) {
2504 case DeclarationName::Identifier:
2505 case DeclarationName::ObjCZeroArgSelector:
2506 case DeclarationName::ObjCOneArgSelector:
2507 case DeclarationName::ObjCMultiArgSelector:
2508 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002509 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002510 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002511 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002512
Douglas Gregor81499bb2009-09-03 22:13:48 +00002513 case DeclarationName::CXXConstructorName:
2514 case DeclarationName::CXXDestructorName:
2515 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002516 TypeSourceInfo *NewTInfo;
2517 CanQualType NewCanTy;
2518 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002519 NewTInfo = getDerived().TransformType(OldTInfo);
2520 if (!NewTInfo)
2521 return DeclarationNameInfo();
2522 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002523 }
2524 else {
2525 NewTInfo = 0;
2526 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002527 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002528 if (NewT.isNull())
2529 return DeclarationNameInfo();
2530 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2531 }
Mike Stump1eb44332009-09-09 15:08:12 +00002532
Abramo Bagnara25777432010-08-11 22:01:17 +00002533 DeclarationName NewName
2534 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2535 NewCanTy);
2536 DeclarationNameInfo NewNameInfo(NameInfo);
2537 NewNameInfo.setName(NewName);
2538 NewNameInfo.setNamedTypeInfo(NewTInfo);
2539 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002540 }
Mike Stump1eb44332009-09-09 15:08:12 +00002541 }
2542
Abramo Bagnara25777432010-08-11 22:01:17 +00002543 assert(0 && "Unknown name kind.");
2544 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002545}
2546
2547template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002548TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002549TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002550 QualType ObjectType,
2551 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002552 SourceLocation Loc = getDerived().getBaseLocation();
2553
Douglas Gregord1067e52009-08-06 06:41:21 +00002554 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002555 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002556 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002557 /*FIXME*/ SourceRange(Loc),
2558 ObjectType,
2559 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002560 if (!NNS)
2561 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002562
Douglas Gregord1067e52009-08-06 06:41:21 +00002563 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002564 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002565 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002566 if (!TransTemplate)
2567 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002568
Douglas Gregord1067e52009-08-06 06:41:21 +00002569 if (!getDerived().AlwaysRebuild() &&
2570 NNS == QTN->getQualifier() &&
2571 TransTemplate == Template)
2572 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002573
Douglas Gregord1067e52009-08-06 06:41:21 +00002574 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2575 TransTemplate);
2576 }
Mike Stump1eb44332009-09-09 15:08:12 +00002577
John McCallf7a1a742009-11-24 19:00:30 +00002578 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002579 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002580 }
Mike Stump1eb44332009-09-09 15:08:12 +00002581
Douglas Gregord1067e52009-08-06 06:41:21 +00002582 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002583 NestedNameSpecifier *NNS = DTN->getQualifier();
2584 if (NNS) {
2585 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2586 /*FIXME:*/SourceRange(Loc),
2587 ObjectType,
2588 FirstQualifierInScope);
2589 if (!NNS) return TemplateName();
2590
2591 // These apply to the scope specifier, not the template.
2592 ObjectType = QualType();
2593 FirstQualifierInScope = 0;
2594 }
Mike Stump1eb44332009-09-09 15:08:12 +00002595
Douglas Gregord1067e52009-08-06 06:41:21 +00002596 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002597 NNS == DTN->getQualifier() &&
2598 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002599 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002600
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002601 if (DTN->isIdentifier()) {
2602 // FIXME: Bad range
2603 SourceRange QualifierRange(getDerived().getBaseLocation());
2604 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2605 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002606 ObjectType,
2607 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002608 }
Sean Huntc3021132010-05-05 15:23:54 +00002609
2610 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002611 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002612 }
Mike Stump1eb44332009-09-09 15:08:12 +00002613
Douglas Gregord1067e52009-08-06 06:41:21 +00002614 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002615 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002616 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002617 if (!TransTemplate)
2618 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002619
Douglas Gregord1067e52009-08-06 06:41:21 +00002620 if (!getDerived().AlwaysRebuild() &&
2621 TransTemplate == Template)
2622 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002623
Douglas Gregord1067e52009-08-06 06:41:21 +00002624 return TemplateName(TransTemplate);
2625 }
Mike Stump1eb44332009-09-09 15:08:12 +00002626
Douglas Gregor1aee05d2011-01-15 06:45:20 +00002627 if (SubstTemplateTemplateParmPackStorage *SubstPack
2628 = Name.getAsSubstTemplateTemplateParmPack()) {
2629 TemplateTemplateParmDecl *TransParam
2630 = cast_or_null<TemplateTemplateParmDecl>(
2631 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2632 if (!TransParam)
2633 return TemplateName();
2634
2635 if (!getDerived().AlwaysRebuild() &&
2636 TransParam == SubstPack->getParameterPack())
2637 return Name;
2638
2639 return getDerived().RebuildTemplateName(TransParam,
2640 SubstPack->getArgumentPack());
2641 }
2642
John McCallf7a1a742009-11-24 19:00:30 +00002643 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002644 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002645 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002646}
2647
2648template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002649void TreeTransform<Derived>::InventTemplateArgumentLoc(
2650 const TemplateArgument &Arg,
2651 TemplateArgumentLoc &Output) {
2652 SourceLocation Loc = getDerived().getBaseLocation();
2653 switch (Arg.getKind()) {
2654 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002655 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002656 break;
2657
2658 case TemplateArgument::Type:
2659 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002660 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002661
John McCall833ca992009-10-29 08:12:44 +00002662 break;
2663
Douglas Gregor788cd062009-11-11 01:00:40 +00002664 case TemplateArgument::Template:
2665 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2666 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002667
2668 case TemplateArgument::TemplateExpansion:
2669 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2670 break;
2671
John McCall833ca992009-10-29 08:12:44 +00002672 case TemplateArgument::Expression:
2673 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2674 break;
2675
2676 case TemplateArgument::Declaration:
2677 case TemplateArgument::Integral:
2678 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002679 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002680 break;
2681 }
2682}
2683
2684template<typename Derived>
2685bool TreeTransform<Derived>::TransformTemplateArgument(
2686 const TemplateArgumentLoc &Input,
2687 TemplateArgumentLoc &Output) {
2688 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002689 switch (Arg.getKind()) {
2690 case TemplateArgument::Null:
2691 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002692 Output = Input;
2693 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002694
Douglas Gregor670444e2009-08-04 22:27:00 +00002695 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002696 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002697 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002698 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002699
2700 DI = getDerived().TransformType(DI);
2701 if (!DI) return true;
2702
2703 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2704 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002705 }
Mike Stump1eb44332009-09-09 15:08:12 +00002706
Douglas Gregor670444e2009-08-04 22:27:00 +00002707 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002708 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002709 DeclarationName Name;
2710 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2711 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002712 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002713 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002714 if (!D) return true;
2715
John McCall828bff22009-10-29 18:45:58 +00002716 Expr *SourceExpr = Input.getSourceDeclExpression();
2717 if (SourceExpr) {
2718 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002719 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002720 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002721 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002722 }
2723
2724 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002725 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002726 }
Mike Stump1eb44332009-09-09 15:08:12 +00002727
Douglas Gregor788cd062009-11-11 01:00:40 +00002728 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002729 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002730 TemplateName Template
2731 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2732 if (Template.isNull())
2733 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002734
Douglas Gregor788cd062009-11-11 01:00:40 +00002735 Output = TemplateArgumentLoc(TemplateArgument(Template),
2736 Input.getTemplateQualifierRange(),
2737 Input.getTemplateNameLoc());
2738 return false;
2739 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002740
2741 case TemplateArgument::TemplateExpansion:
2742 llvm_unreachable("Caller should expand pack expansions");
2743
Douglas Gregor670444e2009-08-04 22:27:00 +00002744 case TemplateArgument::Expression: {
2745 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002746 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002747 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002748
John McCall833ca992009-10-29 08:12:44 +00002749 Expr *InputExpr = Input.getSourceExpression();
2750 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2751
John McCall60d7b3a2010-08-24 06:29:42 +00002752 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002753 = getDerived().TransformExpr(InputExpr);
2754 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002755 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002756 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002757 }
Mike Stump1eb44332009-09-09 15:08:12 +00002758
Douglas Gregor670444e2009-08-04 22:27:00 +00002759 case TemplateArgument::Pack: {
2760 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2761 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002762 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002763 AEnd = Arg.pack_end();
2764 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002765
John McCall833ca992009-10-29 08:12:44 +00002766 // FIXME: preserve source information here when we start
2767 // caring about parameter packs.
2768
John McCall828bff22009-10-29 18:45:58 +00002769 TemplateArgumentLoc InputArg;
2770 TemplateArgumentLoc OutputArg;
2771 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2772 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002773 return true;
2774
John McCall828bff22009-10-29 18:45:58 +00002775 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002776 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002777
2778 TemplateArgument *TransformedArgsPtr
2779 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2780 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2781 TransformedArgsPtr);
2782 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2783 TransformedArgs.size()),
2784 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002785 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002786 }
2787 }
Mike Stump1eb44332009-09-09 15:08:12 +00002788
Douglas Gregor670444e2009-08-04 22:27:00 +00002789 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002790 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002791}
2792
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002793/// \brief Iterator adaptor that invents template argument location information
2794/// for each of the template arguments in its underlying iterator.
2795template<typename Derived, typename InputIterator>
2796class TemplateArgumentLocInventIterator {
2797 TreeTransform<Derived> &Self;
2798 InputIterator Iter;
2799
2800public:
2801 typedef TemplateArgumentLoc value_type;
2802 typedef TemplateArgumentLoc reference;
2803 typedef typename std::iterator_traits<InputIterator>::difference_type
2804 difference_type;
2805 typedef std::input_iterator_tag iterator_category;
2806
2807 class pointer {
2808 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002809
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002810 public:
2811 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2812
2813 const TemplateArgumentLoc *operator->() const { return &Arg; }
2814 };
2815
2816 TemplateArgumentLocInventIterator() { }
2817
2818 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2819 InputIterator Iter)
2820 : Self(Self), Iter(Iter) { }
2821
2822 TemplateArgumentLocInventIterator &operator++() {
2823 ++Iter;
2824 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002825 }
2826
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002827 TemplateArgumentLocInventIterator operator++(int) {
2828 TemplateArgumentLocInventIterator Old(*this);
2829 ++(*this);
2830 return Old;
2831 }
2832
2833 reference operator*() const {
2834 TemplateArgumentLoc Result;
2835 Self.InventTemplateArgumentLoc(*Iter, Result);
2836 return Result;
2837 }
2838
2839 pointer operator->() const { return pointer(**this); }
2840
2841 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2842 const TemplateArgumentLocInventIterator &Y) {
2843 return X.Iter == Y.Iter;
2844 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002845
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002846 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2847 const TemplateArgumentLocInventIterator &Y) {
2848 return X.Iter != Y.Iter;
2849 }
2850};
2851
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002852template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002853template<typename InputIterator>
2854bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2855 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002856 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002857 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002858 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002859 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002860
2861 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2862 // Unpack argument packs, which we translate them into separate
2863 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002864 // FIXME: We could do much better if we could guarantee that the
2865 // TemplateArgumentLocInfo for the pack expansion would be usable for
2866 // all of the template arguments in the argument pack.
2867 typedef TemplateArgumentLocInventIterator<Derived,
2868 TemplateArgument::pack_iterator>
2869 PackLocIterator;
2870 if (TransformTemplateArguments(PackLocIterator(*this,
2871 In.getArgument().pack_begin()),
2872 PackLocIterator(*this,
2873 In.getArgument().pack_end()),
2874 Outputs))
2875 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002876
2877 continue;
2878 }
2879
2880 if (In.getArgument().isPackExpansion()) {
2881 // We have a pack expansion, for which we will be substituting into
2882 // the pattern.
2883 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002884 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002885 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00002886 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2887 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002888
2889 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2890 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2891 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2892
2893 // Determine whether the set of unexpanded parameter packs can and should
2894 // be expanded.
2895 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002896 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002897 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002898 if (getDerived().TryExpandParameterPacks(Ellipsis,
2899 Pattern.getSourceRange(),
2900 Unexpanded.data(),
2901 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002902 Expand,
2903 RetainExpansion,
2904 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002905 return true;
2906
2907 if (!Expand) {
2908 // The transform has determined that we should perform a simple
2909 // transformation on the pack expansion, producing another pack
2910 // expansion.
2911 TemplateArgumentLoc OutPattern;
2912 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2913 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2914 return true;
2915
Douglas Gregorcded4f62011-01-14 17:04:44 +00002916 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2917 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002918 if (Out.getArgument().isNull())
2919 return true;
2920
2921 Outputs.addArgument(Out);
2922 continue;
2923 }
2924
2925 // The transform has determined that we should perform an elementwise
2926 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002927 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002928 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2929
2930 if (getDerived().TransformTemplateArgument(Pattern, Out))
2931 return true;
2932
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002933 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00002934 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2935 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002936 if (Out.getArgument().isNull())
2937 return true;
2938 }
2939
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002940 Outputs.addArgument(Out);
2941 }
2942
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002943 // If we're supposed to retain a pack expansion, do so by temporarily
2944 // forgetting the partially-substituted parameter pack.
2945 if (RetainExpansion) {
2946 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2947
2948 if (getDerived().TransformTemplateArgument(Pattern, Out))
2949 return true;
2950
Douglas Gregorcded4f62011-01-14 17:04:44 +00002951 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2952 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002953 if (Out.getArgument().isNull())
2954 return true;
2955
2956 Outputs.addArgument(Out);
2957 }
Douglas Gregord3731192011-01-10 07:32:04 +00002958
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002959 continue;
2960 }
2961
2962 // The simple case:
2963 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002964 return true;
2965
2966 Outputs.addArgument(Out);
2967 }
2968
2969 return false;
2970
2971}
2972
Douglas Gregor577f75a2009-08-04 16:50:30 +00002973//===----------------------------------------------------------------------===//
2974// Type transformation
2975//===----------------------------------------------------------------------===//
2976
2977template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002978QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002979 if (getDerived().AlreadyTransformed(T))
2980 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002981
John McCalla2becad2009-10-21 00:40:46 +00002982 // Temporary workaround. All of these transformations should
2983 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00002984 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2985 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002986
John McCall43fed0d2010-11-12 08:19:04 +00002987 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002988
John McCalla2becad2009-10-21 00:40:46 +00002989 if (!NewDI)
2990 return QualType();
2991
2992 return NewDI->getType();
2993}
2994
2995template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002996TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002997 if (getDerived().AlreadyTransformed(DI->getType()))
2998 return DI;
2999
3000 TypeLocBuilder TLB;
3001
3002 TypeLoc TL = DI->getTypeLoc();
3003 TLB.reserve(TL.getFullDataSize());
3004
John McCall43fed0d2010-11-12 08:19:04 +00003005 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003006 if (Result.isNull())
3007 return 0;
3008
John McCalla93c9342009-12-07 02:54:59 +00003009 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003010}
3011
3012template<typename Derived>
3013QualType
John McCall43fed0d2010-11-12 08:19:04 +00003014TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003015 switch (T.getTypeLocClass()) {
3016#define ABSTRACT_TYPELOC(CLASS, PARENT)
3017#define TYPELOC(CLASS, PARENT) \
3018 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003019 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003020#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003021 }
Mike Stump1eb44332009-09-09 15:08:12 +00003022
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003023 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003024 return QualType();
3025}
3026
3027/// FIXME: By default, this routine adds type qualifiers only to types
3028/// that can have qualifiers, and silently suppresses those qualifiers
3029/// that are not permitted (e.g., qualifiers on reference or function
3030/// types). This is the right thing for template instantiation, but
3031/// probably not for other clients.
3032template<typename Derived>
3033QualType
3034TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003035 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003036 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003037
John McCall43fed0d2010-11-12 08:19:04 +00003038 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003039 if (Result.isNull())
3040 return QualType();
3041
3042 // Silently suppress qualifiers if the result type can't be qualified.
3043 // FIXME: this is the right thing for template instantiation, but
3044 // probably not for other clients.
3045 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003046 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003047
John McCall28654742010-06-05 06:41:15 +00003048 if (!Quals.empty()) {
3049 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3050 TLB.push<QualifiedTypeLoc>(Result);
3051 // No location information to preserve.
3052 }
John McCalla2becad2009-10-21 00:40:46 +00003053
3054 return Result;
3055}
3056
John McCall43fed0d2010-11-12 08:19:04 +00003057/// \brief Transforms a type that was written in a scope specifier,
3058/// given an object type, the results of unqualified lookup, and
3059/// an already-instantiated prefix.
3060///
3061/// The object type is provided iff the scope specifier qualifies the
3062/// member of a dependent member-access expression. The prefix is
3063/// provided iff the the scope specifier in which this appears has a
3064/// prefix.
3065///
3066/// This is private to TreeTransform.
3067template<typename Derived>
3068QualType
3069TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3070 QualType ObjectType,
3071 NamedDecl *UnqualLookup,
3072 NestedNameSpecifier *Prefix) {
3073 if (getDerived().AlreadyTransformed(T))
3074 return T;
3075
3076 TypeSourceInfo *TSI =
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003077 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall43fed0d2010-11-12 08:19:04 +00003078
3079 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3080 UnqualLookup, Prefix);
3081 if (!TSI) return QualType();
3082 return TSI->getType();
3083}
3084
3085template<typename Derived>
3086TypeSourceInfo *
3087TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3088 QualType ObjectType,
3089 NamedDecl *UnqualLookup,
3090 NestedNameSpecifier *Prefix) {
3091 // TODO: in some cases, we might be some verification to do here.
3092 if (ObjectType.isNull())
3093 return getDerived().TransformType(TSI);
3094
3095 QualType T = TSI->getType();
3096 if (getDerived().AlreadyTransformed(T))
3097 return TSI;
3098
3099 TypeLocBuilder TLB;
3100 QualType Result;
3101
3102 if (isa<TemplateSpecializationType>(T)) {
3103 TemplateSpecializationTypeLoc TL
3104 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3105
3106 TemplateName Template =
3107 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3108 ObjectType, UnqualLookup);
3109 if (Template.isNull()) return 0;
3110
3111 Result = getDerived()
3112 .TransformTemplateSpecializationType(TLB, TL, Template);
3113 } else if (isa<DependentTemplateSpecializationType>(T)) {
3114 DependentTemplateSpecializationTypeLoc TL
3115 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3116
3117 Result = getDerived()
3118 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3119 } else {
3120 // Nothing special needs to be done for these.
3121 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3122 }
3123
3124 if (Result.isNull()) return 0;
3125 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3126}
3127
John McCalla2becad2009-10-21 00:40:46 +00003128template <class TyLoc> static inline
3129QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3130 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3131 NewT.setNameLoc(T.getNameLoc());
3132 return T.getType();
3133}
3134
John McCalla2becad2009-10-21 00:40:46 +00003135template<typename Derived>
3136QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003137 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003138 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3139 NewT.setBuiltinLoc(T.getBuiltinLoc());
3140 if (T.needsExtraLocalData())
3141 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3142 return T.getType();
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>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003147 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003148 // FIXME: recurse?
3149 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003150}
Mike Stump1eb44332009-09-09 15:08:12 +00003151
Douglas Gregor577f75a2009-08-04 16:50:30 +00003152template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003153QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003154 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003155 QualType PointeeType
3156 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003157 if (PointeeType.isNull())
3158 return QualType();
3159
3160 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003161 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003162 // A dependent pointer type 'T *' has is being transformed such
3163 // that an Objective-C class type is being replaced for 'T'. The
3164 // resulting pointer type is an ObjCObjectPointerType, not a
3165 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003166 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003167
John McCallc12c5bb2010-05-15 11:32:37 +00003168 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3169 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003170 return Result;
3171 }
John McCall43fed0d2010-11-12 08:19:04 +00003172
Douglas Gregor92e986e2010-04-22 16:44:27 +00003173 if (getDerived().AlwaysRebuild() ||
3174 PointeeType != TL.getPointeeLoc().getType()) {
3175 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3176 if (Result.isNull())
3177 return QualType();
3178 }
Sean Huntc3021132010-05-05 15:23:54 +00003179
Douglas Gregor92e986e2010-04-22 16:44:27 +00003180 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3181 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003182 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003183}
Mike Stump1eb44332009-09-09 15:08:12 +00003184
3185template<typename Derived>
3186QualType
John McCalla2becad2009-10-21 00:40:46 +00003187TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003188 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003189 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003190 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3191 if (PointeeType.isNull())
3192 return QualType();
3193
3194 QualType Result = TL.getType();
3195 if (getDerived().AlwaysRebuild() ||
3196 PointeeType != TL.getPointeeLoc().getType()) {
3197 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003198 TL.getSigilLoc());
3199 if (Result.isNull())
3200 return QualType();
3201 }
3202
Douglas Gregor39968ad2010-04-22 16:50:51 +00003203 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003204 NewT.setSigilLoc(TL.getSigilLoc());
3205 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003206}
3207
John McCall85737a72009-10-30 00:06:24 +00003208/// Transforms a reference type. Note that somewhat paradoxically we
3209/// don't care whether the type itself is an l-value type or an r-value
3210/// type; we only care if the type was *written* as an l-value type
3211/// or an r-value type.
3212template<typename Derived>
3213QualType
3214TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003215 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003216 const ReferenceType *T = TL.getTypePtr();
3217
3218 // Note that this works with the pointee-as-written.
3219 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3220 if (PointeeType.isNull())
3221 return QualType();
3222
3223 QualType Result = TL.getType();
3224 if (getDerived().AlwaysRebuild() ||
3225 PointeeType != T->getPointeeTypeAsWritten()) {
3226 Result = getDerived().RebuildReferenceType(PointeeType,
3227 T->isSpelledAsLValue(),
3228 TL.getSigilLoc());
3229 if (Result.isNull())
3230 return QualType();
3231 }
3232
3233 // r-value references can be rebuilt as l-value references.
3234 ReferenceTypeLoc NewTL;
3235 if (isa<LValueReferenceType>(Result))
3236 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3237 else
3238 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3239 NewTL.setSigilLoc(TL.getSigilLoc());
3240
3241 return Result;
3242}
3243
Mike Stump1eb44332009-09-09 15:08:12 +00003244template<typename Derived>
3245QualType
John McCalla2becad2009-10-21 00:40:46 +00003246TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003247 LValueReferenceTypeLoc TL) {
3248 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003249}
3250
Mike Stump1eb44332009-09-09 15:08:12 +00003251template<typename Derived>
3252QualType
John McCalla2becad2009-10-21 00:40:46 +00003253TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003254 RValueReferenceTypeLoc TL) {
3255 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003256}
Mike Stump1eb44332009-09-09 15:08:12 +00003257
Douglas Gregor577f75a2009-08-04 16:50:30 +00003258template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003259QualType
John McCalla2becad2009-10-21 00:40:46 +00003260TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003261 MemberPointerTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003262 const MemberPointerType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003263
3264 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003265 if (PointeeType.isNull())
3266 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003267
John McCalla2becad2009-10-21 00:40:46 +00003268 // TODO: preserve source information for this.
3269 QualType ClassType
3270 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003271 if (ClassType.isNull())
3272 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003273
John McCalla2becad2009-10-21 00:40:46 +00003274 QualType Result = TL.getType();
3275 if (getDerived().AlwaysRebuild() ||
3276 PointeeType != T->getPointeeType() ||
3277 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003278 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3279 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003280 if (Result.isNull())
3281 return QualType();
3282 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003283
John McCalla2becad2009-10-21 00:40:46 +00003284 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3285 NewTL.setSigilLoc(TL.getSigilLoc());
3286
3287 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003288}
3289
Mike Stump1eb44332009-09-09 15:08:12 +00003290template<typename Derived>
3291QualType
John McCalla2becad2009-10-21 00:40:46 +00003292TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003293 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003294 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003295 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003296 if (ElementType.isNull())
3297 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003298
John McCalla2becad2009-10-21 00:40:46 +00003299 QualType Result = TL.getType();
3300 if (getDerived().AlwaysRebuild() ||
3301 ElementType != T->getElementType()) {
3302 Result = getDerived().RebuildConstantArrayType(ElementType,
3303 T->getSizeModifier(),
3304 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003305 T->getIndexTypeCVRQualifiers(),
3306 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003307 if (Result.isNull())
3308 return QualType();
3309 }
Sean Huntc3021132010-05-05 15:23:54 +00003310
John McCalla2becad2009-10-21 00:40:46 +00003311 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3312 NewTL.setLBracketLoc(TL.getLBracketLoc());
3313 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003314
John McCalla2becad2009-10-21 00:40:46 +00003315 Expr *Size = TL.getSizeExpr();
3316 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003317 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003318 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3319 }
3320 NewTL.setSizeExpr(Size);
3321
3322 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003323}
Mike Stump1eb44332009-09-09 15:08:12 +00003324
Douglas Gregor577f75a2009-08-04 16:50:30 +00003325template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003326QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003327 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003328 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003329 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003330 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003331 if (ElementType.isNull())
3332 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003333
John McCalla2becad2009-10-21 00:40:46 +00003334 QualType Result = TL.getType();
3335 if (getDerived().AlwaysRebuild() ||
3336 ElementType != T->getElementType()) {
3337 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003338 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003339 T->getIndexTypeCVRQualifiers(),
3340 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003341 if (Result.isNull())
3342 return QualType();
3343 }
Sean Huntc3021132010-05-05 15:23:54 +00003344
John McCalla2becad2009-10-21 00:40:46 +00003345 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3346 NewTL.setLBracketLoc(TL.getLBracketLoc());
3347 NewTL.setRBracketLoc(TL.getRBracketLoc());
3348 NewTL.setSizeExpr(0);
3349
3350 return Result;
3351}
3352
3353template<typename Derived>
3354QualType
3355TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003356 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003357 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003358 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3359 if (ElementType.isNull())
3360 return QualType();
3361
3362 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003363 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003364
John McCall60d7b3a2010-08-24 06:29:42 +00003365 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003366 = getDerived().TransformExpr(T->getSizeExpr());
3367 if (SizeResult.isInvalid())
3368 return QualType();
3369
John McCall9ae2f072010-08-23 23:25:46 +00003370 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003371
3372 QualType Result = TL.getType();
3373 if (getDerived().AlwaysRebuild() ||
3374 ElementType != T->getElementType() ||
3375 Size != T->getSizeExpr()) {
3376 Result = getDerived().RebuildVariableArrayType(ElementType,
3377 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003378 Size,
John McCalla2becad2009-10-21 00:40:46 +00003379 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003380 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003381 if (Result.isNull())
3382 return QualType();
3383 }
Sean Huntc3021132010-05-05 15:23:54 +00003384
John McCalla2becad2009-10-21 00:40:46 +00003385 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3386 NewTL.setLBracketLoc(TL.getLBracketLoc());
3387 NewTL.setRBracketLoc(TL.getRBracketLoc());
3388 NewTL.setSizeExpr(Size);
3389
3390 return Result;
3391}
3392
3393template<typename Derived>
3394QualType
3395TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003396 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003397 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003398 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3399 if (ElementType.isNull())
3400 return QualType();
3401
3402 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003403 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003404
John McCall3b657512011-01-19 10:06:00 +00003405 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3406 Expr *origSize = TL.getSizeExpr();
3407 if (!origSize) origSize = T->getSizeExpr();
3408
3409 ExprResult sizeResult
3410 = getDerived().TransformExpr(origSize);
3411 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003412 return QualType();
3413
John McCall3b657512011-01-19 10:06:00 +00003414 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003415
3416 QualType Result = TL.getType();
3417 if (getDerived().AlwaysRebuild() ||
3418 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003419 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003420 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3421 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003422 size,
John McCalla2becad2009-10-21 00:40:46 +00003423 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003424 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003425 if (Result.isNull())
3426 return QualType();
3427 }
John McCalla2becad2009-10-21 00:40:46 +00003428
3429 // We might have any sort of array type now, but fortunately they
3430 // all have the same location layout.
3431 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3432 NewTL.setLBracketLoc(TL.getLBracketLoc());
3433 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003434 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003435
3436 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003437}
Mike Stump1eb44332009-09-09 15:08:12 +00003438
3439template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003440QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003441 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003442 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003443 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003444
3445 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003446 QualType ElementType = getDerived().TransformType(T->getElementType());
3447 if (ElementType.isNull())
3448 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003449
Douglas Gregor670444e2009-08-04 22:27:00 +00003450 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003451 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003452
John McCall60d7b3a2010-08-24 06:29:42 +00003453 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003454 if (Size.isInvalid())
3455 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003456
John McCalla2becad2009-10-21 00:40:46 +00003457 QualType Result = TL.getType();
3458 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003459 ElementType != T->getElementType() ||
3460 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003461 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003462 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003463 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003464 if (Result.isNull())
3465 return QualType();
3466 }
John McCalla2becad2009-10-21 00:40:46 +00003467
3468 // Result might be dependent or not.
3469 if (isa<DependentSizedExtVectorType>(Result)) {
3470 DependentSizedExtVectorTypeLoc NewTL
3471 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3472 NewTL.setNameLoc(TL.getNameLoc());
3473 } else {
3474 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3475 NewTL.setNameLoc(TL.getNameLoc());
3476 }
3477
3478 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003479}
Mike Stump1eb44332009-09-09 15:08:12 +00003480
3481template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003482QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003483 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003484 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003485 QualType ElementType = getDerived().TransformType(T->getElementType());
3486 if (ElementType.isNull())
3487 return QualType();
3488
John McCalla2becad2009-10-21 00:40:46 +00003489 QualType Result = TL.getType();
3490 if (getDerived().AlwaysRebuild() ||
3491 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003492 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003493 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003494 if (Result.isNull())
3495 return QualType();
3496 }
Sean Huntc3021132010-05-05 15:23:54 +00003497
John McCalla2becad2009-10-21 00:40:46 +00003498 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3499 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003500
John McCalla2becad2009-10-21 00:40:46 +00003501 return Result;
3502}
3503
3504template<typename Derived>
3505QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003506 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003507 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003508 QualType ElementType = getDerived().TransformType(T->getElementType());
3509 if (ElementType.isNull())
3510 return QualType();
3511
3512 QualType Result = TL.getType();
3513 if (getDerived().AlwaysRebuild() ||
3514 ElementType != T->getElementType()) {
3515 Result = getDerived().RebuildExtVectorType(ElementType,
3516 T->getNumElements(),
3517 /*FIXME*/ SourceLocation());
3518 if (Result.isNull())
3519 return QualType();
3520 }
Sean Huntc3021132010-05-05 15:23:54 +00003521
John McCalla2becad2009-10-21 00:40:46 +00003522 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3523 NewTL.setNameLoc(TL.getNameLoc());
3524
3525 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003526}
Mike Stump1eb44332009-09-09 15:08:12 +00003527
3528template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003529ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003530TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3531 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003532 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003533 TypeSourceInfo *NewDI = 0;
3534
3535 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3536 // If we're substituting into a pack expansion type and we know the
3537 TypeLoc OldTL = OldDI->getTypeLoc();
3538 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3539
3540 TypeLocBuilder TLB;
3541 TypeLoc NewTL = OldDI->getTypeLoc();
3542 TLB.reserve(NewTL.getFullDataSize());
3543
3544 QualType Result = getDerived().TransformType(TLB,
3545 OldExpansionTL.getPatternLoc());
3546 if (Result.isNull())
3547 return 0;
3548
3549 Result = RebuildPackExpansionType(Result,
3550 OldExpansionTL.getPatternLoc().getSourceRange(),
3551 OldExpansionTL.getEllipsisLoc(),
3552 NumExpansions);
3553 if (Result.isNull())
3554 return 0;
3555
3556 PackExpansionTypeLoc NewExpansionTL
3557 = TLB.push<PackExpansionTypeLoc>(Result);
3558 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3559 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3560 } else
3561 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003562 if (!NewDI)
3563 return 0;
3564
3565 if (NewDI == OldDI)
3566 return OldParm;
3567 else
3568 return ParmVarDecl::Create(SemaRef.Context,
3569 OldParm->getDeclContext(),
3570 OldParm->getLocation(),
3571 OldParm->getIdentifier(),
3572 NewDI->getType(),
3573 NewDI,
3574 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003575 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003576 /* DefArg */ NULL);
3577}
3578
3579template<typename Derived>
3580bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003581 TransformFunctionTypeParams(SourceLocation Loc,
3582 ParmVarDecl **Params, unsigned NumParams,
3583 const QualType *ParamTypes,
3584 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3585 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3586 for (unsigned i = 0; i != NumParams; ++i) {
3587 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003588 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003589 if (OldParm->isParameterPack()) {
3590 // We have a function parameter pack that may need to be expanded.
3591 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003592
Douglas Gregor603cfb42011-01-05 23:12:31 +00003593 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003594 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3595 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3596 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3597 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003598
3599 // Determine whether we should expand the parameter packs.
3600 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003601 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003602 llvm::Optional<unsigned> OrigNumExpansions
3603 = ExpansionTL.getTypePtr()->getNumExpansions();
3604 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003605 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3606 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003607 Unexpanded.data(),
3608 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003609 ShouldExpand,
3610 RetainExpansion,
3611 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003612 return true;
3613 }
3614
3615 if (ShouldExpand) {
3616 // Expand the function parameter pack into multiple, separate
3617 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003618 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003619 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003620 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3621 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003622 = getDerived().TransformFunctionTypeParam(OldParm,
3623 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003624 if (!NewParm)
3625 return true;
3626
Douglas Gregora009b592011-01-07 00:20:55 +00003627 OutParamTypes.push_back(NewParm->getType());
3628 if (PVars)
3629 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003630 }
Douglas Gregord3731192011-01-10 07:32:04 +00003631
3632 // If we're supposed to retain a pack expansion, do so by temporarily
3633 // forgetting the partially-substituted parameter pack.
3634 if (RetainExpansion) {
3635 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3636 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003637 = getDerived().TransformFunctionTypeParam(OldParm,
3638 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003639 if (!NewParm)
3640 return true;
3641
3642 OutParamTypes.push_back(NewParm->getType());
3643 if (PVars)
3644 PVars->push_back(NewParm);
3645 }
3646
Douglas Gregor603cfb42011-01-05 23:12:31 +00003647 // We're done with the pack expansion.
3648 continue;
3649 }
3650
3651 // We'll substitute the parameter now without expanding the pack
3652 // expansion.
3653 }
3654
3655 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003656 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3657 NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +00003658 if (!NewParm)
3659 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003660
Douglas Gregora009b592011-01-07 00:20:55 +00003661 OutParamTypes.push_back(NewParm->getType());
3662 if (PVars)
3663 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003664 continue;
3665 }
John McCall21ef0fa2010-03-11 09:03:00 +00003666
3667 // Deal with the possibility that we don't have a parameter
3668 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003669 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003670 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003671 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003672 if (const PackExpansionType *Expansion
3673 = dyn_cast<PackExpansionType>(OldType)) {
3674 // We have a function parameter pack that may need to be expanded.
3675 QualType Pattern = Expansion->getPattern();
3676 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3677 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3678
3679 // Determine whether we should expand the parameter packs.
3680 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003681 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003682 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003683 Unexpanded.data(),
3684 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003685 ShouldExpand,
3686 RetainExpansion,
3687 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003688 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003689 }
3690
3691 if (ShouldExpand) {
3692 // Expand the function parameter pack into multiple, separate
3693 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003694 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003695 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3696 QualType NewType = getDerived().TransformType(Pattern);
3697 if (NewType.isNull())
3698 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003699
Douglas Gregora009b592011-01-07 00:20:55 +00003700 OutParamTypes.push_back(NewType);
3701 if (PVars)
3702 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003703 }
3704
3705 // We're done with the pack expansion.
3706 continue;
3707 }
3708
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003709 // If we're supposed to retain a pack expansion, do so by temporarily
3710 // forgetting the partially-substituted parameter pack.
3711 if (RetainExpansion) {
3712 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3713 QualType NewType = getDerived().TransformType(Pattern);
3714 if (NewType.isNull())
3715 return true;
3716
3717 OutParamTypes.push_back(NewType);
3718 if (PVars)
3719 PVars->push_back(0);
3720 }
Douglas Gregord3731192011-01-10 07:32:04 +00003721
Douglas Gregor603cfb42011-01-05 23:12:31 +00003722 // We'll substitute the parameter now without expanding the pack
3723 // expansion.
3724 OldType = Expansion->getPattern();
3725 IsPackExpansion = true;
3726 }
3727
3728 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3729 QualType NewType = getDerived().TransformType(OldType);
3730 if (NewType.isNull())
3731 return true;
3732
3733 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003734 NewType = getSema().Context.getPackExpansionType(NewType,
3735 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003736
Douglas Gregora009b592011-01-07 00:20:55 +00003737 OutParamTypes.push_back(NewType);
3738 if (PVars)
3739 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003740 }
3741
3742 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003743 }
John McCall21ef0fa2010-03-11 09:03:00 +00003744
3745template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003746QualType
John McCalla2becad2009-10-21 00:40:46 +00003747TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003748 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003749 // Transform the parameters and return type.
3750 //
3751 // We instantiate in source order, with the return type first followed by
3752 // the parameters, because users tend to expect this (even if they shouldn't
3753 // rely on it!).
3754 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003755 // When the function has a trailing return type, we instantiate the
3756 // parameters before the return type, since the return type can then refer
3757 // to the parameters themselves (via decltype, sizeof, etc.).
3758 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003759 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003760 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003761 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003762
Douglas Gregordab60ad2010-10-01 18:44:50 +00003763 QualType ResultType;
3764
3765 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003766 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3767 TL.getParmArray(),
3768 TL.getNumArgs(),
3769 TL.getTypePtr()->arg_type_begin(),
3770 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003771 return QualType();
3772
3773 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3774 if (ResultType.isNull())
3775 return QualType();
3776 }
3777 else {
3778 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3779 if (ResultType.isNull())
3780 return QualType();
3781
Douglas Gregora009b592011-01-07 00:20:55 +00003782 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3783 TL.getParmArray(),
3784 TL.getNumArgs(),
3785 TL.getTypePtr()->arg_type_begin(),
3786 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003787 return QualType();
3788 }
3789
John McCalla2becad2009-10-21 00:40:46 +00003790 QualType Result = TL.getType();
3791 if (getDerived().AlwaysRebuild() ||
3792 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003793 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003794 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3795 Result = getDerived().RebuildFunctionProtoType(ResultType,
3796 ParamTypes.data(),
3797 ParamTypes.size(),
3798 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003799 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00003800 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003801 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003802 if (Result.isNull())
3803 return QualType();
3804 }
Mike Stump1eb44332009-09-09 15:08:12 +00003805
John McCalla2becad2009-10-21 00:40:46 +00003806 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3807 NewTL.setLParenLoc(TL.getLParenLoc());
3808 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003809 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003810 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3811 NewTL.setArg(i, ParamDecls[i]);
3812
3813 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814}
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregor577f75a2009-08-04 16:50:30 +00003816template<typename Derived>
3817QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003818 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003819 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003820 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003821 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3822 if (ResultType.isNull())
3823 return QualType();
3824
3825 QualType Result = TL.getType();
3826 if (getDerived().AlwaysRebuild() ||
3827 ResultType != T->getResultType())
3828 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3829
3830 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3831 NewTL.setLParenLoc(TL.getLParenLoc());
3832 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003833 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003834
3835 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003836}
Mike Stump1eb44332009-09-09 15:08:12 +00003837
John McCalled976492009-12-04 22:46:56 +00003838template<typename Derived> QualType
3839TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003840 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003841 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003842 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003843 if (!D)
3844 return QualType();
3845
3846 QualType Result = TL.getType();
3847 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3848 Result = getDerived().RebuildUnresolvedUsingType(D);
3849 if (Result.isNull())
3850 return QualType();
3851 }
3852
3853 // We might get an arbitrary type spec type back. We should at
3854 // least always get a type spec type, though.
3855 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3856 NewTL.setNameLoc(TL.getNameLoc());
3857
3858 return Result;
3859}
3860
Douglas Gregor577f75a2009-08-04 16:50:30 +00003861template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003862QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003863 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003864 const TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003865 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003866 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3867 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003868 if (!Typedef)
3869 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003870
John McCalla2becad2009-10-21 00:40:46 +00003871 QualType Result = TL.getType();
3872 if (getDerived().AlwaysRebuild() ||
3873 Typedef != T->getDecl()) {
3874 Result = getDerived().RebuildTypedefType(Typedef);
3875 if (Result.isNull())
3876 return QualType();
3877 }
Mike Stump1eb44332009-09-09 15:08:12 +00003878
John McCalla2becad2009-10-21 00:40:46 +00003879 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3880 NewTL.setNameLoc(TL.getNameLoc());
3881
3882 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003883}
Mike Stump1eb44332009-09-09 15:08:12 +00003884
Douglas Gregor577f75a2009-08-04 16:50:30 +00003885template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003886QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003887 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003888 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003889 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003890
John McCall60d7b3a2010-08-24 06:29:42 +00003891 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892 if (E.isInvalid())
3893 return QualType();
3894
John McCalla2becad2009-10-21 00:40:46 +00003895 QualType Result = TL.getType();
3896 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003897 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003898 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003899 if (Result.isNull())
3900 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003901 }
John McCalla2becad2009-10-21 00:40:46 +00003902 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003903
John McCalla2becad2009-10-21 00:40:46 +00003904 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003905 NewTL.setTypeofLoc(TL.getTypeofLoc());
3906 NewTL.setLParenLoc(TL.getLParenLoc());
3907 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003908
3909 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003910}
Mike Stump1eb44332009-09-09 15:08:12 +00003911
3912template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003913QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003914 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003915 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3916 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3917 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003918 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003919
John McCalla2becad2009-10-21 00:40:46 +00003920 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003921 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3922 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003923 if (Result.isNull())
3924 return QualType();
3925 }
Mike Stump1eb44332009-09-09 15:08:12 +00003926
John McCalla2becad2009-10-21 00:40:46 +00003927 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003928 NewTL.setTypeofLoc(TL.getTypeofLoc());
3929 NewTL.setLParenLoc(TL.getLParenLoc());
3930 NewTL.setRParenLoc(TL.getRParenLoc());
3931 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003932
3933 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003934}
Mike Stump1eb44332009-09-09 15:08:12 +00003935
3936template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003937QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003938 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003939 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003940
Douglas Gregor670444e2009-08-04 22:27:00 +00003941 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003942 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003943
John McCall60d7b3a2010-08-24 06:29:42 +00003944 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003945 if (E.isInvalid())
3946 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003947
John McCalla2becad2009-10-21 00:40:46 +00003948 QualType Result = TL.getType();
3949 if (getDerived().AlwaysRebuild() ||
3950 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003951 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003952 if (Result.isNull())
3953 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003954 }
John McCalla2becad2009-10-21 00:40:46 +00003955 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003956
John McCalla2becad2009-10-21 00:40:46 +00003957 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3958 NewTL.setNameLoc(TL.getNameLoc());
3959
3960 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003961}
3962
3963template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003964QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003965 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003966 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003967 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003968 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3969 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003970 if (!Record)
3971 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003972
John McCalla2becad2009-10-21 00:40:46 +00003973 QualType Result = TL.getType();
3974 if (getDerived().AlwaysRebuild() ||
3975 Record != T->getDecl()) {
3976 Result = getDerived().RebuildRecordType(Record);
3977 if (Result.isNull())
3978 return QualType();
3979 }
Mike Stump1eb44332009-09-09 15:08:12 +00003980
John McCalla2becad2009-10-21 00:40:46 +00003981 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3982 NewTL.setNameLoc(TL.getNameLoc());
3983
3984 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003985}
Mike Stump1eb44332009-09-09 15:08:12 +00003986
3987template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003988QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003989 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003990 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003991 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003992 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3993 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003994 if (!Enum)
3995 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003996
John McCalla2becad2009-10-21 00:40:46 +00003997 QualType Result = TL.getType();
3998 if (getDerived().AlwaysRebuild() ||
3999 Enum != T->getDecl()) {
4000 Result = getDerived().RebuildEnumType(Enum);
4001 if (Result.isNull())
4002 return QualType();
4003 }
Mike Stump1eb44332009-09-09 15:08:12 +00004004
John McCalla2becad2009-10-21 00:40:46 +00004005 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4006 NewTL.setNameLoc(TL.getNameLoc());
4007
4008 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004009}
John McCall7da24312009-09-05 00:15:47 +00004010
John McCall3cb0ebd2010-03-10 03:28:59 +00004011template<typename Derived>
4012QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4013 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004014 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004015 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4016 TL.getTypePtr()->getDecl());
4017 if (!D) return QualType();
4018
4019 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4020 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4021 return T;
4022}
4023
Douglas Gregor577f75a2009-08-04 16:50:30 +00004024template<typename Derived>
4025QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004026 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004027 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004028 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004029}
4030
Mike Stump1eb44332009-09-09 15:08:12 +00004031template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004032QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004033 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004034 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004035 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00004036}
4037
4038template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004039QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4040 TypeLocBuilder &TLB,
4041 SubstTemplateTypeParmPackTypeLoc TL) {
4042 return TransformTypeSpecType(TLB, TL);
4043}
4044
4045template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004046QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004047 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004048 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004049 const TemplateSpecializationType *T = TL.getTypePtr();
4050
Mike Stump1eb44332009-09-09 15:08:12 +00004051 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00004052 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004053 if (Template.isNull())
4054 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004055
John McCall43fed0d2010-11-12 08:19:04 +00004056 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4057}
4058
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004059namespace {
4060 /// \brief Simple iterator that traverses the template arguments in a
4061 /// container that provides a \c getArgLoc() member function.
4062 ///
4063 /// This iterator is intended to be used with the iterator form of
4064 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4065 template<typename ArgLocContainer>
4066 class TemplateArgumentLocContainerIterator {
4067 ArgLocContainer *Container;
4068 unsigned Index;
4069
4070 public:
4071 typedef TemplateArgumentLoc value_type;
4072 typedef TemplateArgumentLoc reference;
4073 typedef int difference_type;
4074 typedef std::input_iterator_tag iterator_category;
4075
4076 class pointer {
4077 TemplateArgumentLoc Arg;
4078
4079 public:
4080 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4081
4082 const TemplateArgumentLoc *operator->() const {
4083 return &Arg;
4084 }
4085 };
4086
4087
4088 TemplateArgumentLocContainerIterator() {}
4089
4090 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4091 unsigned Index)
4092 : Container(&Container), Index(Index) { }
4093
4094 TemplateArgumentLocContainerIterator &operator++() {
4095 ++Index;
4096 return *this;
4097 }
4098
4099 TemplateArgumentLocContainerIterator operator++(int) {
4100 TemplateArgumentLocContainerIterator Old(*this);
4101 ++(*this);
4102 return Old;
4103 }
4104
4105 TemplateArgumentLoc operator*() const {
4106 return Container->getArgLoc(Index);
4107 }
4108
4109 pointer operator->() const {
4110 return pointer(Container->getArgLoc(Index));
4111 }
4112
4113 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004114 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004115 return X.Container == Y.Container && X.Index == Y.Index;
4116 }
4117
4118 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004119 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004120 return !(X == Y);
4121 }
4122 };
4123}
4124
4125
John McCall43fed0d2010-11-12 08:19:04 +00004126template <typename Derived>
4127QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4128 TypeLocBuilder &TLB,
4129 TemplateSpecializationTypeLoc TL,
4130 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004131 TemplateArgumentListInfo NewTemplateArgs;
4132 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4133 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004134 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4135 ArgIterator;
4136 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4137 ArgIterator(TL, TL.getNumArgs()),
4138 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004139 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004140
John McCall833ca992009-10-29 08:12:44 +00004141 // FIXME: maybe don't rebuild if all the template arguments are the same.
4142
4143 QualType Result =
4144 getDerived().RebuildTemplateSpecializationType(Template,
4145 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004146 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004147
4148 if (!Result.isNull()) {
4149 TemplateSpecializationTypeLoc NewTL
4150 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4151 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4152 NewTL.setLAngleLoc(TL.getLAngleLoc());
4153 NewTL.setRAngleLoc(TL.getRAngleLoc());
4154 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4155 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004156 }
Mike Stump1eb44332009-09-09 15:08:12 +00004157
John McCall833ca992009-10-29 08:12:44 +00004158 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004159}
Mike Stump1eb44332009-09-09 15:08:12 +00004160
4161template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004162QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004163TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004164 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004165 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004166
4167 NestedNameSpecifier *NNS = 0;
4168 // NOTE: the qualifier in an ElaboratedType is optional.
4169 if (T->getQualifier() != 0) {
4170 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004171 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004172 if (!NNS)
4173 return QualType();
4174 }
Mike Stump1eb44332009-09-09 15:08:12 +00004175
John McCall43fed0d2010-11-12 08:19:04 +00004176 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4177 if (NamedT.isNull())
4178 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004179
John McCalla2becad2009-10-21 00:40:46 +00004180 QualType Result = TL.getType();
4181 if (getDerived().AlwaysRebuild() ||
4182 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004183 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004184 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4185 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004186 if (Result.isNull())
4187 return QualType();
4188 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004189
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004190 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004191 NewTL.setKeywordLoc(TL.getKeywordLoc());
4192 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004193
4194 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004195}
Mike Stump1eb44332009-09-09 15:08:12 +00004196
4197template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004198QualType TreeTransform<Derived>::TransformAttributedType(
4199 TypeLocBuilder &TLB,
4200 AttributedTypeLoc TL) {
4201 const AttributedType *oldType = TL.getTypePtr();
4202 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4203 if (modifiedType.isNull())
4204 return QualType();
4205
4206 QualType result = TL.getType();
4207
4208 // FIXME: dependent operand expressions?
4209 if (getDerived().AlwaysRebuild() ||
4210 modifiedType != oldType->getModifiedType()) {
4211 // TODO: this is really lame; we should really be rebuilding the
4212 // equivalent type from first principles.
4213 QualType equivalentType
4214 = getDerived().TransformType(oldType->getEquivalentType());
4215 if (equivalentType.isNull())
4216 return QualType();
4217 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4218 modifiedType,
4219 equivalentType);
4220 }
4221
4222 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4223 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4224 if (TL.hasAttrOperand())
4225 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4226 if (TL.hasAttrExprOperand())
4227 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4228 else if (TL.hasAttrEnumOperand())
4229 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4230
4231 return result;
4232}
4233
4234template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004235QualType
4236TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4237 ParenTypeLoc TL) {
4238 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4239 if (Inner.isNull())
4240 return QualType();
4241
4242 QualType Result = TL.getType();
4243 if (getDerived().AlwaysRebuild() ||
4244 Inner != TL.getInnerLoc().getType()) {
4245 Result = getDerived().RebuildParenType(Inner);
4246 if (Result.isNull())
4247 return QualType();
4248 }
4249
4250 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4251 NewTL.setLParenLoc(TL.getLParenLoc());
4252 NewTL.setRParenLoc(TL.getRParenLoc());
4253 return Result;
4254}
4255
4256template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004257QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004258 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004259 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004260
Douglas Gregor577f75a2009-08-04 16:50:30 +00004261 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004262 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004263 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004264 if (!NNS)
4265 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004266
John McCall33500952010-06-11 00:33:02 +00004267 QualType Result
4268 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4269 T->getIdentifier(),
4270 TL.getKeywordLoc(),
4271 TL.getQualifierRange(),
4272 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004273 if (Result.isNull())
4274 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004275
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004276 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4277 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004278 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4279
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004280 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4281 NewTL.setKeywordLoc(TL.getKeywordLoc());
4282 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004283 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004284 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4285 NewTL.setKeywordLoc(TL.getKeywordLoc());
4286 NewTL.setQualifierRange(TL.getQualifierRange());
4287 NewTL.setNameLoc(TL.getNameLoc());
4288 }
John McCalla2becad2009-10-21 00:40:46 +00004289 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004290}
Mike Stump1eb44332009-09-09 15:08:12 +00004291
Douglas Gregor577f75a2009-08-04 16:50:30 +00004292template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004293QualType TreeTransform<Derived>::
4294 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004295 DependentTemplateSpecializationTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004296 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall33500952010-06-11 00:33:02 +00004297
4298 NestedNameSpecifier *NNS
4299 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004300 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004301 if (!NNS)
4302 return QualType();
4303
John McCall43fed0d2010-11-12 08:19:04 +00004304 return getDerived()
4305 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4306}
4307
4308template<typename Derived>
4309QualType TreeTransform<Derived>::
4310 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4311 DependentTemplateSpecializationTypeLoc TL,
4312 NestedNameSpecifier *NNS) {
John McCallf4c73712011-01-19 06:33:43 +00004313 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall43fed0d2010-11-12 08:19:04 +00004314
John McCall33500952010-06-11 00:33:02 +00004315 TemplateArgumentListInfo NewTemplateArgs;
4316 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4317 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004318
4319 typedef TemplateArgumentLocContainerIterator<
4320 DependentTemplateSpecializationTypeLoc> ArgIterator;
4321 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4322 ArgIterator(TL, TL.getNumArgs()),
4323 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004324 return QualType();
John McCall33500952010-06-11 00:33:02 +00004325
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004326 QualType Result
4327 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4328 NNS,
4329 TL.getQualifierRange(),
4330 T->getIdentifier(),
4331 TL.getNameLoc(),
4332 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004333 if (Result.isNull())
4334 return QualType();
4335
4336 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4337 QualType NamedT = ElabT->getNamedType();
4338
4339 // Copy information relevant to the template specialization.
4340 TemplateSpecializationTypeLoc NamedTL
4341 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4342 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4343 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4344 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4345 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4346
4347 // Copy information relevant to the elaborated type.
4348 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4349 NewTL.setKeywordLoc(TL.getKeywordLoc());
4350 NewTL.setQualifierRange(TL.getQualifierRange());
4351 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004352 TypeLoc NewTL(Result, TL.getOpaqueData());
4353 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004354 }
4355 return Result;
4356}
4357
4358template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004359QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4360 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004361 QualType Pattern
4362 = getDerived().TransformType(TLB, TL.getPatternLoc());
4363 if (Pattern.isNull())
4364 return QualType();
4365
4366 QualType Result = TL.getType();
4367 if (getDerived().AlwaysRebuild() ||
4368 Pattern != TL.getPatternLoc().getType()) {
4369 Result = getDerived().RebuildPackExpansionType(Pattern,
4370 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004371 TL.getEllipsisLoc(),
4372 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004373 if (Result.isNull())
4374 return QualType();
4375 }
4376
4377 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4378 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4379 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004380}
4381
4382template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004383QualType
4384TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004385 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004386 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004387 TLB.pushFullCopy(TL);
4388 return TL.getType();
4389}
4390
4391template<typename Derived>
4392QualType
4393TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004394 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004395 // ObjCObjectType is never dependent.
4396 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004397 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004398}
Mike Stump1eb44332009-09-09 15:08:12 +00004399
4400template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004401QualType
4402TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004403 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004404 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004405 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004406 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004407}
4408
Douglas Gregor577f75a2009-08-04 16:50:30 +00004409//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004410// Statement transformation
4411//===----------------------------------------------------------------------===//
4412template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004413StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004414TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004415 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004416}
4417
4418template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004419StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004420TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4421 return getDerived().TransformCompoundStmt(S, false);
4422}
4423
4424template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004425StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004426TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004427 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004428 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004429 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004430 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004431 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4432 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004433 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004434 if (Result.isInvalid()) {
4435 // Immediately fail if this was a DeclStmt, since it's very
4436 // likely that this will cause problems for future statements.
4437 if (isa<DeclStmt>(*B))
4438 return StmtError();
4439
4440 // Otherwise, just keep processing substatements and fail later.
4441 SubStmtInvalid = true;
4442 continue;
4443 }
Mike Stump1eb44332009-09-09 15:08:12 +00004444
Douglas Gregor43959a92009-08-20 07:17:43 +00004445 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4446 Statements.push_back(Result.takeAs<Stmt>());
4447 }
Mike Stump1eb44332009-09-09 15:08:12 +00004448
John McCall7114cba2010-08-27 19:56:05 +00004449 if (SubStmtInvalid)
4450 return StmtError();
4451
Douglas Gregor43959a92009-08-20 07:17:43 +00004452 if (!getDerived().AlwaysRebuild() &&
4453 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004454 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004455
4456 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4457 move_arg(Statements),
4458 S->getRBracLoc(),
4459 IsStmtExpr);
4460}
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Douglas Gregor43959a92009-08-20 07:17:43 +00004462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004463StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004464TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004465 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004466 {
4467 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004468 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004469
Eli Friedman264c1f82009-11-19 03:14:00 +00004470 // Transform the left-hand case value.
4471 LHS = getDerived().TransformExpr(S->getLHS());
4472 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004473 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Eli Friedman264c1f82009-11-19 03:14:00 +00004475 // Transform the right-hand case value (for the GNU case-range extension).
4476 RHS = getDerived().TransformExpr(S->getRHS());
4477 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004478 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004479 }
Mike Stump1eb44332009-09-09 15:08:12 +00004480
Douglas Gregor43959a92009-08-20 07:17:43 +00004481 // Build the case statement.
4482 // Case statements are always rebuilt so that they will attached to their
4483 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004484 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004485 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004486 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004487 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004488 S->getColonLoc());
4489 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004490 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004491
Douglas Gregor43959a92009-08-20 07:17:43 +00004492 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004493 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004494 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004495 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004496
Douglas Gregor43959a92009-08-20 07:17:43 +00004497 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004498 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004499}
4500
4501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004502StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004503TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004504 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004505 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004506 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004507 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004508
Douglas Gregor43959a92009-08-20 07:17:43 +00004509 // Default statements are always rebuilt
4510 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004511 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004512}
Mike Stump1eb44332009-09-09 15:08:12 +00004513
Douglas Gregor43959a92009-08-20 07:17:43 +00004514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004515StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004516TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004517 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004518 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004519 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004520
Douglas Gregor43959a92009-08-20 07:17:43 +00004521 // FIXME: Pass the real colon location in.
4522 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4523 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004524 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004525}
Mike Stump1eb44332009-09-09 15:08:12 +00004526
Douglas Gregor43959a92009-08-20 07:17:43 +00004527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004528StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004529TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004530 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004531 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004532 VarDecl *ConditionVar = 0;
4533 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004534 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004535 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004536 getDerived().TransformDefinition(
4537 S->getConditionVariable()->getLocation(),
4538 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004539 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004540 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004541 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004542 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004543
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004544 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004545 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004546
4547 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004548 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004549 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4550 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004551 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004552 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004553
John McCall9ae2f072010-08-23 23:25:46 +00004554 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004555 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004556 }
Sean Huntc3021132010-05-05 15:23:54 +00004557
John McCall9ae2f072010-08-23 23:25:46 +00004558 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4559 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004560 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004561
Douglas Gregor43959a92009-08-20 07:17:43 +00004562 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004563 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004564 if (Then.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 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004568 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004569 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004570 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004571
Douglas Gregor43959a92009-08-20 07:17:43 +00004572 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004573 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004574 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004575 Then.get() == S->getThen() &&
4576 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004577 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004578
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004579 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004580 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004581 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004582}
4583
4584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004585StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004586TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004587 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004588 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004589 VarDecl *ConditionVar = 0;
4590 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004591 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004592 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004593 getDerived().TransformDefinition(
4594 S->getConditionVariable()->getLocation(),
4595 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004596 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004597 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004598 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004599 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004600
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004601 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004602 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004603 }
Mike Stump1eb44332009-09-09 15:08:12 +00004604
Douglas Gregor43959a92009-08-20 07:17:43 +00004605 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004606 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004607 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004608 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004609 if (Switch.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 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004613 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004614 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004615 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004616
Douglas Gregor43959a92009-08-20 07:17:43 +00004617 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004618 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4619 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004620}
Mike Stump1eb44332009-09-09 15:08:12 +00004621
Douglas Gregor43959a92009-08-20 07:17:43 +00004622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004623StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004624TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004625 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004626 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004627 VarDecl *ConditionVar = 0;
4628 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004629 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004630 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004631 getDerived().TransformDefinition(
4632 S->getConditionVariable()->getLocation(),
4633 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004634 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004635 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004636 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004637 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004638
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004639 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004640 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004641
4642 if (S->getCond()) {
4643 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004644 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4645 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004646 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004647 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004648 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004649 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004650 }
Mike Stump1eb44332009-09-09 15:08:12 +00004651
John McCall9ae2f072010-08-23 23:25:46 +00004652 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4653 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004654 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004655
Douglas Gregor43959a92009-08-20 07:17:43 +00004656 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004657 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004658 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004659 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004660
Douglas Gregor43959a92009-08-20 07:17:43 +00004661 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004662 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004663 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004664 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004665 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004666
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004667 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004668 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004669}
Mike Stump1eb44332009-09-09 15:08:12 +00004670
Douglas Gregor43959a92009-08-20 07:17:43 +00004671template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004672StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004673TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004674 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004675 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004676 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004677 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004678
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004679 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004680 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004681 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004682 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004683
Douglas Gregor43959a92009-08-20 07:17:43 +00004684 if (!getDerived().AlwaysRebuild() &&
4685 Cond.get() == S->getCond() &&
4686 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004687 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004688
John McCall9ae2f072010-08-23 23:25:46 +00004689 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4690 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004691 S->getRParenLoc());
4692}
Mike Stump1eb44332009-09-09 15:08:12 +00004693
Douglas Gregor43959a92009-08-20 07:17:43 +00004694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004695StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004696TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004697 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004698 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004699 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004700 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregor43959a92009-08-20 07:17:43 +00004702 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004703 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004704 VarDecl *ConditionVar = 0;
4705 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004706 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004707 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004708 getDerived().TransformDefinition(
4709 S->getConditionVariable()->getLocation(),
4710 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004711 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004712 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004713 } else {
4714 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004715
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004716 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004717 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004718
4719 if (S->getCond()) {
4720 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004721 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4722 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004723 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004724 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004725
John McCall9ae2f072010-08-23 23:25:46 +00004726 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004727 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004728 }
Mike Stump1eb44332009-09-09 15:08:12 +00004729
John McCall9ae2f072010-08-23 23:25:46 +00004730 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4731 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004732 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004733
Douglas Gregor43959a92009-08-20 07:17:43 +00004734 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004735 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004736 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004737 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
John McCall9ae2f072010-08-23 23:25:46 +00004739 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4740 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004741 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004742
Douglas Gregor43959a92009-08-20 07:17:43 +00004743 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004744 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004745 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004746 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004747
Douglas Gregor43959a92009-08-20 07:17:43 +00004748 if (!getDerived().AlwaysRebuild() &&
4749 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004750 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004751 Inc.get() == S->getInc() &&
4752 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004753 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Douglas Gregor43959a92009-08-20 07:17:43 +00004755 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004756 Init.get(), FullCond, ConditionVar,
4757 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004758}
4759
4760template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004761StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004762TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004763 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004764 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004765 S->getLabel());
4766}
4767
4768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004769StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004770TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004771 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004772 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004773 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004774
Douglas Gregor43959a92009-08-20 07:17:43 +00004775 if (!getDerived().AlwaysRebuild() &&
4776 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004777 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004778
4779 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004780 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004781}
4782
4783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004784StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004785TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004786 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004787}
Mike Stump1eb44332009-09-09 15:08:12 +00004788
Douglas Gregor43959a92009-08-20 07:17:43 +00004789template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004790StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004791TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004792 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004793}
Mike Stump1eb44332009-09-09 15:08:12 +00004794
Douglas Gregor43959a92009-08-20 07:17:43 +00004795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004796StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004797TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004798 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004799 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004800 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004801
Mike Stump1eb44332009-09-09 15:08:12 +00004802 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004803 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004804 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004805}
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregor43959a92009-08-20 07:17:43 +00004807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004808StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004809TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004810 bool DeclChanged = false;
4811 llvm::SmallVector<Decl *, 4> Decls;
4812 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4813 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004814 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4815 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004816 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004817 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004818
Douglas Gregor43959a92009-08-20 07:17:43 +00004819 if (Transformed != *D)
4820 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004821
Douglas Gregor43959a92009-08-20 07:17:43 +00004822 Decls.push_back(Transformed);
4823 }
Mike Stump1eb44332009-09-09 15:08:12 +00004824
Douglas Gregor43959a92009-08-20 07:17:43 +00004825 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004826 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004827
4828 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004829 S->getStartLoc(), S->getEndLoc());
4830}
Mike Stump1eb44332009-09-09 15:08:12 +00004831
Douglas Gregor43959a92009-08-20 07:17:43 +00004832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004833StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004834TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004835 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004836 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004837}
4838
4839template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004840StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004841TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004842
John McCallca0408f2010-08-23 06:44:23 +00004843 ASTOwningVector<Expr*> Constraints(getSema());
4844 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004845 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004846
John McCall60d7b3a2010-08-24 06:29:42 +00004847 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004848 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004849
4850 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004851
Anders Carlsson703e3942010-01-24 05:50:09 +00004852 // Go through the outputs.
4853 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004854 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004855
Anders Carlsson703e3942010-01-24 05:50:09 +00004856 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004857 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004858
Anders Carlsson703e3942010-01-24 05:50:09 +00004859 // Transform the output expr.
4860 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004861 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004862 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004863 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004864
Anders Carlsson703e3942010-01-24 05:50:09 +00004865 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004866
John McCall9ae2f072010-08-23 23:25:46 +00004867 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004868 }
Sean Huntc3021132010-05-05 15:23:54 +00004869
Anders Carlsson703e3942010-01-24 05:50:09 +00004870 // Go through the inputs.
4871 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004872 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004873
Anders Carlsson703e3942010-01-24 05:50:09 +00004874 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004875 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004876
Anders Carlsson703e3942010-01-24 05:50:09 +00004877 // Transform the input expr.
4878 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004879 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004880 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004881 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004882
Anders Carlsson703e3942010-01-24 05:50:09 +00004883 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004884
John McCall9ae2f072010-08-23 23:25:46 +00004885 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004886 }
Sean Huntc3021132010-05-05 15:23:54 +00004887
Anders Carlsson703e3942010-01-24 05:50:09 +00004888 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004889 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004890
4891 // Go through the clobbers.
4892 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004893 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004894
4895 // No need to transform the asm string literal.
4896 AsmString = SemaRef.Owned(S->getAsmString());
4897
4898 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4899 S->isSimple(),
4900 S->isVolatile(),
4901 S->getNumOutputs(),
4902 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004903 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004904 move_arg(Constraints),
4905 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004906 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004907 move_arg(Clobbers),
4908 S->getRParenLoc(),
4909 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004910}
4911
4912
4913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004914StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004915TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004916 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004917 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004918 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004919 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004920
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004921 // Transform the @catch statements (if present).
4922 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004923 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004924 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004925 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004926 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004927 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004928 if (Catch.get() != S->getCatchStmt(I))
4929 AnyCatchChanged = true;
4930 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004931 }
Sean Huntc3021132010-05-05 15:23:54 +00004932
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004933 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004934 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004935 if (S->getFinallyStmt()) {
4936 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4937 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004938 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004939 }
4940
4941 // If nothing changed, just retain this statement.
4942 if (!getDerived().AlwaysRebuild() &&
4943 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004944 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004945 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004946 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004947
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004948 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004949 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4950 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004951}
Mike Stump1eb44332009-09-09 15:08:12 +00004952
Douglas Gregor43959a92009-08-20 07:17:43 +00004953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004954StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004955TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004956 // Transform the @catch parameter, if there is one.
4957 VarDecl *Var = 0;
4958 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4959 TypeSourceInfo *TSInfo = 0;
4960 if (FromVar->getTypeSourceInfo()) {
4961 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4962 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004963 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004964 }
Sean Huntc3021132010-05-05 15:23:54 +00004965
Douglas Gregorbe270a02010-04-26 17:57:08 +00004966 QualType T;
4967 if (TSInfo)
4968 T = TSInfo->getType();
4969 else {
4970 T = getDerived().TransformType(FromVar->getType());
4971 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004972 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004973 }
Sean Huntc3021132010-05-05 15:23:54 +00004974
Douglas Gregorbe270a02010-04-26 17:57:08 +00004975 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4976 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004977 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004978 }
Sean Huntc3021132010-05-05 15:23:54 +00004979
John McCall60d7b3a2010-08-24 06:29:42 +00004980 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004981 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004982 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004983
4984 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004985 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004986 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004987}
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Douglas Gregor43959a92009-08-20 07:17:43 +00004989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004990StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004991TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004992 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004993 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004994 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004995 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004996
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004997 // If nothing changed, just retain this statement.
4998 if (!getDerived().AlwaysRebuild() &&
4999 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005000 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005001
5002 // Build a new statement.
5003 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005004 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005005}
Mike Stump1eb44332009-09-09 15:08:12 +00005006
Douglas Gregor43959a92009-08-20 07:17:43 +00005007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005008StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005009TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005010 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005011 if (S->getThrowExpr()) {
5012 Operand = getDerived().TransformExpr(S->getThrowExpr());
5013 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005014 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005015 }
Sean Huntc3021132010-05-05 15:23:54 +00005016
Douglas Gregord1377b22010-04-22 21:44:01 +00005017 if (!getDerived().AlwaysRebuild() &&
5018 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005019 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005020
John McCall9ae2f072010-08-23 23:25:46 +00005021 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005022}
Mike Stump1eb44332009-09-09 15:08:12 +00005023
Douglas Gregor43959a92009-08-20 07:17:43 +00005024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005025StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005026TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005027 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005028 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005029 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005030 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005031 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005032
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005033 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005034 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005035 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005036 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005037
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005038 // If nothing change, just retain the current statement.
5039 if (!getDerived().AlwaysRebuild() &&
5040 Object.get() == S->getSynchExpr() &&
5041 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005042 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005043
5044 // Build a new statement.
5045 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005046 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005047}
5048
5049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005050StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005051TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005052 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005053 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005054 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005055 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005056 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005057
Douglas Gregorc3203e72010-04-22 23:10:45 +00005058 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005059 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005060 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005061 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005062
Douglas Gregorc3203e72010-04-22 23:10:45 +00005063 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005064 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005065 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005066 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005067
Douglas Gregorc3203e72010-04-22 23:10:45 +00005068 // If nothing changed, just retain this statement.
5069 if (!getDerived().AlwaysRebuild() &&
5070 Element.get() == S->getElement() &&
5071 Collection.get() == S->getCollection() &&
5072 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005073 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005074
Douglas Gregorc3203e72010-04-22 23:10:45 +00005075 // Build a new statement.
5076 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5077 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005078 Element.get(),
5079 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005080 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005081 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005082}
5083
5084
5085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005087TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5088 // Transform the exception declaration, if any.
5089 VarDecl *Var = 0;
5090 if (S->getExceptionDecl()) {
5091 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005092 TypeSourceInfo *T = getDerived().TransformType(
5093 ExceptionDecl->getTypeSourceInfo());
5094 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005095 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregor83cb9422010-09-09 17:09:21 +00005097 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005099 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005100 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005101 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 }
Mike Stump1eb44332009-09-09 15:08:12 +00005103
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005105 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005106 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005107 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005108
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 if (!getDerived().AlwaysRebuild() &&
5110 !Var &&
5111 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005112 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005113
5114 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5115 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005116 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005117}
Mike Stump1eb44332009-09-09 15:08:12 +00005118
Douglas Gregor43959a92009-08-20 07:17:43 +00005119template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005120StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005121TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5122 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005123 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 = getDerived().TransformCompoundStmt(S->getTryBlock());
5125 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 // Transform the handlers.
5129 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005130 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005132 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5134 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005135 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5138 Handlers.push_back(Handler.takeAs<Stmt>());
5139 }
Mike Stump1eb44332009-09-09 15:08:12 +00005140
Douglas Gregor43959a92009-08-20 07:17:43 +00005141 if (!getDerived().AlwaysRebuild() &&
5142 TryBlock.get() == S->getTryBlock() &&
5143 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005144 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005145
John McCall9ae2f072010-08-23 23:25:46 +00005146 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005147 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005148}
Mike Stump1eb44332009-09-09 15:08:12 +00005149
Douglas Gregor43959a92009-08-20 07:17:43 +00005150//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005151// Expression transformation
5152//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005154ExprResult
John McCall454feb92009-12-08 09:21:05 +00005155TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005156 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157}
Mike Stump1eb44332009-09-09 15:08:12 +00005158
5159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005160ExprResult
John McCall454feb92009-12-08 09:21:05 +00005161TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005162 NestedNameSpecifier *Qualifier = 0;
5163 if (E->getQualifier()) {
5164 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005165 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005166 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005167 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005168 }
John McCalldbd872f2009-12-08 09:08:17 +00005169
5170 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005171 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5172 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005173 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005174 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005175
John McCallec8045d2010-08-17 21:27:17 +00005176 DeclarationNameInfo NameInfo = E->getNameInfo();
5177 if (NameInfo.getName()) {
5178 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5179 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005180 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005181 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005182
5183 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005184 Qualifier == E->getQualifier() &&
5185 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005186 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005187 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005188
5189 // Mark it referenced in the new context regardless.
5190 // FIXME: this is a bit instantiation-specific.
5191 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5192
John McCall3fa5cae2010-10-26 07:05:15 +00005193 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005194 }
John McCalldbd872f2009-12-08 09:08:17 +00005195
5196 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005197 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005198 TemplateArgs = &TransArgs;
5199 TransArgs.setLAngleLoc(E->getLAngleLoc());
5200 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005201 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5202 E->getNumTemplateArgs(),
5203 TransArgs))
5204 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005205 }
5206
Douglas Gregora2813ce2009-10-23 18:54:35 +00005207 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005208 ND, NameInfo, TemplateArgs);
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>::TransformIntegerLiteral(IntegerLiteral *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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005226 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005227}
Mike Stump1eb44332009-09-09 15:08:12 +00005228
Douglas Gregorb98b1992009-08-11 05:31:07 +00005229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005230ExprResult
John McCall454feb92009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005232 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233}
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005236ExprResult
John McCall454feb92009-12-08 09:21:05 +00005237TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005238 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005239}
5240
5241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005242ExprResult
John McCall454feb92009-12-08 09:21:05 +00005243TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005244 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005245 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005247
Douglas Gregorb98b1992009-08-11 05:31:07 +00005248 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005249 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005250
John McCall9ae2f072010-08-23 23:25:46 +00005251 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005252 E->getRParen());
5253}
5254
Mike Stump1eb44332009-09-09 15:08:12 +00005255template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005256ExprResult
John McCall454feb92009-12-08 09:21:05 +00005257TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005258 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005260 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005261
Douglas Gregorb98b1992009-08-11 05:31:07 +00005262 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005263 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005264
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5266 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005267 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005268}
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005271ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005272TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5273 // Transform the type.
5274 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5275 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005276 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005277
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005278 // Transform all of the components into components similar to what the
5279 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005280 // FIXME: It would be slightly more efficient in the non-dependent case to
5281 // just map FieldDecls, rather than requiring the rebuilder to look for
5282 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005283 // template code that we don't care.
5284 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005285 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005286 typedef OffsetOfExpr::OffsetOfNode Node;
5287 llvm::SmallVector<Component, 4> Components;
5288 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5289 const Node &ON = E->getComponent(I);
5290 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005291 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005292 Comp.LocStart = ON.getRange().getBegin();
5293 Comp.LocEnd = ON.getRange().getEnd();
5294 switch (ON.getKind()) {
5295 case Node::Array: {
5296 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005297 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005298 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005299 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005300
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005301 ExprChanged = ExprChanged || Index.get() != FromIndex;
5302 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005303 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005304 break;
5305 }
Sean Huntc3021132010-05-05 15:23:54 +00005306
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005307 case Node::Field:
5308 case Node::Identifier:
5309 Comp.isBrackets = false;
5310 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005311 if (!Comp.U.IdentInfo)
5312 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005313
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005314 break;
Sean Huntc3021132010-05-05 15:23:54 +00005315
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005316 case Node::Base:
5317 // Will be recomputed during the rebuild.
5318 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005319 }
Sean Huntc3021132010-05-05 15:23:54 +00005320
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005321 Components.push_back(Comp);
5322 }
Sean Huntc3021132010-05-05 15:23:54 +00005323
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005324 // If nothing changed, retain the existing expression.
5325 if (!getDerived().AlwaysRebuild() &&
5326 Type == E->getTypeSourceInfo() &&
5327 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005328 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005329
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005330 // Build a new offsetof expression.
5331 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5332 Components.data(), Components.size(),
5333 E->getRParenLoc());
5334}
5335
5336template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005337ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005338TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5339 assert(getDerived().AlreadyTransformed(E->getType()) &&
5340 "opaque value expression requires transformation");
5341 return SemaRef.Owned(E);
5342}
5343
5344template<typename Derived>
5345ExprResult
John McCall454feb92009-12-08 09:21:05 +00005346TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005347 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005348 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005349
John McCalla93c9342009-12-07 02:54:59 +00005350 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005351 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005353
John McCall5ab75172009-11-04 07:28:41 +00005354 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005355 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005356
John McCall5ab75172009-11-04 07:28:41 +00005357 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005358 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005359 E->getSourceRange());
5360 }
Mike Stump1eb44332009-09-09 15:08:12 +00005361
John McCall60d7b3a2010-08-24 06:29:42 +00005362 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005363 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005364 // C++0x [expr.sizeof]p1:
5365 // The operand is either an expression, which is an unevaluated operand
5366 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005367 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005368
Douglas Gregorb98b1992009-08-11 05:31:07 +00005369 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5370 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005371 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregorb98b1992009-08-11 05:31:07 +00005373 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005374 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005375 }
Mike Stump1eb44332009-09-09 15:08:12 +00005376
John McCall9ae2f072010-08-23 23:25:46 +00005377 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005378 E->isSizeOf(),
5379 E->getSourceRange());
5380}
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005383ExprResult
John McCall454feb92009-12-08 09:21:05 +00005384TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005385 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005386 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005388
John McCall60d7b3a2010-08-24 06:29:42 +00005389 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005390 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005392
5393
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394 if (!getDerived().AlwaysRebuild() &&
5395 LHS.get() == E->getLHS() &&
5396 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005397 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005398
John McCall9ae2f072010-08-23 23:25:46 +00005399 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005400 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005401 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005402 E->getRBracketLoc());
5403}
Mike Stump1eb44332009-09-09 15:08:12 +00005404
5405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005406ExprResult
John McCall454feb92009-12-08 09:21:05 +00005407TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005408 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005409 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005410 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005411 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005412
5413 // Transform arguments.
5414 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005415 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005416 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5417 &ArgChanged))
5418 return ExprError();
5419
Douglas Gregorb98b1992009-08-11 05:31:07 +00005420 if (!getDerived().AlwaysRebuild() &&
5421 Callee.get() == E->getCallee() &&
5422 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005423 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005424
Douglas Gregorb98b1992009-08-11 05:31:07 +00005425 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005426 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005427 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005428 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005429 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005430 E->getRParenLoc());
5431}
Mike Stump1eb44332009-09-09 15:08:12 +00005432
5433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005434ExprResult
John McCall454feb92009-12-08 09:21:05 +00005435TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005436 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005437 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005438 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005439
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005440 NestedNameSpecifier *Qualifier = 0;
5441 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005442 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005443 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005444 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005445 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005446 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005447 }
Mike Stump1eb44332009-09-09 15:08:12 +00005448
Eli Friedmanf595cc42009-12-04 06:40:45 +00005449 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005450 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5451 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005452 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005453 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005454
John McCall6bb80172010-03-30 21:47:33 +00005455 NamedDecl *FoundDecl = E->getFoundDecl();
5456 if (FoundDecl == E->getMemberDecl()) {
5457 FoundDecl = Member;
5458 } else {
5459 FoundDecl = cast_or_null<NamedDecl>(
5460 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5461 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005462 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005463 }
5464
Douglas Gregorb98b1992009-08-11 05:31:07 +00005465 if (!getDerived().AlwaysRebuild() &&
5466 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005467 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005468 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005469 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005470 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005471
Anders Carlsson1f240322009-12-22 05:24:09 +00005472 // Mark it referenced in the new context regardless.
5473 // FIXME: this is a bit instantiation-specific.
5474 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005475 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005476 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005477
John McCalld5532b62009-11-23 01:53:49 +00005478 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005479 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005480 TransArgs.setLAngleLoc(E->getLAngleLoc());
5481 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005482 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5483 E->getNumTemplateArgs(),
5484 TransArgs))
5485 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005486 }
Sean Huntc3021132010-05-05 15:23:54 +00005487
Douglas Gregorb98b1992009-08-11 05:31:07 +00005488 // FIXME: Bogus source location for the operator
5489 SourceLocation FakeOperatorLoc
5490 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5491
John McCallc2233c52010-01-15 08:34:02 +00005492 // FIXME: to do this check properly, we will need to preserve the
5493 // first-qualifier-in-scope here, just in case we had a dependent
5494 // base (and therefore couldn't do the check) and a
5495 // nested-name-qualifier (and therefore could do the lookup).
5496 NamedDecl *FirstQualifierInScope = 0;
5497
John McCall9ae2f072010-08-23 23:25:46 +00005498 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005499 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005500 Qualifier,
5501 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005502 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005503 Member,
John McCall6bb80172010-03-30 21:47:33 +00005504 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005505 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005506 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005507 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005508}
Mike Stump1eb44332009-09-09 15:08:12 +00005509
Douglas Gregorb98b1992009-08-11 05:31:07 +00005510template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005511ExprResult
John McCall454feb92009-12-08 09:21:05 +00005512TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005513 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005514 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005516
John McCall60d7b3a2010-08-24 06:29:42 +00005517 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005518 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005519 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregorb98b1992009-08-11 05:31:07 +00005521 if (!getDerived().AlwaysRebuild() &&
5522 LHS.get() == E->getLHS() &&
5523 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005524 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregorb98b1992009-08-11 05:31:07 +00005526 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005527 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528}
5529
Mike Stump1eb44332009-09-09 15:08:12 +00005530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005531ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005532TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005533 CompoundAssignOperator *E) {
5534 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005535}
Mike Stump1eb44332009-09-09 15:08:12 +00005536
Douglas Gregorb98b1992009-08-11 05:31:07 +00005537template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005538ExprResult
John McCall454feb92009-12-08 09:21:05 +00005539TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005541 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005542 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005543
John McCall60d7b3a2010-08-24 06:29:42 +00005544 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005546 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005547
John McCall60d7b3a2010-08-24 06:29:42 +00005548 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005549 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005551
Douglas Gregorb98b1992009-08-11 05:31:07 +00005552 if (!getDerived().AlwaysRebuild() &&
5553 Cond.get() == E->getCond() &&
5554 LHS.get() == E->getLHS() &&
5555 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005556 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005557
John McCall9ae2f072010-08-23 23:25:46 +00005558 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005559 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005560 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005561 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005562 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005563}
Mike Stump1eb44332009-09-09 15:08:12 +00005564
5565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005566ExprResult
John McCall454feb92009-12-08 09:21:05 +00005567TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005568 // Implicit casts are eliminated during transformation, since they
5569 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005570 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005571}
Mike Stump1eb44332009-09-09 15:08:12 +00005572
Douglas Gregorb98b1992009-08-11 05:31:07 +00005573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005574ExprResult
John McCall454feb92009-12-08 09:21:05 +00005575TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005576 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5577 if (!Type)
5578 return ExprError();
5579
John McCall60d7b3a2010-08-24 06:29:42 +00005580 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005581 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005582 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005583 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005584
Douglas Gregorb98b1992009-08-11 05:31:07 +00005585 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005586 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005588 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005589
John McCall9d125032010-01-15 18:39:57 +00005590 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005591 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005592 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005593 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005594}
Mike Stump1eb44332009-09-09 15:08:12 +00005595
Douglas Gregorb98b1992009-08-11 05:31:07 +00005596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005597ExprResult
John McCall454feb92009-12-08 09:21:05 +00005598TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005599 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5600 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5601 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005602 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005603
John McCall60d7b3a2010-08-24 06:29:42 +00005604 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005609 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005610 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005611 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612
John McCall1d7d8d62010-01-19 22:33:45 +00005613 // Note: the expression type doesn't necessarily match the
5614 // type-as-written, but that's okay, because it should always be
5615 // derivable from the initializer.
5616
John McCall42f56b52010-01-18 19:35:47 +00005617 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005618 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005619 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005620}
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Douglas Gregorb98b1992009-08-11 05:31:07 +00005622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005623ExprResult
John McCall454feb92009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005625 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005626 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005627 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005628
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629 if (!getDerived().AlwaysRebuild() &&
5630 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005631 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005632
Douglas Gregorb98b1992009-08-11 05:31:07 +00005633 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005634 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005636 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005637 E->getAccessorLoc(),
5638 E->getAccessor());
5639}
Mike Stump1eb44332009-09-09 15:08:12 +00005640
Douglas Gregorb98b1992009-08-11 05:31:07 +00005641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005642ExprResult
John McCall454feb92009-12-08 09:21:05 +00005643TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005645
John McCallca0408f2010-08-23 06:44:23 +00005646 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005647 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5648 Inits, &InitChanged))
5649 return ExprError();
5650
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005652 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005653
Douglas Gregorb98b1992009-08-11 05:31:07 +00005654 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005655 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656}
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005659ExprResult
John McCall454feb92009-12-08 09:21:05 +00005660TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005662
Douglas Gregor43959a92009-08-20 07:17:43 +00005663 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005664 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregor43959a92009-08-20 07:17:43 +00005668 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005669 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670 bool ExprChanged = false;
5671 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5672 DEnd = E->designators_end();
5673 D != DEnd; ++D) {
5674 if (D->isFieldDesignator()) {
5675 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5676 D->getDotLoc(),
5677 D->getFieldLoc()));
5678 continue;
5679 }
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregorb98b1992009-08-11 05:31:07 +00005681 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005682 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005685
5686 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005687 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregorb98b1992009-08-11 05:31:07 +00005689 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5690 ArrayExprs.push_back(Index.release());
5691 continue;
5692 }
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005695 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5697 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005698 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005699
John McCall60d7b3a2010-08-24 06:29:42 +00005700 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005701 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005702 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005703
5704 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005705 End.get(),
5706 D->getLBracketLoc(),
5707 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005708
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5710 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005711
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712 ArrayExprs.push_back(Start.release());
5713 ArrayExprs.push_back(End.release());
5714 }
Mike Stump1eb44332009-09-09 15:08:12 +00005715
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716 if (!getDerived().AlwaysRebuild() &&
5717 Init.get() == E->getInit() &&
5718 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005719 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005720
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5722 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005723 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724}
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregorb98b1992009-08-11 05:31:07 +00005726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005727ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005729 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005730 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005731
Douglas Gregor5557b252009-10-28 00:29:27 +00005732 // FIXME: Will we ever have proper type location here? Will we actually
5733 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734 QualType T = getDerived().TransformType(E->getType());
5735 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005736 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005737
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 if (!getDerived().AlwaysRebuild() &&
5739 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005740 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005741
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 return getDerived().RebuildImplicitValueInitExpr(T);
5743}
Mike Stump1eb44332009-09-09 15:08:12 +00005744
Douglas Gregorb98b1992009-08-11 05:31:07 +00005745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005746ExprResult
John McCall454feb92009-12-08 09:21:05 +00005747TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005748 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5749 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005751
John McCall60d7b3a2010-08-24 06:29:42 +00005752 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005754 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005755
Douglas Gregorb98b1992009-08-11 05:31:07 +00005756 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005757 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005759 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005760
John McCall9ae2f072010-08-23 23:25:46 +00005761 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005762 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005763}
5764
5765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005766ExprResult
John McCall454feb92009-12-08 09:21:05 +00005767TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005768 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005769 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005770 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5771 &ArgumentChanged))
5772 return ExprError();
5773
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5775 move_arg(Inits),
5776 E->getRParenLoc());
5777}
Mike Stump1eb44332009-09-09 15:08:12 +00005778
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779/// \brief Transform an address-of-label expression.
5780///
5781/// By default, the transformation of an address-of-label expression always
5782/// rebuilds the expression, so that the label identifier can be resolved to
5783/// the corresponding label statement by semantic analysis.
5784template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005785ExprResult
John McCall454feb92009-12-08 09:21:05 +00005786TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5788 E->getLabel());
5789}
Mike Stump1eb44332009-09-09 15:08:12 +00005790
5791template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005792ExprResult
John McCall454feb92009-12-08 09:21:05 +00005793TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005794 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005795 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5796 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005797 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005798
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 if (!getDerived().AlwaysRebuild() &&
5800 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005801 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005802
5803 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005804 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005805 E->getRParenLoc());
5806}
Mike Stump1eb44332009-09-09 15:08:12 +00005807
Douglas Gregorb98b1992009-08-11 05:31:07 +00005808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005809ExprResult
John McCall454feb92009-12-08 09:21:05 +00005810TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005811 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005814
John McCall60d7b3a2010-08-24 06:29:42 +00005815 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005817 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005818
John McCall60d7b3a2010-08-24 06:29:42 +00005819 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005822
Douglas Gregorb98b1992009-08-11 05:31:07 +00005823 if (!getDerived().AlwaysRebuild() &&
5824 Cond.get() == E->getCond() &&
5825 LHS.get() == E->getLHS() &&
5826 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005827 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005828
Douglas Gregorb98b1992009-08-11 05:31:07 +00005829 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005830 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831 E->getRParenLoc());
5832}
Mike Stump1eb44332009-09-09 15:08:12 +00005833
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005835ExprResult
John McCall454feb92009-12-08 09:21:05 +00005836TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005837 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005838}
5839
5840template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005841ExprResult
John McCall454feb92009-12-08 09:21:05 +00005842TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005843 switch (E->getOperator()) {
5844 case OO_New:
5845 case OO_Delete:
5846 case OO_Array_New:
5847 case OO_Array_Delete:
5848 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005849 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005850
Douglas Gregor668d6d92009-12-13 20:44:55 +00005851 case OO_Call: {
5852 // This is a call to an object's operator().
5853 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5854
5855 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005856 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005857 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005858 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005859
5860 // FIXME: Poor location information
5861 SourceLocation FakeLParenLoc
5862 = SemaRef.PP.getLocForEndOfToken(
5863 static_cast<Expr *>(Object.get())->getLocEnd());
5864
5865 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005866 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005867 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5868 Args))
5869 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005870
John McCall9ae2f072010-08-23 23:25:46 +00005871 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005872 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005873 E->getLocEnd());
5874 }
5875
5876#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5877 case OO_##Name:
5878#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5879#include "clang/Basic/OperatorKinds.def"
5880 case OO_Subscript:
5881 // Handled below.
5882 break;
5883
5884 case OO_Conditional:
5885 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005886 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005887
5888 case OO_None:
5889 case NUM_OVERLOADED_OPERATORS:
5890 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005891 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005892 }
5893
John McCall60d7b3a2010-08-24 06:29:42 +00005894 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005895 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005896 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005897
John McCall60d7b3a2010-08-24 06:29:42 +00005898 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005899 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005900 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005901
John McCall60d7b3a2010-08-24 06:29:42 +00005902 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005903 if (E->getNumArgs() == 2) {
5904 Second = getDerived().TransformExpr(E->getArg(1));
5905 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005906 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005907 }
Mike Stump1eb44332009-09-09 15:08:12 +00005908
Douglas Gregorb98b1992009-08-11 05:31:07 +00005909 if (!getDerived().AlwaysRebuild() &&
5910 Callee.get() == E->getCallee() &&
5911 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005912 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005913 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005914
Douglas Gregorb98b1992009-08-11 05:31:07 +00005915 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5916 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005917 Callee.get(),
5918 First.get(),
5919 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005920}
Mike Stump1eb44332009-09-09 15:08:12 +00005921
Douglas Gregorb98b1992009-08-11 05:31:07 +00005922template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005923ExprResult
John McCall454feb92009-12-08 09:21:05 +00005924TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5925 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005926}
Mike Stump1eb44332009-09-09 15:08:12 +00005927
Douglas Gregorb98b1992009-08-11 05:31:07 +00005928template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005929ExprResult
John McCall454feb92009-12-08 09:21:05 +00005930TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005931 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5932 if (!Type)
5933 return ExprError();
5934
John McCall60d7b3a2010-08-24 06:29:42 +00005935 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005936 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005937 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005938 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005939
Douglas Gregorb98b1992009-08-11 05:31:07 +00005940 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005941 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005942 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005943 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005944
Douglas Gregorb98b1992009-08-11 05:31:07 +00005945 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005946 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005947 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5948 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5949 SourceLocation FakeRParenLoc
5950 = SemaRef.PP.getLocForEndOfToken(
5951 E->getSubExpr()->getSourceRange().getEnd());
5952 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005953 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005954 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005955 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005956 FakeRAngleLoc,
5957 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005958 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005959 FakeRParenLoc);
5960}
Mike Stump1eb44332009-09-09 15:08:12 +00005961
Douglas Gregorb98b1992009-08-11 05:31:07 +00005962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005963ExprResult
John McCall454feb92009-12-08 09:21:05 +00005964TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5965 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005966}
Mike Stump1eb44332009-09-09 15:08:12 +00005967
5968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005969ExprResult
John McCall454feb92009-12-08 09:21:05 +00005970TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5971 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005972}
5973
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005975ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005977 CXXReinterpretCastExpr *E) {
5978 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005979}
Mike Stump1eb44332009-09-09 15:08:12 +00005980
Douglas Gregorb98b1992009-08-11 05:31:07 +00005981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005982ExprResult
John McCall454feb92009-12-08 09:21:05 +00005983TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5984 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005985}
Mike Stump1eb44332009-09-09 15:08:12 +00005986
Douglas Gregorb98b1992009-08-11 05:31:07 +00005987template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005988ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005989TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005990 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005991 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5992 if (!Type)
5993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005994
John McCall60d7b3a2010-08-24 06:29:42 +00005995 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005996 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005998 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005999
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006001 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006002 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006003 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006004
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006005 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006006 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006007 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006008 E->getRParenLoc());
6009}
Mike Stump1eb44332009-09-09 15:08:12 +00006010
Douglas Gregorb98b1992009-08-11 05:31:07 +00006011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006012ExprResult
John McCall454feb92009-12-08 09:21:05 +00006013TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006014 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006015 TypeSourceInfo *TInfo
6016 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6017 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006021 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006022 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006023
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006024 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6025 E->getLocStart(),
6026 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006027 E->getLocEnd());
6028 }
Mike Stump1eb44332009-09-09 15:08:12 +00006029
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030 // We don't know whether the expression is potentially evaluated until
6031 // after we perform semantic analysis, so the expression is potentially
6032 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006033 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006034 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006035
John McCall60d7b3a2010-08-24 06:29:42 +00006036 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006037 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006039
Douglas Gregorb98b1992009-08-11 05:31:07 +00006040 if (!getDerived().AlwaysRebuild() &&
6041 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006042 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006043
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006044 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6045 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006046 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047 E->getLocEnd());
6048}
6049
6050template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006051ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006052TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6053 if (E->isTypeOperand()) {
6054 TypeSourceInfo *TInfo
6055 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6056 if (!TInfo)
6057 return ExprError();
6058
6059 if (!getDerived().AlwaysRebuild() &&
6060 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006061 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006062
6063 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6064 E->getLocStart(),
6065 TInfo,
6066 E->getLocEnd());
6067 }
6068
6069 // We don't know whether the expression is potentially evaluated until
6070 // after we perform semantic analysis, so the expression is potentially
6071 // potentially evaluated.
6072 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6073
6074 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6075 if (SubExpr.isInvalid())
6076 return ExprError();
6077
6078 if (!getDerived().AlwaysRebuild() &&
6079 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006081
6082 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6083 E->getLocStart(),
6084 SubExpr.get(),
6085 E->getLocEnd());
6086}
6087
6088template<typename Derived>
6089ExprResult
John McCall454feb92009-12-08 09:21:05 +00006090TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006091 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006092}
Mike Stump1eb44332009-09-09 15:08:12 +00006093
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006095ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006097 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006098 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006099}
Mike Stump1eb44332009-09-09 15:08:12 +00006100
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006102ExprResult
John McCall454feb92009-12-08 09:21:05 +00006103TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006104 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6105 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6106 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006107
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006108 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006109 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006110
Douglas Gregor828a1972010-01-07 23:12:05 +00006111 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112}
Mike Stump1eb44332009-09-09 15:08:12 +00006113
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006115ExprResult
John McCall454feb92009-12-08 09:21:05 +00006116TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006117 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121 if (!getDerived().AlwaysRebuild() &&
6122 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006123 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124
John McCall9ae2f072010-08-23 23:25:46 +00006125 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126}
Mike Stump1eb44332009-09-09 15:08:12 +00006127
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006129ExprResult
John McCall454feb92009-12-08 09:21:05 +00006130TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006131 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006132 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6133 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006134 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006135 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006136
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006137 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006139 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006140
Douglas Gregor036aed12009-12-23 23:03:06 +00006141 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142}
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006145ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006146TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6147 CXXScalarValueInitExpr *E) {
6148 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6149 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006150 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006153 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006154 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006155
Douglas Gregorab6677e2010-09-08 00:15:04 +00006156 return getDerived().RebuildCXXScalarValueInitExpr(T,
6157 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006158 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159}
Mike Stump1eb44332009-09-09 15:08:12 +00006160
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006162ExprResult
John McCall454feb92009-12-08 09:21:05 +00006163TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006165 TypeSourceInfo *AllocTypeInfo
6166 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6167 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006169
Douglas Gregorb98b1992009-08-11 05:31:07 +00006170 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006171 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006172 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006174
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175 // Transform the placement arguments (if any).
6176 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006177 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006178 if (getDerived().TransformExprs(E->getPlacementArgs(),
6179 E->getNumPlacementArgs(), true,
6180 PlacementArgs, &ArgumentChanged))
6181 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006182
Douglas Gregor43959a92009-08-20 07:17:43 +00006183 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006184 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006185 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6186 ConstructorArgs, &ArgumentChanged))
6187 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006188
Douglas Gregor1af74512010-02-26 00:38:10 +00006189 // Transform constructor, new operator, and delete operator.
6190 CXXConstructorDecl *Constructor = 0;
6191 if (E->getConstructor()) {
6192 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006193 getDerived().TransformDecl(E->getLocStart(),
6194 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006195 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006196 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006197 }
6198
6199 FunctionDecl *OperatorNew = 0;
6200 if (E->getOperatorNew()) {
6201 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006202 getDerived().TransformDecl(E->getLocStart(),
6203 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006204 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006206 }
6207
6208 FunctionDecl *OperatorDelete = 0;
6209 if (E->getOperatorDelete()) {
6210 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006211 getDerived().TransformDecl(E->getLocStart(),
6212 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006213 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006214 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006215 }
Sean Huntc3021132010-05-05 15:23:54 +00006216
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006218 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006220 Constructor == E->getConstructor() &&
6221 OperatorNew == E->getOperatorNew() &&
6222 OperatorDelete == E->getOperatorDelete() &&
6223 !ArgumentChanged) {
6224 // Mark any declarations we need as referenced.
6225 // FIXME: instantiation-specific.
6226 if (Constructor)
6227 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6228 if (OperatorNew)
6229 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6230 if (OperatorDelete)
6231 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006232 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006233 }
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006235 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006236 if (!ArraySize.get()) {
6237 // If no array size was specified, but the new expression was
6238 // instantiated with an array type (e.g., "new T" where T is
6239 // instantiated with "int[4]"), extract the outer bound from the
6240 // array type as our array size. We do this with constant and
6241 // dependently-sized array types.
6242 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6243 if (!ArrayT) {
6244 // Do nothing
6245 } else if (const ConstantArrayType *ConsArrayT
6246 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006247 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006248 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6249 ConsArrayT->getSize(),
6250 SemaRef.Context.getSizeType(),
6251 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006252 AllocType = ConsArrayT->getElementType();
6253 } else if (const DependentSizedArrayType *DepArrayT
6254 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6255 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006256 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006257 AllocType = DepArrayT->getElementType();
6258 }
6259 }
6260 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006261
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6263 E->isGlobalNew(),
6264 /*FIXME:*/E->getLocStart(),
6265 move_arg(PlacementArgs),
6266 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006267 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006268 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006269 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006270 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271 /*FIXME:*/E->getLocStart(),
6272 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006273 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006274}
Mike Stump1eb44332009-09-09 15:08:12 +00006275
Douglas Gregorb98b1992009-08-11 05:31:07 +00006276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006277ExprResult
John McCall454feb92009-12-08 09:21:05 +00006278TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006279 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006280 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006281 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006282
Douglas Gregor1af74512010-02-26 00:38:10 +00006283 // Transform the delete operator, if known.
6284 FunctionDecl *OperatorDelete = 0;
6285 if (E->getOperatorDelete()) {
6286 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006287 getDerived().TransformDecl(E->getLocStart(),
6288 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006289 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006290 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006291 }
Sean Huntc3021132010-05-05 15:23:54 +00006292
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006294 Operand.get() == E->getArgument() &&
6295 OperatorDelete == E->getOperatorDelete()) {
6296 // Mark any declarations we need as referenced.
6297 // FIXME: instantiation-specific.
6298 if (OperatorDelete)
6299 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006300
6301 if (!E->getArgument()->isTypeDependent()) {
6302 QualType Destroyed = SemaRef.Context.getBaseElementType(
6303 E->getDestroyedType());
6304 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6305 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6306 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6307 SemaRef.LookupDestructor(Record));
6308 }
6309 }
6310
John McCall3fa5cae2010-10-26 07:05:15 +00006311 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006312 }
Mike Stump1eb44332009-09-09 15:08:12 +00006313
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6315 E->isGlobalDelete(),
6316 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006317 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006318}
Mike Stump1eb44332009-09-09 15:08:12 +00006319
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006321ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006322TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006323 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006324 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006325 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006327
John McCallb3d87482010-08-24 05:47:05 +00006328 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006329 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006330 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006331 E->getOperatorLoc(),
6332 E->isArrow()? tok::arrow : tok::period,
6333 ObjectTypePtr,
6334 MayBePseudoDestructor);
6335 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006336 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006337
John McCallb3d87482010-08-24 05:47:05 +00006338 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006339 NestedNameSpecifier *Qualifier = E->getQualifier();
6340 if (Qualifier) {
6341 Qualifier
6342 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6343 E->getQualifierRange(),
6344 ObjectType);
6345 if (!Qualifier)
6346 return ExprError();
6347 }
Mike Stump1eb44332009-09-09 15:08:12 +00006348
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006349 PseudoDestructorTypeStorage Destroyed;
6350 if (E->getDestroyedTypeInfo()) {
6351 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006352 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6353 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006354 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006355 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006356 Destroyed = DestroyedTypeInfo;
6357 } else if (ObjectType->isDependentType()) {
6358 // We aren't likely to be able to resolve the identifier down to a type
6359 // now anyway, so just retain the identifier.
6360 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6361 E->getDestroyedTypeLoc());
6362 } else {
6363 // Look for a destructor known with the given name.
6364 CXXScopeSpec SS;
6365 if (Qualifier) {
6366 SS.setScopeRep(Qualifier);
6367 SS.setRange(E->getQualifierRange());
6368 }
Sean Huntc3021132010-05-05 15:23:54 +00006369
John McCallb3d87482010-08-24 05:47:05 +00006370 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006371 *E->getDestroyedTypeIdentifier(),
6372 E->getDestroyedTypeLoc(),
6373 /*Scope=*/0,
6374 SS, ObjectTypePtr,
6375 false);
6376 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006377 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006378
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006379 Destroyed
6380 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6381 E->getDestroyedTypeLoc());
6382 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006383
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006384 TypeSourceInfo *ScopeTypeInfo = 0;
6385 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006386 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006387 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006388 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006389 }
Sean Huntc3021132010-05-05 15:23:54 +00006390
John McCall9ae2f072010-08-23 23:25:46 +00006391 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006392 E->getOperatorLoc(),
6393 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006394 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006395 E->getQualifierRange(),
6396 ScopeTypeInfo,
6397 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006398 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006399 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006400}
Mike Stump1eb44332009-09-09 15:08:12 +00006401
Douglas Gregora71d8192009-09-04 17:36:40 +00006402template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006403ExprResult
John McCallba135432009-11-21 08:51:07 +00006404TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006405 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006406 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6407
6408 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6409 Sema::LookupOrdinaryName);
6410
6411 // Transform all the decls.
6412 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6413 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006414 NamedDecl *InstD = static_cast<NamedDecl*>(
6415 getDerived().TransformDecl(Old->getNameLoc(),
6416 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006417 if (!InstD) {
6418 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6419 // This can happen because of dependent hiding.
6420 if (isa<UsingShadowDecl>(*I))
6421 continue;
6422 else
John McCallf312b1e2010-08-26 23:41:50 +00006423 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006424 }
John McCallf7a1a742009-11-24 19:00:30 +00006425
6426 // Expand using declarations.
6427 if (isa<UsingDecl>(InstD)) {
6428 UsingDecl *UD = cast<UsingDecl>(InstD);
6429 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6430 E = UD->shadow_end(); I != E; ++I)
6431 R.addDecl(*I);
6432 continue;
6433 }
6434
6435 R.addDecl(InstD);
6436 }
6437
6438 // Resolve a kind, but don't do any further analysis. If it's
6439 // ambiguous, the callee needs to deal with it.
6440 R.resolveKind();
6441
6442 // Rebuild the nested-name qualifier, if present.
6443 CXXScopeSpec SS;
6444 NestedNameSpecifier *Qualifier = 0;
6445 if (Old->getQualifier()) {
6446 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006447 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006448 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006450
John McCallf7a1a742009-11-24 19:00:30 +00006451 SS.setScopeRep(Qualifier);
6452 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006453 }
6454
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006455 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006456 CXXRecordDecl *NamingClass
6457 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6458 Old->getNameLoc(),
6459 Old->getNamingClass()));
6460 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006461 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006462
Douglas Gregor66c45152010-04-27 16:10:10 +00006463 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006464 }
6465
6466 // If we have no template arguments, it's a normal declaration name.
6467 if (!Old->hasExplicitTemplateArgs())
6468 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6469
6470 // If we have template arguments, rebuild them, then rebuild the
6471 // templateid expression.
6472 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006473 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6474 Old->getNumTemplateArgs(),
6475 TransArgs))
6476 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006477
6478 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6479 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480}
Mike Stump1eb44332009-09-09 15:08:12 +00006481
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006483ExprResult
John McCall454feb92009-12-08 09:21:05 +00006484TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006485 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6486 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006490 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Mike Stump1eb44332009-09-09 15:08:12 +00006493 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 T,
6496 E->getLocEnd());
6497}
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006500ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006501TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6502 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6503 if (!LhsT)
6504 return ExprError();
6505
6506 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6507 if (!RhsT)
6508 return ExprError();
6509
6510 if (!getDerived().AlwaysRebuild() &&
6511 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6512 return SemaRef.Owned(E);
6513
6514 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6515 E->getLocStart(),
6516 LhsT, RhsT,
6517 E->getLocEnd());
6518}
6519
6520template<typename Derived>
6521ExprResult
John McCall865d4472009-11-19 22:55:06 +00006522TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006523 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006525 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006526 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006529
John McCall43fed0d2010-11-12 08:19:04 +00006530 // TODO: If this is a conversion-function-id, verify that the
6531 // destination type name (if present) resolves the same way after
6532 // instantiation as it did in the local scope.
6533
Abramo Bagnara25777432010-08-11 22:01:17 +00006534 DeclarationNameInfo NameInfo
6535 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6536 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006537 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006538
John McCallf7a1a742009-11-24 19:00:30 +00006539 if (!E->hasExplicitTemplateArgs()) {
6540 if (!getDerived().AlwaysRebuild() &&
6541 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006542 // Note: it is sufficient to compare the Name component of NameInfo:
6543 // if name has not changed, DNLoc has not changed either.
6544 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006545 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006546
John McCallf7a1a742009-11-24 19:00:30 +00006547 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6548 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006549 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006550 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006551 }
John McCalld5532b62009-11-23 01:53:49 +00006552
6553 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006554 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6555 E->getNumTemplateArgs(),
6556 TransArgs))
6557 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558
John McCallf7a1a742009-11-24 19:00:30 +00006559 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6560 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006561 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006562 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563}
6564
6565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006566ExprResult
John McCall454feb92009-12-08 09:21:05 +00006567TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006568 // CXXConstructExprs are always implicit, so when we have a
6569 // 1-argument construction we just transform that argument.
6570 if (E->getNumArgs() == 1 ||
6571 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6572 return getDerived().TransformExpr(E->getArg(0));
6573
Douglas Gregorb98b1992009-08-11 05:31:07 +00006574 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6575
6576 QualType T = getDerived().TransformType(E->getType());
6577 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006578 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579
6580 CXXConstructorDecl *Constructor
6581 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006582 getDerived().TransformDecl(E->getLocStart(),
6583 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006585 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregorb98b1992009-08-11 05:31:07 +00006587 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006588 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006589 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6590 &ArgumentChanged))
6591 return ExprError();
6592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 if (!getDerived().AlwaysRebuild() &&
6594 T == E->getType() &&
6595 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006596 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006597 // Mark the constructor as referenced.
6598 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006599 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006600 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006601 }
Mike Stump1eb44332009-09-09 15:08:12 +00006602
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006603 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6604 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006605 move_arg(Args),
6606 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006607 E->getConstructionKind(),
6608 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609}
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611/// \brief Transform a C++ temporary-binding expression.
6612///
Douglas Gregor51326552009-12-24 18:51:59 +00006613/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6614/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006616ExprResult
John McCall454feb92009-12-08 09:21:05 +00006617TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006618 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619}
Mike Stump1eb44332009-09-09 15:08:12 +00006620
John McCall4765fa02010-12-06 08:20:24 +00006621/// \brief Transform a C++ expression that contains cleanups that should
6622/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623///
John McCall4765fa02010-12-06 08:20:24 +00006624/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006625/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006627ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006628TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006629 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630}
Mike Stump1eb44332009-09-09 15:08:12 +00006631
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006633ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006635 CXXTemporaryObjectExpr *E) {
6636 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6637 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 CXXConstructorDecl *Constructor
6641 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006642 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006643 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006645 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006648 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006650 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6651 &ArgumentChanged))
6652 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006653
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006655 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006657 !ArgumentChanged) {
6658 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006659 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006660 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006661 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006662
6663 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6664 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 E->getLocEnd());
6667}
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006670ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006672 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006673 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6674 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006676
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006678 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006679 Args.reserve(E->arg_size());
6680 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6681 &ArgumentChanged))
6682 return ExprError();
6683
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006685 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006686 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006690 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 E->getLParenLoc(),
6692 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 E->getRParenLoc());
6694}
Mike Stump1eb44332009-09-09 15:08:12 +00006695
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006697ExprResult
John McCall865d4472009-11-19 22:55:06 +00006698TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006699 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006700 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006701 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006702 Expr *OldBase;
6703 QualType BaseType;
6704 QualType ObjectType;
6705 if (!E->isImplicitAccess()) {
6706 OldBase = E->getBase();
6707 Base = getDerived().TransformExpr(OldBase);
6708 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006710
John McCallaa81e162009-12-01 22:10:20 +00006711 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006712 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006713 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006714 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006715 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006716 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006717 ObjectTy,
6718 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006719 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006720 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006721
John McCallb3d87482010-08-24 05:47:05 +00006722 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006723 BaseType = ((Expr*) Base.get())->getType();
6724 } else {
6725 OldBase = 0;
6726 BaseType = getDerived().TransformType(E->getBaseType());
6727 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6728 }
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregor6cd21982009-10-20 05:58:46 +00006730 // Transform the first part of the nested-name-specifier that qualifies
6731 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006732 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006733 = getDerived().TransformFirstQualifierInScope(
6734 E->getFirstQualifierFoundInScope(),
6735 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregora38c6872009-09-03 16:14:30 +00006737 NestedNameSpecifier *Qualifier = 0;
6738 if (E->getQualifier()) {
6739 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6740 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006741 ObjectType,
6742 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006743 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006744 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006745 }
Mike Stump1eb44332009-09-09 15:08:12 +00006746
John McCall43fed0d2010-11-12 08:19:04 +00006747 // TODO: If this is a conversion-function-id, verify that the
6748 // destination type name (if present) resolves the same way after
6749 // instantiation as it did in the local scope.
6750
Abramo Bagnara25777432010-08-11 22:01:17 +00006751 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006752 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006753 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006754 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006755
John McCallaa81e162009-12-01 22:10:20 +00006756 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006757 // This is a reference to a member without an explicitly-specified
6758 // template argument list. Optimize for this common case.
6759 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006760 Base.get() == OldBase &&
6761 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006762 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006763 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006764 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006765 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006766
John McCall9ae2f072010-08-23 23:25:46 +00006767 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006768 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006769 E->isArrow(),
6770 E->getOperatorLoc(),
6771 Qualifier,
6772 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006773 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006774 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006775 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006776 }
6777
John McCalld5532b62009-11-23 01:53:49 +00006778 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006779 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6780 E->getNumTemplateArgs(),
6781 TransArgs))
6782 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006783
John McCall9ae2f072010-08-23 23:25:46 +00006784 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006785 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786 E->isArrow(),
6787 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006788 Qualifier,
6789 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006790 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006791 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006792 &TransArgs);
6793}
6794
6795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006796ExprResult
John McCall454feb92009-12-08 09:21:05 +00006797TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006798 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006799 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006800 QualType BaseType;
6801 if (!Old->isImplicitAccess()) {
6802 Base = getDerived().TransformExpr(Old->getBase());
6803 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006805 BaseType = ((Expr*) Base.get())->getType();
6806 } else {
6807 BaseType = getDerived().TransformType(Old->getBaseType());
6808 }
John McCall129e2df2009-11-30 22:42:35 +00006809
6810 NestedNameSpecifier *Qualifier = 0;
6811 if (Old->getQualifier()) {
6812 Qualifier
6813 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006814 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006815 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006816 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006817 }
6818
Abramo Bagnara25777432010-08-11 22:01:17 +00006819 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006820 Sema::LookupOrdinaryName);
6821
6822 // Transform all the decls.
6823 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6824 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006825 NamedDecl *InstD = static_cast<NamedDecl*>(
6826 getDerived().TransformDecl(Old->getMemberLoc(),
6827 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006828 if (!InstD) {
6829 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6830 // This can happen because of dependent hiding.
6831 if (isa<UsingShadowDecl>(*I))
6832 continue;
6833 else
John McCallf312b1e2010-08-26 23:41:50 +00006834 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006835 }
John McCall129e2df2009-11-30 22:42:35 +00006836
6837 // Expand using declarations.
6838 if (isa<UsingDecl>(InstD)) {
6839 UsingDecl *UD = cast<UsingDecl>(InstD);
6840 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6841 E = UD->shadow_end(); I != E; ++I)
6842 R.addDecl(*I);
6843 continue;
6844 }
6845
6846 R.addDecl(InstD);
6847 }
6848
6849 R.resolveKind();
6850
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006851 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006852 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006853 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006854 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006855 Old->getMemberLoc(),
6856 Old->getNamingClass()));
6857 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006858 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006859
Douglas Gregor66c45152010-04-27 16:10:10 +00006860 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006861 }
Sean Huntc3021132010-05-05 15:23:54 +00006862
John McCall129e2df2009-11-30 22:42:35 +00006863 TemplateArgumentListInfo TransArgs;
6864 if (Old->hasExplicitTemplateArgs()) {
6865 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6866 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006867 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6868 Old->getNumTemplateArgs(),
6869 TransArgs))
6870 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006871 }
John McCallc2233c52010-01-15 08:34:02 +00006872
6873 // FIXME: to do this check properly, we will need to preserve the
6874 // first-qualifier-in-scope here, just in case we had a dependent
6875 // base (and therefore couldn't do the check) and a
6876 // nested-name-qualifier (and therefore could do the lookup).
6877 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006878
John McCall9ae2f072010-08-23 23:25:46 +00006879 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006880 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006881 Old->getOperatorLoc(),
6882 Old->isArrow(),
6883 Qualifier,
6884 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006885 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006886 R,
6887 (Old->hasExplicitTemplateArgs()
6888 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889}
6890
6891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006892ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006893TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6894 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6895 if (SubExpr.isInvalid())
6896 return ExprError();
6897
6898 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006899 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006900
6901 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6902}
6903
6904template<typename Derived>
6905ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006906TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00006907 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6908 if (Pattern.isInvalid())
6909 return ExprError();
6910
6911 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6912 return SemaRef.Owned(E);
6913
Douglas Gregor67fd1252011-01-14 21:20:45 +00006914 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6915 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00006916}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006917
6918template<typename Derived>
6919ExprResult
6920TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6921 // If E is not value-dependent, then nothing will change when we transform it.
6922 // Note: This is an instantiation-centric view.
6923 if (!E->isValueDependent())
6924 return SemaRef.Owned(E);
6925
6926 // Note: None of the implementations of TryExpandParameterPacks can ever
6927 // produce a diagnostic when given only a single unexpanded parameter pack,
6928 // so
6929 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6930 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00006931 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00006932 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00006933 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6934 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00006935 ShouldExpand, RetainExpansion,
6936 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00006937 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006938
Douglas Gregord3731192011-01-10 07:32:04 +00006939 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00006940 return SemaRef.Owned(E);
6941
6942 // We now know the length of the parameter pack, so build a new expression
6943 // that stores that length.
6944 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6945 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00006946 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00006947}
6948
Douglas Gregorbe230c32011-01-03 17:17:50 +00006949template<typename Derived>
6950ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00006951TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6952 SubstNonTypeTemplateParmPackExpr *E) {
6953 // Default behavior is to do nothing with this transformation.
6954 return SemaRef.Owned(E);
6955}
6956
6957template<typename Derived>
6958ExprResult
John McCall454feb92009-12-08 09:21:05 +00006959TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961}
6962
Mike Stump1eb44332009-09-09 15:08:12 +00006963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006964ExprResult
John McCall454feb92009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006966 TypeSourceInfo *EncodedTypeInfo
6967 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6968 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006969 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006970
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006972 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006973 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974
6975 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006976 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 E->getRParenLoc());
6978}
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006983 // Transform arguments.
6984 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006985 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006986 Args.reserve(E->getNumArgs());
6987 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6988 &ArgChanged))
6989 return ExprError();
6990
Douglas Gregor92e986e2010-04-22 16:44:27 +00006991 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6992 // Class message: transform the receiver type.
6993 TypeSourceInfo *ReceiverTypeInfo
6994 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6995 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006996 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006997
Douglas Gregor92e986e2010-04-22 16:44:27 +00006998 // If nothing changed, just retain the existing message send.
6999 if (!getDerived().AlwaysRebuild() &&
7000 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007001 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007002
7003 // Build a new class message send.
7004 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7005 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007006 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007007 E->getMethodDecl(),
7008 E->getLeftLoc(),
7009 move_arg(Args),
7010 E->getRightLoc());
7011 }
7012
7013 // Instance message: transform the receiver
7014 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7015 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007016 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007017 = getDerived().TransformExpr(E->getInstanceReceiver());
7018 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007019 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007020
7021 // If nothing changed, just retain the existing message send.
7022 if (!getDerived().AlwaysRebuild() &&
7023 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007024 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007025
Douglas Gregor92e986e2010-04-22 16:44:27 +00007026 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007027 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007028 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007029 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007030 E->getMethodDecl(),
7031 E->getLeftLoc(),
7032 move_arg(Args),
7033 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034}
7035
Mike Stump1eb44332009-09-09 15:08:12 +00007036template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007037ExprResult
John McCall454feb92009-12-08 09:21:05 +00007038TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007039 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040}
7041
Mike Stump1eb44332009-09-09 15:08:12 +00007042template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007043ExprResult
John McCall454feb92009-12-08 09:21:05 +00007044TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007045 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007046}
7047
Mike Stump1eb44332009-09-09 15:08:12 +00007048template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007049ExprResult
John McCall454feb92009-12-08 09:21:05 +00007050TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007051 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007052 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007053 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007054 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007055
7056 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007057
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007058 // If nothing changed, just retain the existing expression.
7059 if (!getDerived().AlwaysRebuild() &&
7060 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007061 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007062
John McCall9ae2f072010-08-23 23:25:46 +00007063 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007064 E->getLocation(),
7065 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066}
7067
Mike Stump1eb44332009-09-09 15:08:12 +00007068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007069ExprResult
John McCall454feb92009-12-08 09:21:05 +00007070TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007071 // 'super' and types never change. Property never changes. Just
7072 // retain the existing expression.
7073 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007074 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007075
Douglas Gregore3303542010-04-26 20:47:02 +00007076 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007077 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007078 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007079 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007080
Douglas Gregore3303542010-04-26 20:47:02 +00007081 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007082
Douglas Gregore3303542010-04-26 20:47:02 +00007083 // If nothing changed, just retain the existing expression.
7084 if (!getDerived().AlwaysRebuild() &&
7085 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007086 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087
John McCall12f78a62010-12-02 01:19:52 +00007088 if (E->isExplicitProperty())
7089 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7090 E->getExplicitProperty(),
7091 E->getLocation());
7092
7093 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7094 E->getType(),
7095 E->getImplicitPropertyGetter(),
7096 E->getImplicitPropertySetter(),
7097 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098}
7099
Mike Stump1eb44332009-09-09 15:08:12 +00007100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007101ExprResult
John McCall454feb92009-12-08 09:21:05 +00007102TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007103 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007104 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007105 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007106 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007107
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007108 // If nothing changed, just retain the existing expression.
7109 if (!getDerived().AlwaysRebuild() &&
7110 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007111 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007112
John McCall9ae2f072010-08-23 23:25:46 +00007113 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007114 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007115}
7116
Mike Stump1eb44332009-09-09 15:08:12 +00007117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007118ExprResult
John McCall454feb92009-12-08 09:21:05 +00007119TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007121 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007122 SubExprs.reserve(E->getNumSubExprs());
7123 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7124 SubExprs, &ArgumentChanged))
7125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127 if (!getDerived().AlwaysRebuild() &&
7128 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007130
Douglas Gregorb98b1992009-08-11 05:31:07 +00007131 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7132 move_arg(SubExprs),
7133 E->getRParenLoc());
7134}
7135
Mike Stump1eb44332009-09-09 15:08:12 +00007136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007137ExprResult
John McCall454feb92009-12-08 09:21:05 +00007138TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007139 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007140
John McCallc6ac9c32011-02-04 18:33:18 +00007141 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7142 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7143
7144 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7145 llvm::SmallVector<ParmVarDecl*, 4> params;
7146 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007147
7148 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007149 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7150 oldBlock->param_begin(),
7151 oldBlock->param_size(),
7152 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007153 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007154
7155 const FunctionType *exprFunctionType = E->getFunctionType();
7156 QualType exprResultType = exprFunctionType->getResultType();
7157 if (!exprResultType.isNull()) {
7158 if (!exprResultType->isDependentType())
7159 blockScope->ReturnType = exprResultType;
7160 else if (exprResultType != getSema().Context.DependentTy)
7161 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007162 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007163
7164 // If the return type has not been determined yet, leave it as a dependent
7165 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007166 if (blockScope->ReturnType.isNull())
7167 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007168
7169 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007170 if (blockScope->ReturnType->isObjCObjectType()) {
7171 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007172 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007173 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007174 return ExprError();
7175 }
John McCall711c52b2011-01-05 12:14:39 +00007176
John McCallc6ac9c32011-02-04 18:33:18 +00007177 QualType functionType = getDerived().RebuildFunctionProtoType(
7178 blockScope->ReturnType,
7179 paramTypes.data(),
7180 paramTypes.size(),
7181 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007182 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007183 exprFunctionType->getExtInfo());
7184 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007185
7186 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007187 if (!params.empty())
7188 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007189
7190 // If the return type wasn't explicitly set, it will have been marked as a
7191 // dependent type (DependentTy); clear out the return type setting so
7192 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007193 if (blockScope->ReturnType == getSema().Context.DependentTy)
7194 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007195
John McCall711c52b2011-01-05 12:14:39 +00007196 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007197 StmtResult body = getDerived().TransformStmt(E->getBody());
7198 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007199 return ExprError();
7200
John McCallc6ac9c32011-02-04 18:33:18 +00007201#ifndef NDEBUG
7202 // In builds with assertions, make sure that we captured everything we
7203 // captured before.
7204
7205 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7206
7207 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7208 e = oldBlock->capture_end(); i != e; ++i) {
7209 VarDecl *oldCapture = *i;
7210
7211 // Ignore parameter packs.
7212 if (isa<ParmVarDecl>(oldCapture) &&
7213 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7214 continue;
7215
7216 VarDecl *newCapture =
7217 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7218 oldCapture));
7219 assert(blockScope->Captures.count(newCapture));
7220 }
7221#endif
7222
7223 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7224 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007225}
7226
Mike Stump1eb44332009-09-09 15:08:12 +00007227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007228ExprResult
John McCall454feb92009-12-08 09:21:05 +00007229TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007230 NestedNameSpecifier *Qualifier = 0;
7231
7232 ValueDecl *ND
7233 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7234 E->getDecl()));
7235 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007236 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007237
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007238 if (!getDerived().AlwaysRebuild() &&
7239 ND == E->getDecl()) {
7240 // Mark it referenced in the new context regardless.
7241 // FIXME: this is a bit instantiation-specific.
7242 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7243
John McCall3fa5cae2010-10-26 07:05:15 +00007244 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007245 }
7246
Abramo Bagnara25777432010-08-11 22:01:17 +00007247 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007248 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007249 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007250}
Mike Stump1eb44332009-09-09 15:08:12 +00007251
Douglas Gregorb98b1992009-08-11 05:31:07 +00007252//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007253// Type reconstruction
7254//===----------------------------------------------------------------------===//
7255
Mike Stump1eb44332009-09-09 15:08:12 +00007256template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007257QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7258 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007259 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007260 getDerived().getBaseEntity());
7261}
7262
Mike Stump1eb44332009-09-09 15:08:12 +00007263template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007264QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7265 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007266 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007267 getDerived().getBaseEntity());
7268}
7269
Mike Stump1eb44332009-09-09 15:08:12 +00007270template<typename Derived>
7271QualType
John McCall85737a72009-10-30 00:06:24 +00007272TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7273 bool WrittenAsLValue,
7274 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007275 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007276 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007277}
7278
7279template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007280QualType
John McCall85737a72009-10-30 00:06:24 +00007281TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7282 QualType ClassType,
7283 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007284 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007285 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007286}
7287
7288template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007289QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007290TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7291 ArrayType::ArraySizeModifier SizeMod,
7292 const llvm::APInt *Size,
7293 Expr *SizeExpr,
7294 unsigned IndexTypeQuals,
7295 SourceRange BracketsRange) {
7296 if (SizeExpr || !Size)
7297 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7298 IndexTypeQuals, BracketsRange,
7299 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007300
7301 QualType Types[] = {
7302 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7303 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7304 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007305 };
7306 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7307 QualType SizeType;
7308 for (unsigned I = 0; I != NumTypes; ++I)
7309 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7310 SizeType = Types[I];
7311 break;
7312 }
Mike Stump1eb44332009-09-09 15:08:12 +00007313
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007314 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7315 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007316 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007317 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007318 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007319}
Mike Stump1eb44332009-09-09 15:08:12 +00007320
Douglas Gregor577f75a2009-08-04 16:50:30 +00007321template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007322QualType
7323TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007324 ArrayType::ArraySizeModifier SizeMod,
7325 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007326 unsigned IndexTypeQuals,
7327 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007328 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007329 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007330}
7331
7332template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007333QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007334TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007335 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007336 unsigned IndexTypeQuals,
7337 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007338 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007339 IndexTypeQuals, BracketsRange);
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>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007345 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007346 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007347 unsigned IndexTypeQuals,
7348 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007349 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007350 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007351 IndexTypeQuals, BracketsRange);
7352}
7353
7354template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007355QualType
7356TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007357 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007358 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007359 unsigned IndexTypeQuals,
7360 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007361 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007362 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007363 IndexTypeQuals, BracketsRange);
7364}
7365
7366template<typename Derived>
7367QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007368 unsigned NumElements,
7369 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007370 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007371 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007372}
Mike Stump1eb44332009-09-09 15:08:12 +00007373
Douglas Gregor577f75a2009-08-04 16:50:30 +00007374template<typename Derived>
7375QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7376 unsigned NumElements,
7377 SourceLocation AttributeLoc) {
7378 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7379 NumElements, true);
7380 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007381 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7382 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007383 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007384}
Mike Stump1eb44332009-09-09 15:08:12 +00007385
Douglas Gregor577f75a2009-08-04 16:50:30 +00007386template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007387QualType
7388TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007389 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007390 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007391 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007392}
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Douglas Gregor577f75a2009-08-04 16:50:30 +00007394template<typename Derived>
7395QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007396 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007397 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007398 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007399 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007400 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007401 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007402 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007403 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007404 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007405 getDerived().getBaseEntity(),
7406 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007407}
Mike Stump1eb44332009-09-09 15:08:12 +00007408
Douglas Gregor577f75a2009-08-04 16:50:30 +00007409template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007410QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7411 return SemaRef.Context.getFunctionNoProtoType(T);
7412}
7413
7414template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007415QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7416 assert(D && "no decl found");
7417 if (D->isInvalidDecl()) return QualType();
7418
Douglas Gregor92e986e2010-04-22 16:44:27 +00007419 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007420 TypeDecl *Ty;
7421 if (isa<UsingDecl>(D)) {
7422 UsingDecl *Using = cast<UsingDecl>(D);
7423 assert(Using->isTypeName() &&
7424 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7425
7426 // A valid resolved using typename decl points to exactly one type decl.
7427 assert(++Using->shadow_begin() == Using->shadow_end());
7428 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007429
John McCalled976492009-12-04 22:46:56 +00007430 } else {
7431 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7432 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7433 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7434 }
7435
7436 return SemaRef.Context.getTypeDeclType(Ty);
7437}
7438
7439template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007440QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7441 SourceLocation Loc) {
7442 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007443}
7444
7445template<typename Derived>
7446QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7447 return SemaRef.Context.getTypeOfType(Underlying);
7448}
7449
7450template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007451QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7452 SourceLocation Loc) {
7453 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007454}
7455
7456template<typename Derived>
7457QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007458 TemplateName Template,
7459 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007460 const TemplateArgumentListInfo &TemplateArgs) {
7461 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007462}
Mike Stump1eb44332009-09-09 15:08:12 +00007463
Douglas Gregordcee1a12009-08-06 05:28:30 +00007464template<typename Derived>
7465NestedNameSpecifier *
7466TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7467 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007468 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007469 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007470 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007471 CXXScopeSpec SS;
7472 // FIXME: The source location information is all wrong.
7473 SS.setRange(Range);
7474 SS.setScopeRep(Prefix);
7475 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007476 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007477 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007478 ObjectType,
7479 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007480 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007481}
7482
7483template<typename Derived>
7484NestedNameSpecifier *
7485TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7486 SourceRange Range,
7487 NamespaceDecl *NS) {
7488 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7489}
7490
7491template<typename Derived>
7492NestedNameSpecifier *
7493TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7494 SourceRange Range,
7495 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007496 QualType T) {
7497 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007498 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007499 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007500 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7501 T.getTypePtr());
7502 }
Mike Stump1eb44332009-09-09 15:08:12 +00007503
Douglas Gregordcee1a12009-08-06 05:28:30 +00007504 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7505 return 0;
7506}
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregord1067e52009-08-06 06:41:21 +00007508template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007509TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007510TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7511 bool TemplateKW,
7512 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007513 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007514 Template);
7515}
7516
7517template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007518TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007519TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007520 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007521 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007522 QualType ObjectType,
7523 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007524 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007525 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007526 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007527 UnqualifiedId Name;
7528 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007529 Sema::TemplateTy Template;
7530 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7531 /*FIXME:*/getDerived().getBaseLocation(),
7532 SS,
7533 Name,
John McCallb3d87482010-08-24 05:47:05 +00007534 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007535 /*EnteringContext=*/false,
7536 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007537 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007538}
Mike Stump1eb44332009-09-09 15:08:12 +00007539
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007541TemplateName
7542TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7543 OverloadedOperatorKind Operator,
7544 QualType ObjectType) {
7545 CXXScopeSpec SS;
7546 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7547 SS.setScopeRep(Qualifier);
7548 UnqualifiedId Name;
7549 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7550 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7551 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007552 Sema::TemplateTy Template;
7553 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007554 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007555 SS,
7556 Name,
John McCallb3d87482010-08-24 05:47:05 +00007557 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007558 /*EnteringContext=*/false,
7559 Template);
7560 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007561}
Sean Huntc3021132010-05-05 15:23:54 +00007562
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007564ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007565TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7566 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007567 Expr *OrigCallee,
7568 Expr *First,
7569 Expr *Second) {
7570 Expr *Callee = OrigCallee->IgnoreParenCasts();
7571 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007572
Douglas Gregorb98b1992009-08-11 05:31:07 +00007573 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007574 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007575 if (!First->getType()->isOverloadableType() &&
7576 !Second->getType()->isOverloadableType())
7577 return getSema().CreateBuiltinArraySubscriptExpr(First,
7578 Callee->getLocStart(),
7579 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007580 } else if (Op == OO_Arrow) {
7581 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007582 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7583 } else if (Second == 0 || isPostIncDec) {
7584 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007585 // The argument is not of overloadable type, so try to create a
7586 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007587 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007588 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007589
John McCall9ae2f072010-08-23 23:25:46 +00007590 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007591 }
7592 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007593 if (!First->getType()->isOverloadableType() &&
7594 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007595 // Neither of the arguments is an overloadable type, so try to
7596 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007597 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007598 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007599 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007601 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007602
Douglas Gregorb98b1992009-08-11 05:31:07 +00007603 return move(Result);
7604 }
7605 }
Mike Stump1eb44332009-09-09 15:08:12 +00007606
7607 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007608 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007609 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007610
John McCall9ae2f072010-08-23 23:25:46 +00007611 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007612 assert(ULE->requiresADL());
7613
7614 // FIXME: Do we have to check
7615 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007616 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007617 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007618 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007619 }
Mike Stump1eb44332009-09-09 15:08:12 +00007620
Douglas Gregorb98b1992009-08-11 05:31:07 +00007621 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007622 Expr *Args[2] = { First, Second };
7623 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007624
Douglas Gregorb98b1992009-08-11 05:31:07 +00007625 // Create the overloaded operator invocation for unary operators.
7626 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007627 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007628 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007629 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007630 }
Mike Stump1eb44332009-09-09 15:08:12 +00007631
Sebastian Redlf322ed62009-10-29 20:17:01 +00007632 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007633 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007634 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007635 First,
7636 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007637
Douglas Gregorb98b1992009-08-11 05:31:07 +00007638 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007639 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007640 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007641 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7642 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007643 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007644
Mike Stump1eb44332009-09-09 15:08:12 +00007645 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007646}
Mike Stump1eb44332009-09-09 15:08:12 +00007647
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007649ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007650TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007651 SourceLocation OperatorLoc,
7652 bool isArrow,
7653 NestedNameSpecifier *Qualifier,
7654 SourceRange QualifierRange,
7655 TypeSourceInfo *ScopeType,
7656 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007657 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007658 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007659 CXXScopeSpec SS;
7660 if (Qualifier) {
7661 SS.setRange(QualifierRange);
7662 SS.setScopeRep(Qualifier);
7663 }
7664
John McCall9ae2f072010-08-23 23:25:46 +00007665 QualType BaseType = Base->getType();
7666 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007667 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007668 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007669 !BaseType->getAs<PointerType>()->getPointeeType()
7670 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007671 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007672 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007673 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007674 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007675 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007676 /*FIXME?*/true);
7677 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007678
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007679 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007680 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7681 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7682 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7683 NameInfo.setNamedTypeInfo(DestroyedType);
7684
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007685 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007686
John McCall9ae2f072010-08-23 23:25:46 +00007687 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007688 OperatorLoc, isArrow,
7689 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007690 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007691 /*TemplateArgs*/ 0);
7692}
7693
Douglas Gregor577f75a2009-08-04 16:50:30 +00007694} // end namespace clang
7695
7696#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H