blob: be4d82c39a68baa8fdc01c89922e8fcae7d714bc [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();
172 Self.getDerived().setBase(Location, Entity);
173 }
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 ~TemporaryBase() {
176 Self.getDerived().setBase(OldLocation, OldEntity);
177 }
178 };
Mike Stump1eb44332009-09-09 15:08:12 +0000179
180 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000181 /// transformed.
182 ///
183 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000184 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// not change. For example, template instantiation need not traverse
186 /// non-dependent types.
187 bool AlreadyTransformed(QualType T) {
188 return T.isNull();
189 }
190
Douglas Gregor6eef5192009-12-14 19:27:10 +0000191 /// \brief Determine whether the given call argument should be dropped, e.g.,
192 /// because it is a default argument.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine to
195 /// determine which kinds of call arguments get dropped. By default,
196 /// CXXDefaultArgument nodes are dropped (prior to transformation).
197 bool DropCallArgument(Expr *E) {
198 return E->isDefaultArgument();
199 }
Sean Huntc3021132010-05-05 15:23:54 +0000200
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000201 /// \brief Determine whether we should expand a pack expansion with the
202 /// given set of parameter packs into separate arguments by repeatedly
203 /// transforming the pattern.
204 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000205 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000206 /// Subclasses can override this routine to provide different behavior.
207 ///
208 /// \param EllipsisLoc The location of the ellipsis that identifies the
209 /// pack expansion.
210 ///
211 /// \param PatternRange The source range that covers the entire pattern of
212 /// the pack expansion.
213 ///
214 /// \param Unexpanded The set of unexpanded parameter packs within the
215 /// pattern.
216 ///
217 /// \param NumUnexpanded The number of unexpanded parameter packs in
218 /// \p Unexpanded.
219 ///
220 /// \param ShouldExpand Will be set to \c true if the transformer should
221 /// expand the corresponding pack expansions into separate arguments. When
222 /// set, \c NumExpansions must also be set.
223 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000224 /// \param RetainExpansion Whether the caller should add an unexpanded
225 /// pack expansion after all of the expanded arguments. This is used
226 /// when extending explicitly-specified template argument packs per
227 /// C++0x [temp.arg.explicit]p9.
228 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000229 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000230 /// the expanded form of the corresponding pack expansion. This is both an
231 /// input and an output parameter, which can be set by the caller if the
232 /// number of expansions is known a priori (e.g., due to a prior substitution)
233 /// and will be set by the callee when the number of expansions is known.
234 /// The callee must set this value when \c ShouldExpand is \c true; it may
235 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000236 ///
237 /// \returns true if an error occurred (e.g., because the parameter packs
238 /// are to be instantiated with arguments of different lengths), false
239 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
240 /// must be set.
241 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
242 SourceRange PatternRange,
243 const UnexpandedParameterPack *Unexpanded,
244 unsigned NumUnexpanded,
245 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000246 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000247 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000248 ShouldExpand = false;
249 return false;
250 }
251
Douglas Gregord3731192011-01-10 07:32:04 +0000252 /// \brief "Forget" about the partially-substituted pack template argument,
253 /// when performing an instantiation that must preserve the parameter pack
254 /// use.
255 ///
256 /// This routine is meant to be overridden by the template instantiator.
257 TemplateArgument ForgetPartiallySubstitutedPack() {
258 return TemplateArgument();
259 }
260
261 /// \brief "Remember" the partially-substituted pack template argument
262 /// after performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
267
Douglas Gregor12c9c002011-01-07 16:43:16 +0000268 /// \brief Note to the derived class when a function parameter pack is
269 /// being expanded.
270 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
271
Douglas Gregor577f75a2009-08-04 16:50:30 +0000272 /// \brief Transforms the given type into another type.
273 ///
John McCalla2becad2009-10-21 00:40:46 +0000274 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000275 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000276 /// function. This is expensive, but we don't mind, because
277 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000278 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 ///
280 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000281 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000282
John McCalla2becad2009-10-21 00:40:46 +0000283 /// \brief Transforms the given type-with-location into a new
284 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000285 ///
John McCalla2becad2009-10-21 00:40:46 +0000286 /// By default, this routine transforms a type by delegating to the
287 /// appropriate TransformXXXType to build a new type. Subclasses
288 /// may override this function (to take over all type
289 /// transformations) or some set of the TransformXXXType functions
290 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000291 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000292
293 /// \brief Transform the given type-with-location into a new
294 /// type, collecting location information in the given builder
295 /// as necessary.
296 ///
John McCall43fed0d2010-11-12 08:19:04 +0000297 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000298
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000299 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000300 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000301 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000302 /// appropriate TransformXXXStmt function to transform a specific kind of
303 /// statement or the TransformExpr() function to transform an expression.
304 /// Subclasses may override this function to transform statements using some
305 /// other mechanism.
306 ///
307 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000308 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000309
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000310 /// \brief Transform the given expression.
311 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000312 /// By default, this routine transforms an expression by delegating to the
313 /// appropriate TransformXXXExpr function to build a new expression.
314 /// Subclasses may override this function to transform expressions using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000318 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000319
Douglas Gregoraa165f82011-01-03 19:04:46 +0000320 /// \brief Transform the given list of expressions.
321 ///
322 /// This routine transforms a list of expressions by invoking
323 /// \c TransformExpr() for each subexpression. However, it also provides
324 /// support for variadic templates by expanding any pack expansions (if the
325 /// derived class permits such expansion) along the way. When pack expansions
326 /// are present, the number of outputs may not equal the number of inputs.
327 ///
328 /// \param Inputs The set of expressions to be transformed.
329 ///
330 /// \param NumInputs The number of expressions in \c Inputs.
331 ///
332 /// \param IsCall If \c true, then this transform is being performed on
333 /// function-call arguments, and any arguments that should be dropped, will
334 /// be.
335 ///
336 /// \param Outputs The transformed input expressions will be added to this
337 /// vector.
338 ///
339 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
340 /// due to transformation.
341 ///
342 /// \returns true if an error occurred, false otherwise.
343 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
344 llvm::SmallVectorImpl<Expr *> &Outputs,
345 bool *ArgChanged = 0);
346
Douglas Gregor577f75a2009-08-04 16:50:30 +0000347 /// \brief Transform the given declaration, which is referenced from a type
348 /// or expression.
349 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000350 /// By default, acts as the identity function on declarations. Subclasses
351 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000352 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000353
354 /// \brief Transform the definition of the given declaration.
355 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000356 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000357 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000358 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
359 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000360 }
Mike Stump1eb44332009-09-09 15:08:12 +0000361
Douglas Gregor6cd21982009-10-20 05:58:46 +0000362 /// \brief Transform the given declaration, which was the first part of a
363 /// nested-name-specifier in a member access expression.
364 ///
Sean Huntc3021132010-05-05 15:23:54 +0000365 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000366 /// identifier in a nested-name-specifier of a member access expression, e.g.,
367 /// the \c T in \c x->T::member
368 ///
369 /// By default, invokes TransformDecl() to transform the declaration.
370 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000371 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
372 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000373 }
Sean Huntc3021132010-05-05 15:23:54 +0000374
Douglas Gregor577f75a2009-08-04 16:50:30 +0000375 /// \brief Transform the given nested-name-specifier.
376 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000377 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000378 /// nested-name-specifier. Subclasses may override this function to provide
379 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000380 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000381 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000382 QualType ObjectType = QualType(),
383 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000384
Douglas Gregor81499bb2009-09-03 22:13:48 +0000385 /// \brief Transform the given declaration name.
386 ///
387 /// By default, transforms the types of conversion function, constructor,
388 /// and destructor names and then (if needed) rebuilds the declaration name.
389 /// Identifiers and selectors are returned unmodified. Sublcasses may
390 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000391 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000392 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000395 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000396 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000397 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000398 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000399 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000400 QualType ObjectType = QualType(),
401 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000402
Douglas Gregor577f75a2009-08-04 16:50:30 +0000403 /// \brief Transform the given template argument.
404 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000405 /// By default, this operation transforms the type, expression, or
406 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000407 /// new template argument from the transformed result. Subclasses may
408 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000409 ///
410 /// Returns true if there was an error.
411 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
412 TemplateArgumentLoc &Output);
413
Douglas Gregorfcc12532010-12-20 17:31:10 +0000414 /// \brief Transform the given set of template arguments.
415 ///
416 /// By default, this operation transforms all of the template arguments
417 /// in the input set using \c TransformTemplateArgument(), and appends
418 /// the transformed arguments to the output list.
419 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000420 /// Note that this overload of \c TransformTemplateArguments() is merely
421 /// a convenience function. Subclasses that wish to override this behavior
422 /// should override the iterator-based member template version.
423 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000424 /// \param Inputs The set of template arguments to be transformed.
425 ///
426 /// \param NumInputs The number of template arguments in \p Inputs.
427 ///
428 /// \param Outputs The set of transformed template arguments output by this
429 /// routine.
430 ///
431 /// Returns true if an error occurred.
432 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
433 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000434 TemplateArgumentListInfo &Outputs) {
435 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
436 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000437
438 /// \brief Transform the given set of template arguments.
439 ///
440 /// By default, this operation transforms all of the template arguments
441 /// in the input set using \c TransformTemplateArgument(), and appends
442 /// the transformed arguments to the output list.
443 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000444 /// \param First An iterator to the first template argument.
445 ///
446 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000447 ///
448 /// \param Outputs The set of transformed template arguments output by this
449 /// routine.
450 ///
451 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000452 template<typename InputIterator>
453 bool TransformTemplateArguments(InputIterator First,
454 InputIterator Last,
455 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000456
John McCall833ca992009-10-29 08:12:44 +0000457 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
458 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
459 TemplateArgumentLoc &ArgLoc);
460
John McCalla93c9342009-12-07 02:54:59 +0000461 /// \brief Fakes up a TypeSourceInfo for a type.
462 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
463 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000464 getDerived().getBaseLocation());
465 }
Mike Stump1eb44332009-09-09 15:08:12 +0000466
John McCalla2becad2009-10-21 00:40:46 +0000467#define ABSTRACT_TYPELOC(CLASS, PARENT)
468#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000469 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000470#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000471
John McCall43fed0d2010-11-12 08:19:04 +0000472 QualType
473 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
474 TemplateSpecializationTypeLoc TL,
475 TemplateName Template);
476
477 QualType
478 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
479 DependentTemplateSpecializationTypeLoc TL,
480 NestedNameSpecifier *Prefix);
481
John McCall21ef0fa2010-03-11 09:03:00 +0000482 /// \brief Transforms the parameters of a function type into the
483 /// given vectors.
484 ///
485 /// The result vectors should be kept in sync; null entries in the
486 /// variables vector are acceptable.
487 ///
488 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000489 bool TransformFunctionTypeParams(SourceLocation Loc,
490 ParmVarDecl **Params, unsigned NumParams,
491 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000492 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000493 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000494
495 /// \brief Transforms a single function-type parameter. Return null
496 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000497 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
498 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000499
John McCall43fed0d2010-11-12 08:19:04 +0000500 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000501
John McCall60d7b3a2010-08-24 06:29:42 +0000502 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
503 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000504
Douglas Gregor43959a92009-08-20 07:17:43 +0000505#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000506 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000507#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000508 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000509#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000510#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 /// \brief Build a new pointer type given its pointee type.
513 ///
514 /// By default, performs semantic analysis when building the pointer type.
515 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000516 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000517
518 /// \brief Build a new block pointer type given its pointee type.
519 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000520 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000522 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000523
John McCall85737a72009-10-30 00:06:24 +0000524 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000525 ///
John McCall85737a72009-10-30 00:06:24 +0000526 /// By default, performs semantic analysis when building the
527 /// reference type. Subclasses may override this routine to provide
528 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529 ///
John McCall85737a72009-10-30 00:06:24 +0000530 /// \param LValue whether the type was written with an lvalue sigil
531 /// or an rvalue sigil.
532 QualType RebuildReferenceType(QualType ReferentType,
533 bool LValue,
534 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000535
Douglas Gregor577f75a2009-08-04 16:50:30 +0000536 /// \brief Build a new member pointer type given the pointee type and the
537 /// class type it refers into.
538 ///
539 /// By default, performs semantic analysis when building the member pointer
540 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000541 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
542 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000543
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544 /// \brief Build a new array type given the element type, size
545 /// modifier, size of the array (if known), size expression, and index type
546 /// qualifiers.
547 ///
548 /// By default, performs semantic analysis when building the array type.
549 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000550 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000551 QualType RebuildArrayType(QualType ElementType,
552 ArrayType::ArraySizeModifier SizeMod,
553 const llvm::APInt *Size,
554 Expr *SizeExpr,
555 unsigned IndexTypeQuals,
556 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000557
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558 /// \brief Build a new constant array type given the element type, size
559 /// modifier, (known) size of the array, and index type qualifiers.
560 ///
561 /// By default, performs semantic analysis when building the array type.
562 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000563 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 ArrayType::ArraySizeModifier SizeMod,
565 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000566 unsigned IndexTypeQuals,
567 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000568
Douglas Gregor577f75a2009-08-04 16:50:30 +0000569 /// \brief Build a new incomplete array type given the element type, size
570 /// modifier, and index type qualifiers.
571 ///
572 /// By default, performs semantic analysis when building the array type.
573 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000574 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000575 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000576 unsigned IndexTypeQuals,
577 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000578
Mike Stump1eb44332009-09-09 15:08:12 +0000579 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000580 /// size modifier, size expression, and index type qualifiers.
581 ///
582 /// By default, performs semantic analysis when building the array type.
583 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000584 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000585 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000586 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587 unsigned IndexTypeQuals,
588 SourceRange BracketsRange);
589
Mike Stump1eb44332009-09-09 15:08:12 +0000590 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000591 /// size modifier, size expression, and index type qualifiers.
592 ///
593 /// By default, performs semantic analysis when building the array type.
594 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000595 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000596 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000597 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598 unsigned IndexTypeQuals,
599 SourceRange BracketsRange);
600
601 /// \brief Build a new vector type given the element type and
602 /// number of elements.
603 ///
604 /// By default, performs semantic analysis when building the vector type.
605 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000606 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000607 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000608
Douglas Gregor577f75a2009-08-04 16:50:30 +0000609 /// \brief Build a new extended vector type given the element type and
610 /// number of elements.
611 ///
612 /// By default, performs semantic analysis when building the vector type.
613 /// Subclasses may override this routine to provide different behavior.
614 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
615 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000616
617 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000618 /// given the element type and number of elements.
619 ///
620 /// By default, performs semantic analysis when building the vector type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000623 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000624 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000625
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// \brief Build a new function type.
627 ///
628 /// By default, performs semantic analysis when building the function type.
629 /// Subclasses may override this routine to provide different behavior.
630 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000631 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000633 bool Variadic, unsigned Quals,
634 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
John McCalla2becad2009-10-21 00:40:46 +0000636 /// \brief Build a new unprototyped function type.
637 QualType RebuildFunctionNoProtoType(QualType ResultType);
638
John McCalled976492009-12-04 22:46:56 +0000639 /// \brief Rebuild an unresolved typename type, given the decl that
640 /// the UnresolvedUsingTypenameDecl was transformed to.
641 QualType RebuildUnresolvedUsingType(Decl *D);
642
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 /// \brief Build a new typedef type.
644 QualType RebuildTypedefType(TypedefDecl *Typedef) {
645 return SemaRef.Context.getTypeDeclType(Typedef);
646 }
647
648 /// \brief Build a new class/struct/union type.
649 QualType RebuildRecordType(RecordDecl *Record) {
650 return SemaRef.Context.getTypeDeclType(Record);
651 }
652
653 /// \brief Build a new Enum type.
654 QualType RebuildEnumType(EnumDecl *Enum) {
655 return SemaRef.Context.getTypeDeclType(Enum);
656 }
John McCall7da24312009-09-05 00:15:47 +0000657
Mike Stump1eb44332009-09-09 15:08:12 +0000658 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 ///
660 /// By default, performs semantic analysis when building the typeof type.
661 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000662 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 ///
666 /// By default, builds a new TypeOfType with the given underlying type.
667 QualType RebuildTypeOfType(QualType Underlying);
668
Mike Stump1eb44332009-09-09 15:08:12 +0000669 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 ///
671 /// By default, performs semantic analysis when building the decltype type.
672 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000673 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000674
Douglas Gregor577f75a2009-08-04 16:50:30 +0000675 /// \brief Build a new template specialization type.
676 ///
677 /// By default, performs semantic analysis when building the template
678 /// specialization type. Subclasses may override this routine to provide
679 /// different behavior.
680 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000681 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000682 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000684 /// \brief Build a new parenthesized type.
685 ///
686 /// By default, builds a new ParenType type from the inner type.
687 /// Subclasses may override this routine to provide different behavior.
688 QualType RebuildParenType(QualType InnerType) {
689 return SemaRef.Context.getParenType(InnerType);
690 }
691
Douglas Gregor577f75a2009-08-04 16:50:30 +0000692 /// \brief Build a new qualified name type.
693 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000694 /// By default, builds a new ElaboratedType type from the keyword,
695 /// the nested-name-specifier and the named type.
696 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000697 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
698 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000699 NestedNameSpecifier *NNS, QualType Named) {
700 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000701 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702
703 /// \brief Build a new typename type that refers to a template-id.
704 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000705 /// By default, builds a new DependentNameType type from the
706 /// nested-name-specifier and the given type. Subclasses may override
707 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000708 QualType RebuildDependentTemplateSpecializationType(
709 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000710 NestedNameSpecifier *Qualifier,
711 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000712 const IdentifierInfo *Name,
713 SourceLocation NameLoc,
714 const TemplateArgumentListInfo &Args) {
715 // Rebuild the template name.
716 // TODO: avoid TemplateName abstraction
717 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000718 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000719 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000720
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000721 if (InstName.isNull())
722 return QualType();
723
John McCall33500952010-06-11 00:33:02 +0000724 // If it's still dependent, make a dependent specialization.
725 if (InstName.getAsDependentTemplateName())
726 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000727 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000728
729 // Otherwise, make an elaborated type wrapping a non-dependent
730 // specialization.
731 QualType T =
732 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
733 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000734
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000735 // NOTE: NNS is already recorded in template specialization type T.
736 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000737 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000738
739 /// \brief Build a new typename type that refers to an identifier.
740 ///
741 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000742 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000743 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000744 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000745 NestedNameSpecifier *NNS,
746 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000747 SourceLocation KeywordLoc,
748 SourceRange NNSRange,
749 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000750 CXXScopeSpec SS;
751 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000752 SS.setRange(NNSRange);
753
Douglas Gregor40336422010-03-31 22:19:08 +0000754 if (NNS->isDependent()) {
755 // If the name is still dependent, just build a new dependent name type.
756 if (!SemaRef.computeDeclContext(SS))
757 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
758 }
759
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000760 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000761 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
762 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000763
764 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
765
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000766 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000767 // into a non-dependent elaborated-type-specifier. Find the tag we're
768 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000769 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000770 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
771 if (!DC)
772 return QualType();
773
John McCall56138762010-05-27 06:40:31 +0000774 if (SemaRef.RequireCompleteDeclContext(SS, DC))
775 return QualType();
776
Douglas Gregor40336422010-03-31 22:19:08 +0000777 TagDecl *Tag = 0;
778 SemaRef.LookupQualifiedName(Result, DC);
779 switch (Result.getResultKind()) {
780 case LookupResult::NotFound:
781 case LookupResult::NotFoundInCurrentInstantiation:
782 break;
Sean Huntc3021132010-05-05 15:23:54 +0000783
Douglas Gregor40336422010-03-31 22:19:08 +0000784 case LookupResult::Found:
785 Tag = Result.getAsSingle<TagDecl>();
786 break;
Sean Huntc3021132010-05-05 15:23:54 +0000787
Douglas Gregor40336422010-03-31 22:19:08 +0000788 case LookupResult::FoundOverloaded:
789 case LookupResult::FoundUnresolvedValue:
790 llvm_unreachable("Tag lookup cannot find non-tags");
791 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000792
Douglas Gregor40336422010-03-31 22:19:08 +0000793 case LookupResult::Ambiguous:
794 // Let the LookupResult structure handle ambiguities.
795 return QualType();
796 }
797
798 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000799 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000800 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000801 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000802 return QualType();
803 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000804
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
806 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000807 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
808 return QualType();
809 }
810
811 // Build the elaborated-type-specifier type.
812 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000813 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000814 }
Mike Stump1eb44332009-09-09 15:08:12 +0000815
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000816 /// \brief Build a new pack expansion type.
817 ///
818 /// By default, builds a new PackExpansionType type from the given pattern.
819 /// Subclasses may override this routine to provide different behavior.
820 QualType RebuildPackExpansionType(QualType Pattern,
821 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000822 SourceLocation EllipsisLoc,
823 llvm::Optional<unsigned> NumExpansions) {
824 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
825 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000826 }
827
Douglas Gregordcee1a12009-08-06 05:28:30 +0000828 /// \brief Build a new nested-name-specifier given the prefix and an
829 /// identifier that names the next step in the nested-name-specifier.
830 ///
831 /// By default, performs semantic analysis when building the new
832 /// nested-name-specifier. Subclasses may override this routine to provide
833 /// different behavior.
834 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
835 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000836 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000837 QualType ObjectType,
838 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000839
840 /// \brief Build a new nested-name-specifier given the prefix and the
841 /// namespace named in the next step in the nested-name-specifier.
842 ///
843 /// By default, performs semantic analysis when building the new
844 /// nested-name-specifier. Subclasses may override this routine to provide
845 /// different behavior.
846 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
847 SourceRange Range,
848 NamespaceDecl *NS);
849
850 /// \brief Build a new nested-name-specifier given the prefix and the
851 /// type named in 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,
858 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000859 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000860
861 /// \brief Build a new template name given a nested name specifier, a flag
862 /// indicating whether the "template" keyword was provided, and the template
863 /// that the template name refers to.
864 ///
865 /// By default, builds the new template name directly. Subclasses may override
866 /// this routine to provide different behavior.
867 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
868 bool TemplateKW,
869 TemplateDecl *Template);
870
Douglas Gregord1067e52009-08-06 06:41:21 +0000871 /// \brief Build a new template name given a nested name specifier and the
872 /// name that is referred to as a template.
873 ///
874 /// By default, performs semantic analysis to determine whether the name can
875 /// be resolved to a specific template, then builds the appropriate kind of
876 /// template name. Subclasses may override this routine to provide different
877 /// behavior.
878 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000879 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000880 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000881 QualType ObjectType,
882 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000883
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000884 /// \brief Build a new template name given a nested name specifier and the
885 /// overloaded operator name that is referred to as a template.
886 ///
887 /// By default, performs semantic analysis to determine whether the name can
888 /// be resolved to a specific template, then builds the appropriate kind of
889 /// template name. Subclasses may override this routine to provide different
890 /// behavior.
891 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
892 OverloadedOperatorKind Operator,
893 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000894
895 /// \brief Build a new template name given a template template parameter pack
896 /// and the
897 ///
898 /// By default, performs semantic analysis to determine whether the name can
899 /// be resolved to a specific template, then builds the appropriate kind of
900 /// template name. Subclasses may override this routine to provide different
901 /// behavior.
902 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
903 const TemplateArgument &ArgPack) {
904 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
905 }
906
Douglas Gregor43959a92009-08-20 07:17:43 +0000907 /// \brief Build a new compound statement.
908 ///
909 /// By default, performs semantic analysis to build the new statement.
910 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000911 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000912 MultiStmtArg Statements,
913 SourceLocation RBraceLoc,
914 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000915 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000916 IsStmtExpr);
917 }
918
919 /// \brief Build a new case statement.
920 ///
921 /// By default, performs semantic analysis to build the new statement.
922 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000923 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000924 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000925 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000926 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000927 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000928 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000929 ColonLoc);
930 }
Mike Stump1eb44332009-09-09 15:08:12 +0000931
Douglas Gregor43959a92009-08-20 07:17:43 +0000932 /// \brief Attach the body to a new case statement.
933 ///
934 /// By default, performs semantic analysis to build the new statement.
935 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000936 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000937 getSema().ActOnCaseStmtBody(S, Body);
938 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000939 }
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Douglas Gregor43959a92009-08-20 07:17:43 +0000941 /// \brief Build a new default 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 RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000946 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000947 Stmt *SubStmt) {
948 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000949 /*CurScope=*/0);
950 }
Mike Stump1eb44332009-09-09 15:08:12 +0000951
Douglas Gregor43959a92009-08-20 07:17:43 +0000952 /// \brief Build a new label statement.
953 ///
954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000956 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000957 IdentifierInfo *Id,
958 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000959 Stmt *SubStmt, bool HasUnusedAttr) {
960 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
961 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 }
Mike Stump1eb44332009-09-09 15:08:12 +0000963
Douglas Gregor43959a92009-08-20 07:17:43 +0000964 /// \brief Build a new "if" statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000968 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000969 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000970 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000971 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000972 }
Mike Stump1eb44332009-09-09 15:08:12 +0000973
Douglas Gregor43959a92009-08-20 07:17:43 +0000974 /// \brief Start building a new switch 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 RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000979 Expr *Cond, VarDecl *CondVar) {
980 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000981 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000982 }
Mike Stump1eb44332009-09-09 15:08:12 +0000983
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 /// \brief Attach the body to the switch statement.
985 ///
986 /// By default, performs semantic analysis to build the new statement.
987 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000988 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000989 Stmt *Switch, Stmt *Body) {
990 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000991 }
992
993 /// \brief Build a new while statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000997 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000998 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000999 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +00001000 Stmt *Body) {
1001 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 }
Mike Stump1eb44332009-09-09 15:08:12 +00001003
Douglas Gregor43959a92009-08-20 07:17:43 +00001004 /// \brief Build a new do-while statement.
1005 ///
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001008 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +00001009 SourceLocation WhileLoc,
1010 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001011 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +00001012 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001013 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1014 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 }
1016
1017 /// \brief Build a new for statement.
1018 ///
1019 /// By default, performs semantic analysis to build the new statement.
1020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001021 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001023 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001024 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +00001025 SourceLocation RParenLoc, Stmt *Body) {
1026 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +00001027 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +00001028 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 }
Mike Stump1eb44332009-09-09 15:08:12 +00001030
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 /// \brief Build a new goto statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001035 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 SourceLocation LabelLoc,
1037 LabelStmt *Label) {
1038 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1039 }
1040
1041 /// \brief Build a new indirect goto statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001045 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001046 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001047 Expr *Target) {
1048 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 }
Mike Stump1eb44332009-09-09 15:08:12 +00001050
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 /// \brief Build a new return statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001055 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001056 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +00001057
John McCall9ae2f072010-08-23 23:25:46 +00001058 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 }
Mike Stump1eb44332009-09-09 15:08:12 +00001060
Douglas Gregor43959a92009-08-20 07:17:43 +00001061 /// \brief Build a new declaration statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001065 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001066 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001067 SourceLocation EndLoc) {
1068 return getSema().Owned(
1069 new (getSema().Context) DeclStmt(
1070 DeclGroupRef::Create(getSema().Context,
1071 Decls, NumDecls),
1072 StartLoc, EndLoc));
1073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Anders Carlsson703e3942010-01-24 05:50:09 +00001075 /// \brief Build a new inline asm statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001079 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001080 bool IsSimple,
1081 bool IsVolatile,
1082 unsigned NumOutputs,
1083 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001084 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001085 MultiExprArg Constraints,
1086 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001087 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001088 MultiExprArg Clobbers,
1089 SourceLocation RParenLoc,
1090 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001091 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001092 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001093 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001094 RParenLoc, MSAsm);
1095 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001096
1097 /// \brief Build a new Objective-C @try 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 RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001102 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001103 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001104 Stmt *Finally) {
1105 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1106 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001107 }
1108
Douglas Gregorbe270a02010-04-26 17:57:08 +00001109 /// \brief Rebuild an Objective-C exception declaration.
1110 ///
1111 /// By default, performs semantic analysis to build the new declaration.
1112 /// Subclasses may override this routine to provide different behavior.
1113 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1114 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001115 return getSema().BuildObjCExceptionDecl(TInfo, T,
1116 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001117 ExceptionDecl->getLocation());
1118 }
Sean Huntc3021132010-05-05 15:23:54 +00001119
Douglas Gregorbe270a02010-04-26 17:57:08 +00001120 /// \brief Build a new Objective-C @catch statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001124 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001125 SourceLocation RParenLoc,
1126 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001127 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001128 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001129 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001130 }
Sean Huntc3021132010-05-05 15:23:54 +00001131
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001132 /// \brief Build a new Objective-C @finally statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001137 Stmt *Body) {
1138 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001139 }
Sean Huntc3021132010-05-05 15:23:54 +00001140
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001141 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001145 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001146 Expr *Operand) {
1147 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001148 }
Sean Huntc3021132010-05-05 15:23:54 +00001149
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001150 /// \brief Build a new Objective-C @synchronized statement.
1151 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001154 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001155 Expr *Object,
1156 Stmt *Body) {
1157 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1158 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001159 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001160
1161 /// \brief Build a new Objective-C fast enumeration statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001166 SourceLocation LParenLoc,
1167 Stmt *Element,
1168 Expr *Collection,
1169 SourceLocation RParenLoc,
1170 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001171 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001172 Element,
1173 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001174 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001175 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001176 }
Sean Huntc3021132010-05-05 15:23:54 +00001177
Douglas Gregor43959a92009-08-20 07:17:43 +00001178 /// \brief Build a new C++ exception declaration.
1179 ///
1180 /// By default, performs semantic analysis to build the new decaration.
1181 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001182 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001183 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001184 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001185 SourceLocation Loc) {
1186 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new C++ catch statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001193 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001194 VarDecl *ExceptionDecl,
1195 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001196 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1197 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001198 }
Mike Stump1eb44332009-09-09 15:08:12 +00001199
Douglas Gregor43959a92009-08-20 07:17:43 +00001200 /// \brief Build a new C++ try statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001204 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001205 Stmt *TryBlock,
1206 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001207 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001208 }
Mike Stump1eb44332009-09-09 15:08:12 +00001209
Douglas Gregorb98b1992009-08-11 05:31:07 +00001210 /// \brief Build a new expression that references a declaration.
1211 ///
1212 /// By default, performs semantic analysis to build the new expression.
1213 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001214 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001215 LookupResult &R,
1216 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001217 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1218 }
1219
1220
1221 /// \brief Build a new expression that references a declaration.
1222 ///
1223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001225 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001226 SourceRange QualifierRange,
1227 ValueDecl *VD,
1228 const DeclarationNameInfo &NameInfo,
1229 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001230 CXXScopeSpec SS;
1231 SS.setScopeRep(Qualifier);
1232 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001233
1234 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001235
1236 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001237 }
Mike Stump1eb44332009-09-09 15:08:12 +00001238
Douglas Gregorb98b1992009-08-11 05:31:07 +00001239 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001240 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001243 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001244 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001245 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001246 }
1247
Douglas Gregora71d8192009-09-04 17:36:40 +00001248 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001249 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001252 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001253 SourceLocation OperatorLoc,
1254 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001255 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001256 SourceRange QualifierRange,
1257 TypeSourceInfo *ScopeType,
1258 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001259 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001260 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001261
Douglas Gregorb98b1992009-08-11 05:31:07 +00001262 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001263 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001264 /// By default, performs semantic analysis to build the new expression.
1265 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001266 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001267 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001268 Expr *SubExpr) {
1269 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001270 }
Mike Stump1eb44332009-09-09 15:08:12 +00001271
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001272 /// \brief Build a new builtin offsetof expression.
1273 ///
1274 /// By default, performs semantic analysis to build the new expression.
1275 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001276 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001277 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001278 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001279 unsigned NumComponents,
1280 SourceLocation RParenLoc) {
1281 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1282 NumComponents, RParenLoc);
1283 }
Sean Huntc3021132010-05-05 15:23:54 +00001284
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001286 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001289 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001290 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001292 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001293 }
1294
Mike Stump1eb44332009-09-09 15:08:12 +00001295 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001297 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001300 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001301 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001302 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001303 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001304 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001305 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001306
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 return move(Result);
1308 }
Mike Stump1eb44332009-09-09 15:08:12 +00001309
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001311 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001314 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001316 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001318 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1319 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 RBracketLoc);
1321 }
1322
1323 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001324 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001327 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001330 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001331 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 }
1333
1334 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001335 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001338 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001339 bool isArrow,
1340 NestedNameSpecifier *Qualifier,
1341 SourceRange QualifierRange,
1342 const DeclarationNameInfo &MemberNameInfo,
1343 ValueDecl *Member,
1344 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001345 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001346 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001347 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001348 // We have a reference to an unnamed field. This is always the
1349 // base of an anonymous struct/union member access, i.e. the
1350 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001351 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001352 assert(Member->getType()->isRecordType() &&
1353 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001354
John McCall9ae2f072010-08-23 23:25:46 +00001355 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001356 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001357 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001358
John McCallf89e55a2010-11-18 06:31:45 +00001359 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001360 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001361 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001362 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001363 cast<FieldDecl>(Member)->getType(),
1364 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001365 return getSema().Owned(ME);
1366 }
Mike Stump1eb44332009-09-09 15:08:12 +00001367
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001368 CXXScopeSpec SS;
1369 if (Qualifier) {
1370 SS.setRange(QualifierRange);
1371 SS.setScopeRep(Qualifier);
1372 }
1373
John McCall9ae2f072010-08-23 23:25:46 +00001374 getSema().DefaultFunctionArrayConversion(Base);
1375 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001376
John McCall6bb80172010-03-30 21:47:33 +00001377 // FIXME: this involves duplicating earlier analysis in a lot of
1378 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001379 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001380 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001381 R.resolveKind();
1382
John McCall9ae2f072010-08-23 23:25:46 +00001383 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001384 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001385 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 }
Mike Stump1eb44332009-09-09 15:08:12 +00001387
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001389 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001392 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001393 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001394 Expr *LHS, Expr *RHS) {
1395 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 }
1397
1398 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001399 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 /// By default, performs semantic analysis to build the new expression.
1401 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001402 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001404 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001406 Expr *RHS) {
1407 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1408 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 }
1410
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001412 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001415 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001416 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001418 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001419 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001420 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 }
Mike Stump1eb44332009-09-09 15:08:12 +00001422
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001424 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001427 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001428 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001430 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001431 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001432 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001436 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001439 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 SourceLocation OpLoc,
1441 SourceLocation AccessorLoc,
1442 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001443
John McCall129e2df2009-11-30 22:42:35 +00001444 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001445 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001446 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001447 OpLoc, /*IsArrow*/ false,
1448 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001449 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001450 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 }
Mike Stump1eb44332009-09-09 15:08:12 +00001452
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001454 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001457 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001458 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001459 SourceLocation RBraceLoc,
1460 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001461 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001462 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1463 if (Result.isInvalid() || ResultTy->isDependentType())
1464 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001465
Douglas Gregore48319a2009-11-09 17:16:50 +00001466 // Patch in the result type we were given, which may have been computed
1467 // when the initial InitListExpr was built.
1468 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1469 ILE->setType(ResultTy);
1470 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 }
Mike Stump1eb44332009-09-09 15:08:12 +00001472
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001474 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001477 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 MultiExprArg ArrayExprs,
1479 SourceLocation EqualOrColonLoc,
1480 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001481 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001482 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001484 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001486 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001487
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 ArrayExprs.release();
1489 return move(Result);
1490 }
Mike Stump1eb44332009-09-09 15:08:12 +00001491
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001493 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// By default, builds the implicit value initialization without performing
1495 /// any semantic analysis. Subclasses may override this routine to provide
1496 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1499 }
Mike Stump1eb44332009-09-09 15:08:12 +00001500
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001502 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001505 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001506 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001507 SourceLocation RParenLoc) {
1508 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001509 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001510 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
1512
1513 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 MultiExprArg SubExprs,
1519 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001520 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001521 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
Mike Stump1eb44332009-09-09 15:08:12 +00001523
Douglas Gregorb98b1992009-08-11 05:31:07 +00001524 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001525 ///
1526 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// rather than attempting to map the label statement itself.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 SourceLocation LabelLoc,
1531 LabelStmt *Label) {
1532 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1533 }
Mike Stump1eb44332009-09-09 15:08:12 +00001534
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 /// \brief Build a new GNU statement expression.
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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001540 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001542 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 }
Mike Stump1eb44332009-09-09 15:08:12 +00001544
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// \brief Build a new __builtin_choose_expr expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001549 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001550 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 SourceLocation RParenLoc) {
1552 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001553 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 RParenLoc);
1555 }
Mike Stump1eb44332009-09-09 15:08:12 +00001556
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 /// \brief Build a new overloaded operator call expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// The semantic analysis provides the behavior of template instantiation,
1561 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001562 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// argument-dependent lookup, etc. Subclasses may override this routine to
1564 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001565 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001567 Expr *Callee,
1568 Expr *First,
1569 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001570
1571 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 /// reinterpret_cast.
1573 ///
1574 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001575 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001577 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 Stmt::StmtClass Class,
1579 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001580 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 SourceLocation RAngleLoc,
1582 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001583 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 SourceLocation RParenLoc) {
1585 switch (Class) {
1586 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001587 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001588 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590
1591 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001592 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001593 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001594 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001595
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001597 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001598 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001603 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001604 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001605 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001606
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 default:
1608 assert(false && "Invalid C++ named cast");
1609 break;
1610 }
Mike Stump1eb44332009-09-09 15:08:12 +00001611
John McCallf312b1e2010-08-26 23:41:50 +00001612 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 }
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// \brief Build a new C++ static_cast expression.
1616 ///
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001619 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001621 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 SourceLocation RAngleLoc,
1623 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001624 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001626 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001627 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001628 SourceRange(LAngleLoc, RAngleLoc),
1629 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 }
1631
1632 /// \brief Build a new C++ dynamic_cast expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001638 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 SourceLocation RAngleLoc,
1640 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001641 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001643 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001644 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001645 SourceRange(LAngleLoc, RAngleLoc),
1646 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 }
1648
1649 /// \brief Build a new C++ reinterpret_cast expression.
1650 ///
1651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001653 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001655 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 SourceLocation RAngleLoc,
1657 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001658 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001660 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001661 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001662 SourceRange(LAngleLoc, RAngleLoc),
1663 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 }
1665
1666 /// \brief Build a new C++ const_cast expression.
1667 ///
1668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001670 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001672 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 SourceLocation RAngleLoc,
1674 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001677 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001678 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001679 SourceRange(LAngleLoc, RAngleLoc),
1680 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 }
Mike Stump1eb44332009-09-09 15:08:12 +00001682
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// \brief Build a new C++ functional-style cast expression.
1684 ///
1685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001687 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1688 SourceLocation LParenLoc,
1689 Expr *Sub,
1690 SourceLocation RParenLoc) {
1691 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001692 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 RParenLoc);
1694 }
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 /// \brief Build a new C++ typeid(type) expression.
1697 ///
1698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001700 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001701 SourceLocation TypeidLoc,
1702 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001704 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001705 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 }
Mike Stump1eb44332009-09-09 15:08:12 +00001707
Francois Pichet01b7c302010-09-08 12:20:18 +00001708
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 /// \brief Build a new C++ typeid(expr) expression.
1710 ///
1711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001713 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001714 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001715 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001717 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001718 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001719 }
1720
Francois Pichet01b7c302010-09-08 12:20:18 +00001721 /// \brief Build a new C++ __uuidof(type) expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
1725 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1726 SourceLocation TypeidLoc,
1727 TypeSourceInfo *Operand,
1728 SourceLocation RParenLoc) {
1729 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1730 RParenLoc);
1731 }
1732
1733 /// \brief Build a new C++ __uuidof(expr) expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
1737 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1738 SourceLocation TypeidLoc,
1739 Expr *Operand,
1740 SourceLocation RParenLoc) {
1741 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1742 RParenLoc);
1743 }
1744
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 /// \brief Build a new C++ "this" expression.
1746 ///
1747 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001748 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001750 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001751 QualType ThisType,
1752 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001754 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1755 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001756 }
1757
1758 /// \brief Build a new C++ throw expression.
1759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001762 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001763 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 }
1765
1766 /// \brief Build a new C++ default-argument expression.
1767 ///
1768 /// By default, builds a new default-argument expression, which does not
1769 /// require any semantic analysis. Subclasses may override this routine to
1770 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001771 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001772 ParmVarDecl *Param) {
1773 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1774 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ zero-initialization expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001781 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1782 SourceLocation LParenLoc,
1783 SourceLocation RParenLoc) {
1784 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001785 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001786 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 }
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 /// \brief Build a new C++ "new" expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001794 bool UseGlobal,
1795 SourceLocation PlacementLParen,
1796 MultiExprArg PlacementArgs,
1797 SourceLocation PlacementRParen,
1798 SourceRange TypeIdParens,
1799 QualType AllocatedType,
1800 TypeSourceInfo *AllocatedTypeInfo,
1801 Expr *ArraySize,
1802 SourceLocation ConstructorLParen,
1803 MultiExprArg ConstructorArgs,
1804 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001805 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 PlacementLParen,
1807 move(PlacementArgs),
1808 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001809 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001810 AllocatedType,
1811 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001812 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 ConstructorLParen,
1814 move(ConstructorArgs),
1815 ConstructorRParen);
1816 }
Mike Stump1eb44332009-09-09 15:08:12 +00001817
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 /// \brief Build a new C++ "delete" expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001822 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 bool IsGlobalDelete,
1824 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001825 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001827 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 }
Mike Stump1eb44332009-09-09 15:08:12 +00001829
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 /// \brief Build a new unary type trait expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001834 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001835 SourceLocation StartLoc,
1836 TypeSourceInfo *T,
1837 SourceLocation RParenLoc) {
1838 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 }
1840
Francois Pichet6ad6f282010-12-07 00:08:36 +00001841 /// \brief Build a new binary type trait expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
1845 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1846 SourceLocation StartLoc,
1847 TypeSourceInfo *LhsT,
1848 TypeSourceInfo *RhsT,
1849 SourceLocation RParenLoc) {
1850 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1851 }
1852
Mike Stump1eb44332009-09-09 15:08:12 +00001853 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 /// expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001858 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001860 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001861 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 CXXScopeSpec SS;
1863 SS.setRange(QualifierRange);
1864 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001865
1866 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001867 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001868 *TemplateArgs);
1869
Abramo Bagnara25777432010-08-11 22:01:17 +00001870 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new template-id expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001877 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001878 LookupResult &R,
1879 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001880 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001881 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new object-construction expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001888 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001889 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 CXXConstructorDecl *Constructor,
1891 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001892 MultiExprArg Args,
1893 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001894 CXXConstructExpr::ConstructionKind ConstructKind,
1895 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001896 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001897 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001898 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001899 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001900
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001901 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001902 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001903 RequiresZeroInit, ConstructKind,
1904 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 }
1906
1907 /// \brief Build a new object-construction expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001911 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1912 SourceLocation LParenLoc,
1913 MultiExprArg Args,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 LParenLoc,
1917 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 RParenLoc);
1919 }
1920
1921 /// \brief Build a new object-construction expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001925 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1926 SourceLocation LParenLoc,
1927 MultiExprArg Args,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 LParenLoc,
1931 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001932 RParenLoc);
1933 }
Mike Stump1eb44332009-09-09 15:08:12 +00001934
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// \brief Build a new member reference expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001939 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001940 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001941 bool IsArrow,
1942 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001943 NestedNameSpecifier *Qualifier,
1944 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001945 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001946 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001947 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001948 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001949 SS.setRange(QualifierRange);
1950 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001951
John McCall9ae2f072010-08-23 23:25:46 +00001952 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001953 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001954 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001955 MemberNameInfo,
1956 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 }
1958
John McCall129e2df2009-11-30 22:42:35 +00001959 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001963 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001964 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001965 SourceLocation OperatorLoc,
1966 bool IsArrow,
1967 NestedNameSpecifier *Qualifier,
1968 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001969 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001970 LookupResult &R,
1971 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001972 CXXScopeSpec SS;
1973 SS.setRange(QualifierRange);
1974 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001975
John McCall9ae2f072010-08-23 23:25:46 +00001976 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001977 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001978 SS, FirstQualifierInScope,
1979 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001980 }
Mike Stump1eb44332009-09-09 15:08:12 +00001981
Sebastian Redl2e156222010-09-10 20:55:43 +00001982 /// \brief Build a new noexcept expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1987 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1988 }
1989
Douglas Gregoree8aff02011-01-04 17:33:58 +00001990 /// \brief Build a new expression to compute the length of a parameter pack.
1991 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1992 SourceLocation PackLoc,
1993 SourceLocation RParenLoc,
1994 unsigned Length) {
1995 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1996 OperatorLoc, Pack, PackLoc,
1997 RParenLoc, Length);
1998 }
1999
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 /// \brief Build a new Objective-C @encode expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002004 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002005 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002007 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002008 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002009 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002010
Douglas Gregor92e986e2010-04-22 16:44:27 +00002011 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002012 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002013 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002014 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002015 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002016 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002017 MultiExprArg Args,
2018 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002019 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2020 ReceiverTypeInfo->getType(),
2021 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002022 Sel, Method, LBracLoc, SelectorLoc,
2023 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002024 }
2025
2026 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002027 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002028 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002029 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002030 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002031 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002032 MultiExprArg Args,
2033 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002034 return SemaRef.BuildInstanceMessage(Receiver,
2035 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002036 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002037 Sel, Method, LBracLoc, SelectorLoc,
2038 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002039 }
2040
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002041 /// \brief Build a new Objective-C ivar reference expression.
2042 ///
2043 /// By default, performs semantic analysis to build the new expression.
2044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002045 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002046 SourceLocation IvarLoc,
2047 bool IsArrow, bool IsFreeIvar) {
2048 // FIXME: We lose track of the IsFreeIvar bit.
2049 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002050 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002051 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2052 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002053 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002054 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002055 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002056 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002057 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002058 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002059
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002060 if (Result.get())
2061 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002062
John McCall9ae2f072010-08-23 23:25:46 +00002063 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002064 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002065 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002066 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002067 /*TemplateArgs=*/0);
2068 }
Douglas Gregore3303542010-04-26 20:47:02 +00002069
2070 /// \brief Build a new Objective-C property reference expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002074 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002075 ObjCPropertyDecl *Property,
2076 SourceLocation PropertyLoc) {
2077 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002078 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002079 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2080 Sema::LookupMemberName);
2081 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002082 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002083 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002084 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002085 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002086 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002087
Douglas Gregore3303542010-04-26 20:47:02 +00002088 if (Result.get())
2089 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002090
John McCall9ae2f072010-08-23 23:25:46 +00002091 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002092 /*FIXME:*/PropertyLoc, IsArrow,
2093 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002094 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002095 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002096 /*TemplateArgs=*/0);
2097 }
Sean Huntc3021132010-05-05 15:23:54 +00002098
John McCall12f78a62010-12-02 01:19:52 +00002099 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002100 ///
2101 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002102 /// Subclasses may override this routine to provide different behavior.
2103 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2104 ObjCMethodDecl *Getter,
2105 ObjCMethodDecl *Setter,
2106 SourceLocation PropertyLoc) {
2107 // Since these expressions can only be value-dependent, we do not
2108 // need to perform semantic analysis again.
2109 return Owned(
2110 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2111 VK_LValue, OK_ObjCProperty,
2112 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002113 }
2114
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002115 /// \brief Build a new Objective-C "isa" expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002120 bool IsArrow) {
2121 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002122 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002123 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2124 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002125 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002126 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002127 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002128 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002129 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002130
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002131 if (Result.get())
2132 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002133
John McCall9ae2f072010-08-23 23:25:46 +00002134 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002135 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002136 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002137 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002138 /*TemplateArgs=*/0);
2139 }
Sean Huntc3021132010-05-05 15:23:54 +00002140
Douglas Gregorb98b1992009-08-11 05:31:07 +00002141 /// \brief Build a new shuffle vector expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002145 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002146 MultiExprArg SubExprs,
2147 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002148 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002149 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2151 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2152 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2153 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002154
Douglas Gregorb98b1992009-08-11 05:31:07 +00002155 // Build a reference to the __builtin_shufflevector builtin
2156 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002157 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002158 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002159 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002161
2162 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002163 unsigned NumSubExprs = SubExprs.size();
2164 Expr **Subs = (Expr **)SubExprs.release();
2165 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2166 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002167 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002168 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002169 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002170 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002171
Douglas Gregorb98b1992009-08-11 05:31:07 +00002172 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002173 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002174 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002176
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002178 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002179 }
John McCall43fed0d2010-11-12 08:19:04 +00002180
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002181 /// \brief Build a new template argument pack expansion.
2182 ///
2183 /// By default, performs semantic analysis to build a new pack expansion
2184 /// for a template argument. Subclasses may override this routine to provide
2185 /// different behavior.
2186 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002187 SourceLocation EllipsisLoc,
2188 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002189 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002190 case TemplateArgument::Expression: {
2191 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002192 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2193 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002194 if (Result.isInvalid())
2195 return TemplateArgumentLoc();
2196
2197 return TemplateArgumentLoc(Result.get(), Result.get());
2198 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002199
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002200 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002201 return TemplateArgumentLoc(TemplateArgument(
2202 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002203 NumExpansions),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002204 Pattern.getTemplateQualifierRange(),
2205 Pattern.getTemplateNameLoc(),
2206 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002207
2208 case TemplateArgument::Null:
2209 case TemplateArgument::Integral:
2210 case TemplateArgument::Declaration:
2211 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002212 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002213 llvm_unreachable("Pack expansion pattern has no parameter packs");
2214
2215 case TemplateArgument::Type:
2216 if (TypeSourceInfo *Expansion
2217 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002218 EllipsisLoc,
2219 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002220 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2221 Expansion);
2222 break;
2223 }
2224
2225 return TemplateArgumentLoc();
2226 }
2227
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002228 /// \brief Build a new expression pack expansion.
2229 ///
2230 /// By default, performs semantic analysis to build a new pack expansion
2231 /// for an expression. Subclasses may override this routine to provide
2232 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002233 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2234 llvm::Optional<unsigned> NumExpansions) {
2235 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002236 }
2237
John McCall43fed0d2010-11-12 08:19:04 +00002238private:
2239 QualType TransformTypeInObjectScope(QualType T,
2240 QualType ObjectType,
2241 NamedDecl *FirstQualifierInScope,
2242 NestedNameSpecifier *Prefix);
2243
2244 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2245 QualType ObjectType,
2246 NamedDecl *FirstQualifierInScope,
2247 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002248};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002249
Douglas Gregor43959a92009-08-20 07:17:43 +00002250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002251StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002252 if (!S)
2253 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002254
Douglas Gregor43959a92009-08-20 07:17:43 +00002255 switch (S->getStmtClass()) {
2256 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002257
Douglas Gregor43959a92009-08-20 07:17:43 +00002258 // Transform individual statement nodes
2259#define STMT(Node, Parent) \
2260 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2261#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002262#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002263
Douglas Gregor43959a92009-08-20 07:17:43 +00002264 // Transform expressions by calling TransformExpr.
2265#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002266#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002267#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002268#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002269 {
John McCall60d7b3a2010-08-24 06:29:42 +00002270 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002271 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002272 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002273
John McCall9ae2f072010-08-23 23:25:46 +00002274 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002275 }
Mike Stump1eb44332009-09-09 15:08:12 +00002276 }
2277
John McCall3fa5cae2010-10-26 07:05:15 +00002278 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002279}
Mike Stump1eb44332009-09-09 15:08:12 +00002280
2281
Douglas Gregor670444e2009-08-04 22:27:00 +00002282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002283ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002284 if (!E)
2285 return SemaRef.Owned(E);
2286
2287 switch (E->getStmtClass()) {
2288 case Stmt::NoStmtClass: break;
2289#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002290#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002291#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002292 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002293#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002294 }
2295
John McCall3fa5cae2010-10-26 07:05:15 +00002296 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002297}
2298
2299template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002300bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2301 unsigned NumInputs,
2302 bool IsCall,
2303 llvm::SmallVectorImpl<Expr *> &Outputs,
2304 bool *ArgChanged) {
2305 for (unsigned I = 0; I != NumInputs; ++I) {
2306 // If requested, drop call arguments that need to be dropped.
2307 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2308 if (ArgChanged)
2309 *ArgChanged = true;
2310
2311 break;
2312 }
2313
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002314 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2315 Expr *Pattern = Expansion->getPattern();
2316
2317 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2318 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2319 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2320
2321 // Determine whether the set of unexpanded parameter packs can and should
2322 // be expanded.
2323 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002324 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002325 llvm::Optional<unsigned> OrigNumExpansions
2326 = Expansion->getNumExpansions();
2327 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002328 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2329 Pattern->getSourceRange(),
2330 Unexpanded.data(),
2331 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002332 Expand, RetainExpansion,
2333 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002334 return true;
2335
2336 if (!Expand) {
2337 // The transform has determined that we should perform a simple
2338 // transformation on the pack expansion, producing another pack
2339 // expansion.
2340 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2341 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2342 if (OutPattern.isInvalid())
2343 return true;
2344
2345 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002346 Expansion->getEllipsisLoc(),
2347 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002348 if (Out.isInvalid())
2349 return true;
2350
2351 if (ArgChanged)
2352 *ArgChanged = true;
2353 Outputs.push_back(Out.get());
2354 continue;
2355 }
2356
2357 // The transform has determined that we should perform an elementwise
2358 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002359 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002360 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2361 ExprResult Out = getDerived().TransformExpr(Pattern);
2362 if (Out.isInvalid())
2363 return true;
2364
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002365 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002366 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2367 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002368 if (Out.isInvalid())
2369 return true;
2370 }
2371
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002372 if (ArgChanged)
2373 *ArgChanged = true;
2374 Outputs.push_back(Out.get());
2375 }
2376
2377 continue;
2378 }
2379
Douglas Gregoraa165f82011-01-03 19:04:46 +00002380 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2381 if (Result.isInvalid())
2382 return true;
2383
2384 if (Result.get() != Inputs[I] && ArgChanged)
2385 *ArgChanged = true;
2386
2387 Outputs.push_back(Result.get());
2388 }
2389
2390 return false;
2391}
2392
2393template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002394NestedNameSpecifier *
2395TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002396 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002397 QualType ObjectType,
2398 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002399 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002400
Douglas Gregor43959a92009-08-20 07:17:43 +00002401 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002402 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002403 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002404 ObjectType,
2405 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002406 if (!Prefix)
2407 return 0;
2408 }
Mike Stump1eb44332009-09-09 15:08:12 +00002409
Douglas Gregordcee1a12009-08-06 05:28:30 +00002410 switch (NNS->getKind()) {
2411 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002412 if (Prefix) {
2413 // The object type and qualifier-in-scope really apply to the
2414 // leftmost entity.
2415 ObjectType = QualType();
2416 FirstQualifierInScope = 0;
2417 }
2418
Mike Stump1eb44332009-09-09 15:08:12 +00002419 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002420 "Identifier nested-name-specifier with no prefix or object type");
2421 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2422 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002423 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002424
2425 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002426 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002427 ObjectType,
2428 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002429
Douglas Gregordcee1a12009-08-06 05:28:30 +00002430 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002431 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002432 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002433 getDerived().TransformDecl(Range.getBegin(),
2434 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002436 Prefix == NNS->getPrefix() &&
2437 NS == NNS->getAsNamespace())
2438 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002439
Douglas Gregordcee1a12009-08-06 05:28:30 +00002440 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2441 }
Mike Stump1eb44332009-09-09 15:08:12 +00002442
Douglas Gregordcee1a12009-08-06 05:28:30 +00002443 case NestedNameSpecifier::Global:
2444 // There is no meaningful transformation that one could perform on the
2445 // global scope.
2446 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002447
Douglas Gregordcee1a12009-08-06 05:28:30 +00002448 case NestedNameSpecifier::TypeSpecWithTemplate:
2449 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002450 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002451 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2452 ObjectType,
2453 FirstQualifierInScope,
2454 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002455 if (T.isNull())
2456 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002457
Douglas Gregordcee1a12009-08-06 05:28:30 +00002458 if (!getDerived().AlwaysRebuild() &&
2459 Prefix == NNS->getPrefix() &&
2460 T == QualType(NNS->getAsType(), 0))
2461 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002462
2463 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2464 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002465 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002466 }
2467 }
Mike Stump1eb44332009-09-09 15:08:12 +00002468
Douglas Gregordcee1a12009-08-06 05:28:30 +00002469 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002470 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002471}
2472
2473template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002474DeclarationNameInfo
2475TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002476::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002477 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002478 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002479 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002480
2481 switch (Name.getNameKind()) {
2482 case DeclarationName::Identifier:
2483 case DeclarationName::ObjCZeroArgSelector:
2484 case DeclarationName::ObjCOneArgSelector:
2485 case DeclarationName::ObjCMultiArgSelector:
2486 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002487 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002488 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002489 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002490
Douglas Gregor81499bb2009-09-03 22:13:48 +00002491 case DeclarationName::CXXConstructorName:
2492 case DeclarationName::CXXDestructorName:
2493 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002494 TypeSourceInfo *NewTInfo;
2495 CanQualType NewCanTy;
2496 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002497 NewTInfo = getDerived().TransformType(OldTInfo);
2498 if (!NewTInfo)
2499 return DeclarationNameInfo();
2500 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002501 }
2502 else {
2503 NewTInfo = 0;
2504 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002505 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002506 if (NewT.isNull())
2507 return DeclarationNameInfo();
2508 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2509 }
Mike Stump1eb44332009-09-09 15:08:12 +00002510
Abramo Bagnara25777432010-08-11 22:01:17 +00002511 DeclarationName NewName
2512 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2513 NewCanTy);
2514 DeclarationNameInfo NewNameInfo(NameInfo);
2515 NewNameInfo.setName(NewName);
2516 NewNameInfo.setNamedTypeInfo(NewTInfo);
2517 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002518 }
Mike Stump1eb44332009-09-09 15:08:12 +00002519 }
2520
Abramo Bagnara25777432010-08-11 22:01:17 +00002521 assert(0 && "Unknown name kind.");
2522 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002523}
2524
2525template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002526TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002527TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002530 SourceLocation Loc = getDerived().getBaseLocation();
2531
Douglas Gregord1067e52009-08-06 06:41:21 +00002532 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002533 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002534 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002535 /*FIXME*/ SourceRange(Loc),
2536 ObjectType,
2537 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002538 if (!NNS)
2539 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002540
Douglas Gregord1067e52009-08-06 06:41:21 +00002541 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002542 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002543 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002544 if (!TransTemplate)
2545 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002546
Douglas Gregord1067e52009-08-06 06:41:21 +00002547 if (!getDerived().AlwaysRebuild() &&
2548 NNS == QTN->getQualifier() &&
2549 TransTemplate == Template)
2550 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002551
Douglas Gregord1067e52009-08-06 06:41:21 +00002552 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2553 TransTemplate);
2554 }
Mike Stump1eb44332009-09-09 15:08:12 +00002555
John McCallf7a1a742009-11-24 19:00:30 +00002556 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002557 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002558 }
Mike Stump1eb44332009-09-09 15:08:12 +00002559
Douglas Gregord1067e52009-08-06 06:41:21 +00002560 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002561 NestedNameSpecifier *NNS = DTN->getQualifier();
2562 if (NNS) {
2563 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2564 /*FIXME:*/SourceRange(Loc),
2565 ObjectType,
2566 FirstQualifierInScope);
2567 if (!NNS) return TemplateName();
2568
2569 // These apply to the scope specifier, not the template.
2570 ObjectType = QualType();
2571 FirstQualifierInScope = 0;
2572 }
Mike Stump1eb44332009-09-09 15:08:12 +00002573
Douglas Gregord1067e52009-08-06 06:41:21 +00002574 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002575 NNS == DTN->getQualifier() &&
2576 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002577 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002578
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002579 if (DTN->isIdentifier()) {
2580 // FIXME: Bad range
2581 SourceRange QualifierRange(getDerived().getBaseLocation());
2582 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2583 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002584 ObjectType,
2585 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002586 }
Sean Huntc3021132010-05-05 15:23:54 +00002587
2588 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002589 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002590 }
Mike Stump1eb44332009-09-09 15:08:12 +00002591
Douglas Gregord1067e52009-08-06 06:41:21 +00002592 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002593 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002594 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002595 if (!TransTemplate)
2596 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002597
Douglas Gregord1067e52009-08-06 06:41:21 +00002598 if (!getDerived().AlwaysRebuild() &&
2599 TransTemplate == Template)
2600 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002601
Douglas Gregord1067e52009-08-06 06:41:21 +00002602 return TemplateName(TransTemplate);
2603 }
Mike Stump1eb44332009-09-09 15:08:12 +00002604
Douglas Gregor1aee05d2011-01-15 06:45:20 +00002605 if (SubstTemplateTemplateParmPackStorage *SubstPack
2606 = Name.getAsSubstTemplateTemplateParmPack()) {
2607 TemplateTemplateParmDecl *TransParam
2608 = cast_or_null<TemplateTemplateParmDecl>(
2609 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2610 if (!TransParam)
2611 return TemplateName();
2612
2613 if (!getDerived().AlwaysRebuild() &&
2614 TransParam == SubstPack->getParameterPack())
2615 return Name;
2616
2617 return getDerived().RebuildTemplateName(TransParam,
2618 SubstPack->getArgumentPack());
2619 }
2620
John McCallf7a1a742009-11-24 19:00:30 +00002621 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002622 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002623 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002624}
2625
2626template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002627void TreeTransform<Derived>::InventTemplateArgumentLoc(
2628 const TemplateArgument &Arg,
2629 TemplateArgumentLoc &Output) {
2630 SourceLocation Loc = getDerived().getBaseLocation();
2631 switch (Arg.getKind()) {
2632 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002633 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002634 break;
2635
2636 case TemplateArgument::Type:
2637 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002638 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002639
John McCall833ca992009-10-29 08:12:44 +00002640 break;
2641
Douglas Gregor788cd062009-11-11 01:00:40 +00002642 case TemplateArgument::Template:
2643 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2644 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002645
2646 case TemplateArgument::TemplateExpansion:
2647 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2648 break;
2649
John McCall833ca992009-10-29 08:12:44 +00002650 case TemplateArgument::Expression:
2651 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2652 break;
2653
2654 case TemplateArgument::Declaration:
2655 case TemplateArgument::Integral:
2656 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002657 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002658 break;
2659 }
2660}
2661
2662template<typename Derived>
2663bool TreeTransform<Derived>::TransformTemplateArgument(
2664 const TemplateArgumentLoc &Input,
2665 TemplateArgumentLoc &Output) {
2666 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002667 switch (Arg.getKind()) {
2668 case TemplateArgument::Null:
2669 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002670 Output = Input;
2671 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002672
Douglas Gregor670444e2009-08-04 22:27:00 +00002673 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002674 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002675 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002676 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002677
2678 DI = getDerived().TransformType(DI);
2679 if (!DI) return true;
2680
2681 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2682 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002683 }
Mike Stump1eb44332009-09-09 15:08:12 +00002684
Douglas Gregor670444e2009-08-04 22:27:00 +00002685 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002686 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002687 DeclarationName Name;
2688 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2689 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002690 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002691 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002692 if (!D) return true;
2693
John McCall828bff22009-10-29 18:45:58 +00002694 Expr *SourceExpr = Input.getSourceDeclExpression();
2695 if (SourceExpr) {
2696 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002697 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002698 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002699 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002700 }
2701
2702 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002703 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002704 }
Mike Stump1eb44332009-09-09 15:08:12 +00002705
Douglas Gregor788cd062009-11-11 01:00:40 +00002706 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002707 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002708 TemplateName Template
2709 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2710 if (Template.isNull())
2711 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002712
Douglas Gregor788cd062009-11-11 01:00:40 +00002713 Output = TemplateArgumentLoc(TemplateArgument(Template),
2714 Input.getTemplateQualifierRange(),
2715 Input.getTemplateNameLoc());
2716 return false;
2717 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002718
2719 case TemplateArgument::TemplateExpansion:
2720 llvm_unreachable("Caller should expand pack expansions");
2721
Douglas Gregor670444e2009-08-04 22:27:00 +00002722 case TemplateArgument::Expression: {
2723 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002724 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002725 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002726
John McCall833ca992009-10-29 08:12:44 +00002727 Expr *InputExpr = Input.getSourceExpression();
2728 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2729
John McCall60d7b3a2010-08-24 06:29:42 +00002730 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002731 = getDerived().TransformExpr(InputExpr);
2732 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002733 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002734 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002735 }
Mike Stump1eb44332009-09-09 15:08:12 +00002736
Douglas Gregor670444e2009-08-04 22:27:00 +00002737 case TemplateArgument::Pack: {
2738 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2739 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002740 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002741 AEnd = Arg.pack_end();
2742 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002743
John McCall833ca992009-10-29 08:12:44 +00002744 // FIXME: preserve source information here when we start
2745 // caring about parameter packs.
2746
John McCall828bff22009-10-29 18:45:58 +00002747 TemplateArgumentLoc InputArg;
2748 TemplateArgumentLoc OutputArg;
2749 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2750 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002751 return true;
2752
John McCall828bff22009-10-29 18:45:58 +00002753 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002754 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002755
2756 TemplateArgument *TransformedArgsPtr
2757 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2758 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2759 TransformedArgsPtr);
2760 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2761 TransformedArgs.size()),
2762 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002763 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002764 }
2765 }
Mike Stump1eb44332009-09-09 15:08:12 +00002766
Douglas Gregor670444e2009-08-04 22:27:00 +00002767 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002768 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002769}
2770
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002771/// \brief Iterator adaptor that invents template argument location information
2772/// for each of the template arguments in its underlying iterator.
2773template<typename Derived, typename InputIterator>
2774class TemplateArgumentLocInventIterator {
2775 TreeTransform<Derived> &Self;
2776 InputIterator Iter;
2777
2778public:
2779 typedef TemplateArgumentLoc value_type;
2780 typedef TemplateArgumentLoc reference;
2781 typedef typename std::iterator_traits<InputIterator>::difference_type
2782 difference_type;
2783 typedef std::input_iterator_tag iterator_category;
2784
2785 class pointer {
2786 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002787
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002788 public:
2789 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2790
2791 const TemplateArgumentLoc *operator->() const { return &Arg; }
2792 };
2793
2794 TemplateArgumentLocInventIterator() { }
2795
2796 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2797 InputIterator Iter)
2798 : Self(Self), Iter(Iter) { }
2799
2800 TemplateArgumentLocInventIterator &operator++() {
2801 ++Iter;
2802 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002803 }
2804
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002805 TemplateArgumentLocInventIterator operator++(int) {
2806 TemplateArgumentLocInventIterator Old(*this);
2807 ++(*this);
2808 return Old;
2809 }
2810
2811 reference operator*() const {
2812 TemplateArgumentLoc Result;
2813 Self.InventTemplateArgumentLoc(*Iter, Result);
2814 return Result;
2815 }
2816
2817 pointer operator->() const { return pointer(**this); }
2818
2819 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2820 const TemplateArgumentLocInventIterator &Y) {
2821 return X.Iter == Y.Iter;
2822 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002823
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002824 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2825 const TemplateArgumentLocInventIterator &Y) {
2826 return X.Iter != Y.Iter;
2827 }
2828};
2829
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002830template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002831template<typename InputIterator>
2832bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2833 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002834 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002835 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002836 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002837 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002838
2839 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2840 // Unpack argument packs, which we translate them into separate
2841 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002842 // FIXME: We could do much better if we could guarantee that the
2843 // TemplateArgumentLocInfo for the pack expansion would be usable for
2844 // all of the template arguments in the argument pack.
2845 typedef TemplateArgumentLocInventIterator<Derived,
2846 TemplateArgument::pack_iterator>
2847 PackLocIterator;
2848 if (TransformTemplateArguments(PackLocIterator(*this,
2849 In.getArgument().pack_begin()),
2850 PackLocIterator(*this,
2851 In.getArgument().pack_end()),
2852 Outputs))
2853 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002854
2855 continue;
2856 }
2857
2858 if (In.getArgument().isPackExpansion()) {
2859 // We have a pack expansion, for which we will be substituting into
2860 // the pattern.
2861 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002862 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002863 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00002864 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2865 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002866
2867 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2868 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2869 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2870
2871 // Determine whether the set of unexpanded parameter packs can and should
2872 // be expanded.
2873 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002874 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002875 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002876 if (getDerived().TryExpandParameterPacks(Ellipsis,
2877 Pattern.getSourceRange(),
2878 Unexpanded.data(),
2879 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002880 Expand,
2881 RetainExpansion,
2882 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002883 return true;
2884
2885 if (!Expand) {
2886 // The transform has determined that we should perform a simple
2887 // transformation on the pack expansion, producing another pack
2888 // expansion.
2889 TemplateArgumentLoc OutPattern;
2890 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2891 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2892 return true;
2893
Douglas Gregorcded4f62011-01-14 17:04:44 +00002894 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2895 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002896 if (Out.getArgument().isNull())
2897 return true;
2898
2899 Outputs.addArgument(Out);
2900 continue;
2901 }
2902
2903 // The transform has determined that we should perform an elementwise
2904 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002905 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2907
2908 if (getDerived().TransformTemplateArgument(Pattern, Out))
2909 return true;
2910
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002911 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00002912 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2913 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002914 if (Out.getArgument().isNull())
2915 return true;
2916 }
2917
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002918 Outputs.addArgument(Out);
2919 }
2920
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002921 // If we're supposed to retain a pack expansion, do so by temporarily
2922 // forgetting the partially-substituted parameter pack.
2923 if (RetainExpansion) {
2924 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2925
2926 if (getDerived().TransformTemplateArgument(Pattern, Out))
2927 return true;
2928
Douglas Gregorcded4f62011-01-14 17:04:44 +00002929 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2930 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002931 if (Out.getArgument().isNull())
2932 return true;
2933
2934 Outputs.addArgument(Out);
2935 }
Douglas Gregord3731192011-01-10 07:32:04 +00002936
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002937 continue;
2938 }
2939
2940 // The simple case:
2941 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002942 return true;
2943
2944 Outputs.addArgument(Out);
2945 }
2946
2947 return false;
2948
2949}
2950
Douglas Gregor577f75a2009-08-04 16:50:30 +00002951//===----------------------------------------------------------------------===//
2952// Type transformation
2953//===----------------------------------------------------------------------===//
2954
2955template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002956QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002957 if (getDerived().AlreadyTransformed(T))
2958 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002959
John McCalla2becad2009-10-21 00:40:46 +00002960 // Temporary workaround. All of these transformations should
2961 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002962 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002963 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002964
John McCall43fed0d2010-11-12 08:19:04 +00002965 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002966
John McCalla2becad2009-10-21 00:40:46 +00002967 if (!NewDI)
2968 return QualType();
2969
2970 return NewDI->getType();
2971}
2972
2973template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002974TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002975 if (getDerived().AlreadyTransformed(DI->getType()))
2976 return DI;
2977
2978 TypeLocBuilder TLB;
2979
2980 TypeLoc TL = DI->getTypeLoc();
2981 TLB.reserve(TL.getFullDataSize());
2982
John McCall43fed0d2010-11-12 08:19:04 +00002983 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002984 if (Result.isNull())
2985 return 0;
2986
John McCalla93c9342009-12-07 02:54:59 +00002987 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002988}
2989
2990template<typename Derived>
2991QualType
John McCall43fed0d2010-11-12 08:19:04 +00002992TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002993 switch (T.getTypeLocClass()) {
2994#define ABSTRACT_TYPELOC(CLASS, PARENT)
2995#define TYPELOC(CLASS, PARENT) \
2996 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002997 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002998#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002999 }
Mike Stump1eb44332009-09-09 15:08:12 +00003000
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003001 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003002 return QualType();
3003}
3004
3005/// FIXME: By default, this routine adds type qualifiers only to types
3006/// that can have qualifiers, and silently suppresses those qualifiers
3007/// that are not permitted (e.g., qualifiers on reference or function
3008/// types). This is the right thing for template instantiation, but
3009/// probably not for other clients.
3010template<typename Derived>
3011QualType
3012TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003013 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003014 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003015
John McCall43fed0d2010-11-12 08:19:04 +00003016 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003017 if (Result.isNull())
3018 return QualType();
3019
3020 // Silently suppress qualifiers if the result type can't be qualified.
3021 // FIXME: this is the right thing for template instantiation, but
3022 // probably not for other clients.
3023 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003024 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003025
John McCall28654742010-06-05 06:41:15 +00003026 if (!Quals.empty()) {
3027 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3028 TLB.push<QualifiedTypeLoc>(Result);
3029 // No location information to preserve.
3030 }
John McCalla2becad2009-10-21 00:40:46 +00003031
3032 return Result;
3033}
3034
John McCall43fed0d2010-11-12 08:19:04 +00003035/// \brief Transforms a type that was written in a scope specifier,
3036/// given an object type, the results of unqualified lookup, and
3037/// an already-instantiated prefix.
3038///
3039/// The object type is provided iff the scope specifier qualifies the
3040/// member of a dependent member-access expression. The prefix is
3041/// provided iff the the scope specifier in which this appears has a
3042/// prefix.
3043///
3044/// This is private to TreeTransform.
3045template<typename Derived>
3046QualType
3047TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3048 QualType ObjectType,
3049 NamedDecl *UnqualLookup,
3050 NestedNameSpecifier *Prefix) {
3051 if (getDerived().AlreadyTransformed(T))
3052 return T;
3053
3054 TypeSourceInfo *TSI =
3055 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
3056
3057 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3058 UnqualLookup, Prefix);
3059 if (!TSI) return QualType();
3060 return TSI->getType();
3061}
3062
3063template<typename Derived>
3064TypeSourceInfo *
3065TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3066 QualType ObjectType,
3067 NamedDecl *UnqualLookup,
3068 NestedNameSpecifier *Prefix) {
3069 // TODO: in some cases, we might be some verification to do here.
3070 if (ObjectType.isNull())
3071 return getDerived().TransformType(TSI);
3072
3073 QualType T = TSI->getType();
3074 if (getDerived().AlreadyTransformed(T))
3075 return TSI;
3076
3077 TypeLocBuilder TLB;
3078 QualType Result;
3079
3080 if (isa<TemplateSpecializationType>(T)) {
3081 TemplateSpecializationTypeLoc TL
3082 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3083
3084 TemplateName Template =
3085 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3086 ObjectType, UnqualLookup);
3087 if (Template.isNull()) return 0;
3088
3089 Result = getDerived()
3090 .TransformTemplateSpecializationType(TLB, TL, Template);
3091 } else if (isa<DependentTemplateSpecializationType>(T)) {
3092 DependentTemplateSpecializationTypeLoc TL
3093 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3094
3095 Result = getDerived()
3096 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3097 } else {
3098 // Nothing special needs to be done for these.
3099 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3100 }
3101
3102 if (Result.isNull()) return 0;
3103 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3104}
3105
John McCalla2becad2009-10-21 00:40:46 +00003106template <class TyLoc> static inline
3107QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3108 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3109 NewT.setNameLoc(T.getNameLoc());
3110 return T.getType();
3111}
3112
John McCalla2becad2009-10-21 00:40:46 +00003113template<typename Derived>
3114QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003115 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003116 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3117 NewT.setBuiltinLoc(T.getBuiltinLoc());
3118 if (T.needsExtraLocalData())
3119 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3120 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003121}
Mike Stump1eb44332009-09-09 15:08:12 +00003122
Douglas Gregor577f75a2009-08-04 16:50:30 +00003123template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003124QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003125 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003126 // FIXME: recurse?
3127 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003128}
Mike Stump1eb44332009-09-09 15:08:12 +00003129
Douglas Gregor577f75a2009-08-04 16:50:30 +00003130template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003131QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003132 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003133 QualType PointeeType
3134 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003135 if (PointeeType.isNull())
3136 return QualType();
3137
3138 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003139 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003140 // A dependent pointer type 'T *' has is being transformed such
3141 // that an Objective-C class type is being replaced for 'T'. The
3142 // resulting pointer type is an ObjCObjectPointerType, not a
3143 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003144 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003145
John McCallc12c5bb2010-05-15 11:32:37 +00003146 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3147 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003148 return Result;
3149 }
John McCall43fed0d2010-11-12 08:19:04 +00003150
Douglas Gregor92e986e2010-04-22 16:44:27 +00003151 if (getDerived().AlwaysRebuild() ||
3152 PointeeType != TL.getPointeeLoc().getType()) {
3153 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3154 if (Result.isNull())
3155 return QualType();
3156 }
Sean Huntc3021132010-05-05 15:23:54 +00003157
Douglas Gregor92e986e2010-04-22 16:44:27 +00003158 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3159 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003160 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003161}
Mike Stump1eb44332009-09-09 15:08:12 +00003162
3163template<typename Derived>
3164QualType
John McCalla2becad2009-10-21 00:40:46 +00003165TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003166 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003167 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003168 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3169 if (PointeeType.isNull())
3170 return QualType();
3171
3172 QualType Result = TL.getType();
3173 if (getDerived().AlwaysRebuild() ||
3174 PointeeType != TL.getPointeeLoc().getType()) {
3175 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003176 TL.getSigilLoc());
3177 if (Result.isNull())
3178 return QualType();
3179 }
3180
Douglas Gregor39968ad2010-04-22 16:50:51 +00003181 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003182 NewT.setSigilLoc(TL.getSigilLoc());
3183 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003184}
3185
John McCall85737a72009-10-30 00:06:24 +00003186/// Transforms a reference type. Note that somewhat paradoxically we
3187/// don't care whether the type itself is an l-value type or an r-value
3188/// type; we only care if the type was *written* as an l-value type
3189/// or an r-value type.
3190template<typename Derived>
3191QualType
3192TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003193 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003194 const ReferenceType *T = TL.getTypePtr();
3195
3196 // Note that this works with the pointee-as-written.
3197 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3198 if (PointeeType.isNull())
3199 return QualType();
3200
3201 QualType Result = TL.getType();
3202 if (getDerived().AlwaysRebuild() ||
3203 PointeeType != T->getPointeeTypeAsWritten()) {
3204 Result = getDerived().RebuildReferenceType(PointeeType,
3205 T->isSpelledAsLValue(),
3206 TL.getSigilLoc());
3207 if (Result.isNull())
3208 return QualType();
3209 }
3210
3211 // r-value references can be rebuilt as l-value references.
3212 ReferenceTypeLoc NewTL;
3213 if (isa<LValueReferenceType>(Result))
3214 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3215 else
3216 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3217 NewTL.setSigilLoc(TL.getSigilLoc());
3218
3219 return Result;
3220}
3221
Mike Stump1eb44332009-09-09 15:08:12 +00003222template<typename Derived>
3223QualType
John McCalla2becad2009-10-21 00:40:46 +00003224TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003225 LValueReferenceTypeLoc TL) {
3226 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003227}
3228
Mike Stump1eb44332009-09-09 15:08:12 +00003229template<typename Derived>
3230QualType
John McCalla2becad2009-10-21 00:40:46 +00003231TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003232 RValueReferenceTypeLoc TL) {
3233 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003234}
Mike Stump1eb44332009-09-09 15:08:12 +00003235
Douglas Gregor577f75a2009-08-04 16:50:30 +00003236template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003237QualType
John McCalla2becad2009-10-21 00:40:46 +00003238TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003239 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003240 MemberPointerType *T = TL.getTypePtr();
3241
3242 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003243 if (PointeeType.isNull())
3244 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003245
John McCalla2becad2009-10-21 00:40:46 +00003246 // TODO: preserve source information for this.
3247 QualType ClassType
3248 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003249 if (ClassType.isNull())
3250 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003251
John McCalla2becad2009-10-21 00:40:46 +00003252 QualType Result = TL.getType();
3253 if (getDerived().AlwaysRebuild() ||
3254 PointeeType != T->getPointeeType() ||
3255 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003256 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3257 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003258 if (Result.isNull())
3259 return QualType();
3260 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003261
John McCalla2becad2009-10-21 00:40:46 +00003262 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3263 NewTL.setSigilLoc(TL.getSigilLoc());
3264
3265 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266}
3267
Mike Stump1eb44332009-09-09 15:08:12 +00003268template<typename Derived>
3269QualType
John McCalla2becad2009-10-21 00:40:46 +00003270TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003271 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003272 ConstantArrayType *T = TL.getTypePtr();
3273 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003274 if (ElementType.isNull())
3275 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003276
John McCalla2becad2009-10-21 00:40:46 +00003277 QualType Result = TL.getType();
3278 if (getDerived().AlwaysRebuild() ||
3279 ElementType != T->getElementType()) {
3280 Result = getDerived().RebuildConstantArrayType(ElementType,
3281 T->getSizeModifier(),
3282 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003283 T->getIndexTypeCVRQualifiers(),
3284 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003285 if (Result.isNull())
3286 return QualType();
3287 }
Sean Huntc3021132010-05-05 15:23:54 +00003288
John McCalla2becad2009-10-21 00:40:46 +00003289 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3290 NewTL.setLBracketLoc(TL.getLBracketLoc());
3291 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003292
John McCalla2becad2009-10-21 00:40:46 +00003293 Expr *Size = TL.getSizeExpr();
3294 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003295 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003296 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3297 }
3298 NewTL.setSizeExpr(Size);
3299
3300 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003301}
Mike Stump1eb44332009-09-09 15:08:12 +00003302
Douglas Gregor577f75a2009-08-04 16:50:30 +00003303template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003304QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003305 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003306 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003307 IncompleteArrayType *T = TL.getTypePtr();
3308 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003309 if (ElementType.isNull())
3310 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003311
John McCalla2becad2009-10-21 00:40:46 +00003312 QualType Result = TL.getType();
3313 if (getDerived().AlwaysRebuild() ||
3314 ElementType != T->getElementType()) {
3315 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003316 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003317 T->getIndexTypeCVRQualifiers(),
3318 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003319 if (Result.isNull())
3320 return QualType();
3321 }
Sean Huntc3021132010-05-05 15:23:54 +00003322
John McCalla2becad2009-10-21 00:40:46 +00003323 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3324 NewTL.setLBracketLoc(TL.getLBracketLoc());
3325 NewTL.setRBracketLoc(TL.getRBracketLoc());
3326 NewTL.setSizeExpr(0);
3327
3328 return Result;
3329}
3330
3331template<typename Derived>
3332QualType
3333TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003334 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003335 VariableArrayType *T = TL.getTypePtr();
3336 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3337 if (ElementType.isNull())
3338 return QualType();
3339
3340 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003342
John McCall60d7b3a2010-08-24 06:29:42 +00003343 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003344 = getDerived().TransformExpr(T->getSizeExpr());
3345 if (SizeResult.isInvalid())
3346 return QualType();
3347
John McCall9ae2f072010-08-23 23:25:46 +00003348 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003349
3350 QualType Result = TL.getType();
3351 if (getDerived().AlwaysRebuild() ||
3352 ElementType != T->getElementType() ||
3353 Size != T->getSizeExpr()) {
3354 Result = getDerived().RebuildVariableArrayType(ElementType,
3355 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003356 Size,
John McCalla2becad2009-10-21 00:40:46 +00003357 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003358 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003359 if (Result.isNull())
3360 return QualType();
3361 }
Sean Huntc3021132010-05-05 15:23:54 +00003362
John McCalla2becad2009-10-21 00:40:46 +00003363 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3364 NewTL.setLBracketLoc(TL.getLBracketLoc());
3365 NewTL.setRBracketLoc(TL.getRBracketLoc());
3366 NewTL.setSizeExpr(Size);
3367
3368 return Result;
3369}
3370
3371template<typename Derived>
3372QualType
3373TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003374 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003375 DependentSizedArrayType *T = TL.getTypePtr();
3376 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3377 if (ElementType.isNull())
3378 return QualType();
3379
3380 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003381 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003382
John McCall60d7b3a2010-08-24 06:29:42 +00003383 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003384 = getDerived().TransformExpr(T->getSizeExpr());
3385 if (SizeResult.isInvalid())
3386 return QualType();
3387
3388 Expr *Size = static_cast<Expr*>(SizeResult.get());
3389
3390 QualType Result = TL.getType();
3391 if (getDerived().AlwaysRebuild() ||
3392 ElementType != T->getElementType() ||
3393 Size != T->getSizeExpr()) {
3394 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3395 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003396 Size,
John McCalla2becad2009-10-21 00:40:46 +00003397 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003398 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003399 if (Result.isNull())
3400 return QualType();
3401 }
3402 else SizeResult.take();
3403
3404 // We might have any sort of array type now, but fortunately they
3405 // all have the same location layout.
3406 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3407 NewTL.setLBracketLoc(TL.getLBracketLoc());
3408 NewTL.setRBracketLoc(TL.getRBracketLoc());
3409 NewTL.setSizeExpr(Size);
3410
3411 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003412}
Mike Stump1eb44332009-09-09 15:08:12 +00003413
3414template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003416 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003417 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003418 DependentSizedExtVectorType *T = TL.getTypePtr();
3419
3420 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003421 QualType ElementType = getDerived().TransformType(T->getElementType());
3422 if (ElementType.isNull())
3423 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003424
Douglas Gregor670444e2009-08-04 22:27:00 +00003425 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003426 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003427
John McCall60d7b3a2010-08-24 06:29:42 +00003428 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003429 if (Size.isInvalid())
3430 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003431
John McCalla2becad2009-10-21 00:40:46 +00003432 QualType Result = TL.getType();
3433 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003434 ElementType != T->getElementType() ||
3435 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003436 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003437 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003438 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003439 if (Result.isNull())
3440 return QualType();
3441 }
John McCalla2becad2009-10-21 00:40:46 +00003442
3443 // Result might be dependent or not.
3444 if (isa<DependentSizedExtVectorType>(Result)) {
3445 DependentSizedExtVectorTypeLoc NewTL
3446 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3447 NewTL.setNameLoc(TL.getNameLoc());
3448 } else {
3449 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3450 NewTL.setNameLoc(TL.getNameLoc());
3451 }
3452
3453 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003454}
Mike Stump1eb44332009-09-09 15:08:12 +00003455
3456template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003457QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003458 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003459 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003460 QualType ElementType = getDerived().TransformType(T->getElementType());
3461 if (ElementType.isNull())
3462 return QualType();
3463
John McCalla2becad2009-10-21 00:40:46 +00003464 QualType Result = TL.getType();
3465 if (getDerived().AlwaysRebuild() ||
3466 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003467 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003468 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003469 if (Result.isNull())
3470 return QualType();
3471 }
Sean Huntc3021132010-05-05 15:23:54 +00003472
John McCalla2becad2009-10-21 00:40:46 +00003473 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3474 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003475
John McCalla2becad2009-10-21 00:40:46 +00003476 return Result;
3477}
3478
3479template<typename Derived>
3480QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003481 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003482 VectorType *T = TL.getTypePtr();
3483 QualType ElementType = getDerived().TransformType(T->getElementType());
3484 if (ElementType.isNull())
3485 return QualType();
3486
3487 QualType Result = TL.getType();
3488 if (getDerived().AlwaysRebuild() ||
3489 ElementType != T->getElementType()) {
3490 Result = getDerived().RebuildExtVectorType(ElementType,
3491 T->getNumElements(),
3492 /*FIXME*/ SourceLocation());
3493 if (Result.isNull())
3494 return QualType();
3495 }
Sean Huntc3021132010-05-05 15:23:54 +00003496
John McCalla2becad2009-10-21 00:40:46 +00003497 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3498 NewTL.setNameLoc(TL.getNameLoc());
3499
3500 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003501}
Mike Stump1eb44332009-09-09 15:08:12 +00003502
3503template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003504ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003505TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3506 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003507 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003508 TypeSourceInfo *NewDI = 0;
3509
3510 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3511 // If we're substituting into a pack expansion type and we know the
3512 TypeLoc OldTL = OldDI->getTypeLoc();
3513 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3514
3515 TypeLocBuilder TLB;
3516 TypeLoc NewTL = OldDI->getTypeLoc();
3517 TLB.reserve(NewTL.getFullDataSize());
3518
3519 QualType Result = getDerived().TransformType(TLB,
3520 OldExpansionTL.getPatternLoc());
3521 if (Result.isNull())
3522 return 0;
3523
3524 Result = RebuildPackExpansionType(Result,
3525 OldExpansionTL.getPatternLoc().getSourceRange(),
3526 OldExpansionTL.getEllipsisLoc(),
3527 NumExpansions);
3528 if (Result.isNull())
3529 return 0;
3530
3531 PackExpansionTypeLoc NewExpansionTL
3532 = TLB.push<PackExpansionTypeLoc>(Result);
3533 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3534 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3535 } else
3536 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003537 if (!NewDI)
3538 return 0;
3539
3540 if (NewDI == OldDI)
3541 return OldParm;
3542 else
3543 return ParmVarDecl::Create(SemaRef.Context,
3544 OldParm->getDeclContext(),
3545 OldParm->getLocation(),
3546 OldParm->getIdentifier(),
3547 NewDI->getType(),
3548 NewDI,
3549 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003550 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003551 /* DefArg */ NULL);
3552}
3553
3554template<typename Derived>
3555bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003556 TransformFunctionTypeParams(SourceLocation Loc,
3557 ParmVarDecl **Params, unsigned NumParams,
3558 const QualType *ParamTypes,
3559 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3560 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3561 for (unsigned i = 0; i != NumParams; ++i) {
3562 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003563 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003564 if (OldParm->isParameterPack()) {
3565 // We have a function parameter pack that may need to be expanded.
3566 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003567
Douglas Gregor603cfb42011-01-05 23:12:31 +00003568 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003569 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3570 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3571 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3572 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003573
3574 // Determine whether we should expand the parameter packs.
3575 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003576 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003577 llvm::Optional<unsigned> OrigNumExpansions
3578 = ExpansionTL.getTypePtr()->getNumExpansions();
3579 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003580 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3581 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003582 Unexpanded.data(),
3583 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003584 ShouldExpand,
3585 RetainExpansion,
3586 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003587 return true;
3588 }
3589
3590 if (ShouldExpand) {
3591 // Expand the function parameter pack into multiple, separate
3592 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003593 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003594 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003595 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3596 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003597 = getDerived().TransformFunctionTypeParam(OldParm,
3598 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003599 if (!NewParm)
3600 return true;
3601
Douglas Gregora009b592011-01-07 00:20:55 +00003602 OutParamTypes.push_back(NewParm->getType());
3603 if (PVars)
3604 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003605 }
Douglas Gregord3731192011-01-10 07:32:04 +00003606
3607 // If we're supposed to retain a pack expansion, do so by temporarily
3608 // forgetting the partially-substituted parameter pack.
3609 if (RetainExpansion) {
3610 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3611 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003612 = getDerived().TransformFunctionTypeParam(OldParm,
3613 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003614 if (!NewParm)
3615 return true;
3616
3617 OutParamTypes.push_back(NewParm->getType());
3618 if (PVars)
3619 PVars->push_back(NewParm);
3620 }
3621
Douglas Gregor603cfb42011-01-05 23:12:31 +00003622 // We're done with the pack expansion.
3623 continue;
3624 }
3625
3626 // We'll substitute the parameter now without expanding the pack
3627 // expansion.
3628 }
3629
3630 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003631 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3632 NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +00003633 if (!NewParm)
3634 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003635
Douglas Gregora009b592011-01-07 00:20:55 +00003636 OutParamTypes.push_back(NewParm->getType());
3637 if (PVars)
3638 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003639 continue;
3640 }
John McCall21ef0fa2010-03-11 09:03:00 +00003641
3642 // Deal with the possibility that we don't have a parameter
3643 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003644 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003645 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003646 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003647 if (const PackExpansionType *Expansion
3648 = dyn_cast<PackExpansionType>(OldType)) {
3649 // We have a function parameter pack that may need to be expanded.
3650 QualType Pattern = Expansion->getPattern();
3651 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3652 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3653
3654 // Determine whether we should expand the parameter packs.
3655 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003656 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003657 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003658 Unexpanded.data(),
3659 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003660 ShouldExpand,
3661 RetainExpansion,
3662 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003663 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003664 }
3665
3666 if (ShouldExpand) {
3667 // Expand the function parameter pack into multiple, separate
3668 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003669 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003670 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3671 QualType NewType = getDerived().TransformType(Pattern);
3672 if (NewType.isNull())
3673 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003674
Douglas Gregora009b592011-01-07 00:20:55 +00003675 OutParamTypes.push_back(NewType);
3676 if (PVars)
3677 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003678 }
3679
3680 // We're done with the pack expansion.
3681 continue;
3682 }
3683
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003684 // If we're supposed to retain a pack expansion, do so by temporarily
3685 // forgetting the partially-substituted parameter pack.
3686 if (RetainExpansion) {
3687 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3688 QualType NewType = getDerived().TransformType(Pattern);
3689 if (NewType.isNull())
3690 return true;
3691
3692 OutParamTypes.push_back(NewType);
3693 if (PVars)
3694 PVars->push_back(0);
3695 }
Douglas Gregord3731192011-01-10 07:32:04 +00003696
Douglas Gregor603cfb42011-01-05 23:12:31 +00003697 // We'll substitute the parameter now without expanding the pack
3698 // expansion.
3699 OldType = Expansion->getPattern();
3700 IsPackExpansion = true;
3701 }
3702
3703 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3704 QualType NewType = getDerived().TransformType(OldType);
3705 if (NewType.isNull())
3706 return true;
3707
3708 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003709 NewType = getSema().Context.getPackExpansionType(NewType,
3710 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003711
Douglas Gregora009b592011-01-07 00:20:55 +00003712 OutParamTypes.push_back(NewType);
3713 if (PVars)
3714 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003715 }
3716
3717 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003718 }
John McCall21ef0fa2010-03-11 09:03:00 +00003719
3720template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003721QualType
John McCalla2becad2009-10-21 00:40:46 +00003722TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003723 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003724 // Transform the parameters and return type.
3725 //
3726 // We instantiate in source order, with the return type first followed by
3727 // the parameters, because users tend to expect this (even if they shouldn't
3728 // rely on it!).
3729 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003730 // When the function has a trailing return type, we instantiate the
3731 // parameters before the return type, since the return type can then refer
3732 // to the parameters themselves (via decltype, sizeof, etc.).
3733 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003735 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003736 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003737
Douglas Gregordab60ad2010-10-01 18:44:50 +00003738 QualType ResultType;
3739
3740 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003741 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3742 TL.getParmArray(),
3743 TL.getNumArgs(),
3744 TL.getTypePtr()->arg_type_begin(),
3745 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003746 return QualType();
3747
3748 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3749 if (ResultType.isNull())
3750 return QualType();
3751 }
3752 else {
3753 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3754 if (ResultType.isNull())
3755 return QualType();
3756
Douglas Gregora009b592011-01-07 00:20:55 +00003757 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3758 TL.getParmArray(),
3759 TL.getNumArgs(),
3760 TL.getTypePtr()->arg_type_begin(),
3761 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003762 return QualType();
3763 }
3764
John McCalla2becad2009-10-21 00:40:46 +00003765 QualType Result = TL.getType();
3766 if (getDerived().AlwaysRebuild() ||
3767 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003768 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003769 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3770 Result = getDerived().RebuildFunctionProtoType(ResultType,
3771 ParamTypes.data(),
3772 ParamTypes.size(),
3773 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003774 T->getTypeQuals(),
3775 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003776 if (Result.isNull())
3777 return QualType();
3778 }
Mike Stump1eb44332009-09-09 15:08:12 +00003779
John McCalla2becad2009-10-21 00:40:46 +00003780 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3781 NewTL.setLParenLoc(TL.getLParenLoc());
3782 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003783 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003784 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3785 NewTL.setArg(i, ParamDecls[i]);
3786
3787 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003788}
Mike Stump1eb44332009-09-09 15:08:12 +00003789
Douglas Gregor577f75a2009-08-04 16:50:30 +00003790template<typename Derived>
3791QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003792 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003793 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003794 FunctionNoProtoType *T = TL.getTypePtr();
3795 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3796 if (ResultType.isNull())
3797 return QualType();
3798
3799 QualType Result = TL.getType();
3800 if (getDerived().AlwaysRebuild() ||
3801 ResultType != T->getResultType())
3802 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3803
3804 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3805 NewTL.setLParenLoc(TL.getLParenLoc());
3806 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003807 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003808
3809 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003810}
Mike Stump1eb44332009-09-09 15:08:12 +00003811
John McCalled976492009-12-04 22:46:56 +00003812template<typename Derived> QualType
3813TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003814 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003815 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003816 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003817 if (!D)
3818 return QualType();
3819
3820 QualType Result = TL.getType();
3821 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3822 Result = getDerived().RebuildUnresolvedUsingType(D);
3823 if (Result.isNull())
3824 return QualType();
3825 }
3826
3827 // We might get an arbitrary type spec type back. We should at
3828 // least always get a type spec type, though.
3829 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3830 NewTL.setNameLoc(TL.getNameLoc());
3831
3832 return Result;
3833}
3834
Douglas Gregor577f75a2009-08-04 16:50:30 +00003835template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003836QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003837 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003838 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003839 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003840 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3841 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003842 if (!Typedef)
3843 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003844
John McCalla2becad2009-10-21 00:40:46 +00003845 QualType Result = TL.getType();
3846 if (getDerived().AlwaysRebuild() ||
3847 Typedef != T->getDecl()) {
3848 Result = getDerived().RebuildTypedefType(Typedef);
3849 if (Result.isNull())
3850 return QualType();
3851 }
Mike Stump1eb44332009-09-09 15:08:12 +00003852
John McCalla2becad2009-10-21 00:40:46 +00003853 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3854 NewTL.setNameLoc(TL.getNameLoc());
3855
3856 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003857}
Mike Stump1eb44332009-09-09 15:08:12 +00003858
Douglas Gregor577f75a2009-08-04 16:50:30 +00003859template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003860QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003861 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003862 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003863 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003864
John McCall60d7b3a2010-08-24 06:29:42 +00003865 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003866 if (E.isInvalid())
3867 return QualType();
3868
John McCalla2becad2009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003871 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003872 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003873 if (Result.isNull())
3874 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003875 }
John McCalla2becad2009-10-21 00:40:46 +00003876 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003877
John McCalla2becad2009-10-21 00:40:46 +00003878 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003879 NewTL.setTypeofLoc(TL.getTypeofLoc());
3880 NewTL.setLParenLoc(TL.getLParenLoc());
3881 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003882
3883 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003884}
Mike Stump1eb44332009-09-09 15:08:12 +00003885
3886template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003887QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003888 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003889 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3890 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3891 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003892 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003893
John McCalla2becad2009-10-21 00:40:46 +00003894 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003895 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3896 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003897 if (Result.isNull())
3898 return QualType();
3899 }
Mike Stump1eb44332009-09-09 15:08:12 +00003900
John McCalla2becad2009-10-21 00:40:46 +00003901 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003902 NewTL.setTypeofLoc(TL.getTypeofLoc());
3903 NewTL.setLParenLoc(TL.getLParenLoc());
3904 NewTL.setRParenLoc(TL.getRParenLoc());
3905 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003906
3907 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003908}
Mike Stump1eb44332009-09-09 15:08:12 +00003909
3910template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003911QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003912 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003913 DecltypeType *T = TL.getTypePtr();
3914
Douglas Gregor670444e2009-08-04 22:27:00 +00003915 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003916 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003917
John McCall60d7b3a2010-08-24 06:29:42 +00003918 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003919 if (E.isInvalid())
3920 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003921
John McCalla2becad2009-10-21 00:40:46 +00003922 QualType Result = TL.getType();
3923 if (getDerived().AlwaysRebuild() ||
3924 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003925 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003926 if (Result.isNull())
3927 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003928 }
John McCalla2becad2009-10-21 00:40:46 +00003929 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003930
John McCalla2becad2009-10-21 00:40:46 +00003931 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3932 NewTL.setNameLoc(TL.getNameLoc());
3933
3934 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003935}
3936
3937template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003938QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003939 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003940 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003941 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003942 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3943 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003944 if (!Record)
3945 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003946
John McCalla2becad2009-10-21 00:40:46 +00003947 QualType Result = TL.getType();
3948 if (getDerived().AlwaysRebuild() ||
3949 Record != T->getDecl()) {
3950 Result = getDerived().RebuildRecordType(Record);
3951 if (Result.isNull())
3952 return QualType();
3953 }
Mike Stump1eb44332009-09-09 15:08:12 +00003954
John McCalla2becad2009-10-21 00:40:46 +00003955 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3956 NewTL.setNameLoc(TL.getNameLoc());
3957
3958 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003959}
Mike Stump1eb44332009-09-09 15:08:12 +00003960
3961template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003962QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003963 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003964 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003965 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003966 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3967 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003968 if (!Enum)
3969 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003970
John McCalla2becad2009-10-21 00:40:46 +00003971 QualType Result = TL.getType();
3972 if (getDerived().AlwaysRebuild() ||
3973 Enum != T->getDecl()) {
3974 Result = getDerived().RebuildEnumType(Enum);
3975 if (Result.isNull())
3976 return QualType();
3977 }
Mike Stump1eb44332009-09-09 15:08:12 +00003978
John McCalla2becad2009-10-21 00:40:46 +00003979 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3980 NewTL.setNameLoc(TL.getNameLoc());
3981
3982 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003983}
John McCall7da24312009-09-05 00:15:47 +00003984
John McCall3cb0ebd2010-03-10 03:28:59 +00003985template<typename Derived>
3986QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3987 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003988 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003989 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3990 TL.getTypePtr()->getDecl());
3991 if (!D) return QualType();
3992
3993 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3994 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3995 return T;
3996}
3997
Douglas Gregor577f75a2009-08-04 16:50:30 +00003998template<typename Derived>
3999QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004000 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004001 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004002 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004003}
4004
Mike Stump1eb44332009-09-09 15:08:12 +00004005template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004006QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004007 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004008 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004009 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00004010}
4011
4012template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004013QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4014 TypeLocBuilder &TLB,
4015 SubstTemplateTypeParmPackTypeLoc TL) {
4016 return TransformTypeSpecType(TLB, TL);
4017}
4018
4019template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004020QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004021 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004022 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004023 const TemplateSpecializationType *T = TL.getTypePtr();
4024
Mike Stump1eb44332009-09-09 15:08:12 +00004025 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00004026 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004027 if (Template.isNull())
4028 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004029
John McCall43fed0d2010-11-12 08:19:04 +00004030 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4031}
4032
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004033namespace {
4034 /// \brief Simple iterator that traverses the template arguments in a
4035 /// container that provides a \c getArgLoc() member function.
4036 ///
4037 /// This iterator is intended to be used with the iterator form of
4038 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4039 template<typename ArgLocContainer>
4040 class TemplateArgumentLocContainerIterator {
4041 ArgLocContainer *Container;
4042 unsigned Index;
4043
4044 public:
4045 typedef TemplateArgumentLoc value_type;
4046 typedef TemplateArgumentLoc reference;
4047 typedef int difference_type;
4048 typedef std::input_iterator_tag iterator_category;
4049
4050 class pointer {
4051 TemplateArgumentLoc Arg;
4052
4053 public:
4054 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4055
4056 const TemplateArgumentLoc *operator->() const {
4057 return &Arg;
4058 }
4059 };
4060
4061
4062 TemplateArgumentLocContainerIterator() {}
4063
4064 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4065 unsigned Index)
4066 : Container(&Container), Index(Index) { }
4067
4068 TemplateArgumentLocContainerIterator &operator++() {
4069 ++Index;
4070 return *this;
4071 }
4072
4073 TemplateArgumentLocContainerIterator operator++(int) {
4074 TemplateArgumentLocContainerIterator Old(*this);
4075 ++(*this);
4076 return Old;
4077 }
4078
4079 TemplateArgumentLoc operator*() const {
4080 return Container->getArgLoc(Index);
4081 }
4082
4083 pointer operator->() const {
4084 return pointer(Container->getArgLoc(Index));
4085 }
4086
4087 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004088 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004089 return X.Container == Y.Container && X.Index == Y.Index;
4090 }
4091
4092 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004093 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004094 return !(X == Y);
4095 }
4096 };
4097}
4098
4099
John McCall43fed0d2010-11-12 08:19:04 +00004100template <typename Derived>
4101QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4102 TypeLocBuilder &TLB,
4103 TemplateSpecializationTypeLoc TL,
4104 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004105 TemplateArgumentListInfo NewTemplateArgs;
4106 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4107 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004108 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4109 ArgIterator;
4110 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4111 ArgIterator(TL, TL.getNumArgs()),
4112 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004113 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004114
John McCall833ca992009-10-29 08:12:44 +00004115 // FIXME: maybe don't rebuild if all the template arguments are the same.
4116
4117 QualType Result =
4118 getDerived().RebuildTemplateSpecializationType(Template,
4119 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004120 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004121
4122 if (!Result.isNull()) {
4123 TemplateSpecializationTypeLoc NewTL
4124 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4125 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4126 NewTL.setLAngleLoc(TL.getLAngleLoc());
4127 NewTL.setRAngleLoc(TL.getRAngleLoc());
4128 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4129 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004130 }
Mike Stump1eb44332009-09-09 15:08:12 +00004131
John McCall833ca992009-10-29 08:12:44 +00004132 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004133}
Mike Stump1eb44332009-09-09 15:08:12 +00004134
4135template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004136QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004137TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004138 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004139 ElaboratedType *T = TL.getTypePtr();
4140
4141 NestedNameSpecifier *NNS = 0;
4142 // NOTE: the qualifier in an ElaboratedType is optional.
4143 if (T->getQualifier() != 0) {
4144 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004145 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004146 if (!NNS)
4147 return QualType();
4148 }
Mike Stump1eb44332009-09-09 15:08:12 +00004149
John McCall43fed0d2010-11-12 08:19:04 +00004150 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4151 if (NamedT.isNull())
4152 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004153
John McCalla2becad2009-10-21 00:40:46 +00004154 QualType Result = TL.getType();
4155 if (getDerived().AlwaysRebuild() ||
4156 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004157 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004158 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4159 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004160 if (Result.isNull())
4161 return QualType();
4162 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004163
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004164 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004165 NewTL.setKeywordLoc(TL.getKeywordLoc());
4166 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004167
4168 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004169}
Mike Stump1eb44332009-09-09 15:08:12 +00004170
4171template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004172QualType TreeTransform<Derived>::TransformAttributedType(
4173 TypeLocBuilder &TLB,
4174 AttributedTypeLoc TL) {
4175 const AttributedType *oldType = TL.getTypePtr();
4176 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4177 if (modifiedType.isNull())
4178 return QualType();
4179
4180 QualType result = TL.getType();
4181
4182 // FIXME: dependent operand expressions?
4183 if (getDerived().AlwaysRebuild() ||
4184 modifiedType != oldType->getModifiedType()) {
4185 // TODO: this is really lame; we should really be rebuilding the
4186 // equivalent type from first principles.
4187 QualType equivalentType
4188 = getDerived().TransformType(oldType->getEquivalentType());
4189 if (equivalentType.isNull())
4190 return QualType();
4191 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4192 modifiedType,
4193 equivalentType);
4194 }
4195
4196 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4197 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4198 if (TL.hasAttrOperand())
4199 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4200 if (TL.hasAttrExprOperand())
4201 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4202 else if (TL.hasAttrEnumOperand())
4203 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4204
4205 return result;
4206}
4207
4208template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004209QualType
4210TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4211 ParenTypeLoc TL) {
4212 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4213 if (Inner.isNull())
4214 return QualType();
4215
4216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
4218 Inner != TL.getInnerLoc().getType()) {
4219 Result = getDerived().RebuildParenType(Inner);
4220 if (Result.isNull())
4221 return QualType();
4222 }
4223
4224 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4225 NewTL.setLParenLoc(TL.getLParenLoc());
4226 NewTL.setRParenLoc(TL.getRParenLoc());
4227 return Result;
4228}
4229
4230template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004231QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004232 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00004233 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004234
Douglas Gregor577f75a2009-08-04 16:50:30 +00004235 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004236 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004237 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004238 if (!NNS)
4239 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004240
John McCall33500952010-06-11 00:33:02 +00004241 QualType Result
4242 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4243 T->getIdentifier(),
4244 TL.getKeywordLoc(),
4245 TL.getQualifierRange(),
4246 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004247 if (Result.isNull())
4248 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004249
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004250 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4251 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004252 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4253
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004254 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4255 NewTL.setKeywordLoc(TL.getKeywordLoc());
4256 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004257 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004258 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4259 NewTL.setKeywordLoc(TL.getKeywordLoc());
4260 NewTL.setQualifierRange(TL.getQualifierRange());
4261 NewTL.setNameLoc(TL.getNameLoc());
4262 }
John McCalla2becad2009-10-21 00:40:46 +00004263 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004264}
Mike Stump1eb44332009-09-09 15:08:12 +00004265
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004267QualType TreeTransform<Derived>::
4268 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004269 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00004270 DependentTemplateSpecializationType *T = TL.getTypePtr();
4271
4272 NestedNameSpecifier *NNS
4273 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004274 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004275 if (!NNS)
4276 return QualType();
4277
John McCall43fed0d2010-11-12 08:19:04 +00004278 return getDerived()
4279 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4280}
4281
4282template<typename Derived>
4283QualType TreeTransform<Derived>::
4284 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4285 DependentTemplateSpecializationTypeLoc TL,
4286 NestedNameSpecifier *NNS) {
4287 DependentTemplateSpecializationType *T = TL.getTypePtr();
4288
John McCall33500952010-06-11 00:33:02 +00004289 TemplateArgumentListInfo NewTemplateArgs;
4290 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4291 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004292
4293 typedef TemplateArgumentLocContainerIterator<
4294 DependentTemplateSpecializationTypeLoc> ArgIterator;
4295 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4296 ArgIterator(TL, TL.getNumArgs()),
4297 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004298 return QualType();
John McCall33500952010-06-11 00:33:02 +00004299
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004300 QualType Result
4301 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4302 NNS,
4303 TL.getQualifierRange(),
4304 T->getIdentifier(),
4305 TL.getNameLoc(),
4306 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004307 if (Result.isNull())
4308 return QualType();
4309
4310 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4311 QualType NamedT = ElabT->getNamedType();
4312
4313 // Copy information relevant to the template specialization.
4314 TemplateSpecializationTypeLoc NamedTL
4315 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4316 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4317 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4318 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4319 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4320
4321 // Copy information relevant to the elaborated type.
4322 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4323 NewTL.setKeywordLoc(TL.getKeywordLoc());
4324 NewTL.setQualifierRange(TL.getQualifierRange());
4325 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004326 TypeLoc NewTL(Result, TL.getOpaqueData());
4327 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004328 }
4329 return Result;
4330}
4331
4332template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004333QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4334 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004335 QualType Pattern
4336 = getDerived().TransformType(TLB, TL.getPatternLoc());
4337 if (Pattern.isNull())
4338 return QualType();
4339
4340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() ||
4342 Pattern != TL.getPatternLoc().getType()) {
4343 Result = getDerived().RebuildPackExpansionType(Pattern,
4344 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004345 TL.getEllipsisLoc(),
4346 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004347 if (Result.isNull())
4348 return QualType();
4349 }
4350
4351 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4352 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4353 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004354}
4355
4356template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004357QualType
4358TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004359 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004360 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004361 TLB.pushFullCopy(TL);
4362 return TL.getType();
4363}
4364
4365template<typename Derived>
4366QualType
4367TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004368 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004369 // ObjCObjectType is never dependent.
4370 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004371 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004372}
Mike Stump1eb44332009-09-09 15:08:12 +00004373
4374template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004375QualType
4376TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004377 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004378 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004379 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004380 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004381}
4382
Douglas Gregor577f75a2009-08-04 16:50:30 +00004383//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004384// Statement transformation
4385//===----------------------------------------------------------------------===//
4386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004387StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004388TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004389 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004390}
4391
4392template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004393StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004394TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4395 return getDerived().TransformCompoundStmt(S, false);
4396}
4397
4398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004399StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004400TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004401 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004402 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004403 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004404 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004405 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4406 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004407 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004408 if (Result.isInvalid()) {
4409 // Immediately fail if this was a DeclStmt, since it's very
4410 // likely that this will cause problems for future statements.
4411 if (isa<DeclStmt>(*B))
4412 return StmtError();
4413
4414 // Otherwise, just keep processing substatements and fail later.
4415 SubStmtInvalid = true;
4416 continue;
4417 }
Mike Stump1eb44332009-09-09 15:08:12 +00004418
Douglas Gregor43959a92009-08-20 07:17:43 +00004419 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4420 Statements.push_back(Result.takeAs<Stmt>());
4421 }
Mike Stump1eb44332009-09-09 15:08:12 +00004422
John McCall7114cba2010-08-27 19:56:05 +00004423 if (SubStmtInvalid)
4424 return StmtError();
4425
Douglas Gregor43959a92009-08-20 07:17:43 +00004426 if (!getDerived().AlwaysRebuild() &&
4427 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004428 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004429
4430 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4431 move_arg(Statements),
4432 S->getRBracLoc(),
4433 IsStmtExpr);
4434}
Mike Stump1eb44332009-09-09 15:08:12 +00004435
Douglas Gregor43959a92009-08-20 07:17:43 +00004436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004437StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004438TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004439 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004440 {
4441 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004442 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004443
Eli Friedman264c1f82009-11-19 03:14:00 +00004444 // Transform the left-hand case value.
4445 LHS = getDerived().TransformExpr(S->getLHS());
4446 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004447 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004448
Eli Friedman264c1f82009-11-19 03:14:00 +00004449 // Transform the right-hand case value (for the GNU case-range extension).
4450 RHS = getDerived().TransformExpr(S->getRHS());
4451 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004452 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004453 }
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregor43959a92009-08-20 07:17:43 +00004455 // Build the case statement.
4456 // Case statements are always rebuilt so that they will attached to their
4457 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004458 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004459 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004460 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004461 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004462 S->getColonLoc());
4463 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004464 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004465
Douglas Gregor43959a92009-08-20 07:17:43 +00004466 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004467 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004468 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004469 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004470
Douglas Gregor43959a92009-08-20 07:17:43 +00004471 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004472 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004473}
4474
4475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004476StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004477TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004478 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004479 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004480 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004481 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004482
Douglas Gregor43959a92009-08-20 07:17:43 +00004483 // Default statements are always rebuilt
4484 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004485 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004486}
Mike Stump1eb44332009-09-09 15:08:12 +00004487
Douglas Gregor43959a92009-08-20 07:17:43 +00004488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004489StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004490TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004491 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004492 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004493 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004494
Douglas Gregor43959a92009-08-20 07:17:43 +00004495 // FIXME: Pass the real colon location in.
4496 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4497 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004498 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004499}
Mike Stump1eb44332009-09-09 15:08:12 +00004500
Douglas Gregor43959a92009-08-20 07:17:43 +00004501template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004502StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004503TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004504 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004505 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004506 VarDecl *ConditionVar = 0;
4507 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004508 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004509 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004510 getDerived().TransformDefinition(
4511 S->getConditionVariable()->getLocation(),
4512 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004513 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004514 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004515 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004516 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004517
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004518 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004519 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004520
4521 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004522 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004523 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4524 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004525 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004526 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004527
John McCall9ae2f072010-08-23 23:25:46 +00004528 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004529 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004530 }
Sean Huntc3021132010-05-05 15:23:54 +00004531
John McCall9ae2f072010-08-23 23:25:46 +00004532 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4533 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004534 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004535
Douglas Gregor43959a92009-08-20 07:17:43 +00004536 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004537 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004538 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004539 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004540
Douglas Gregor43959a92009-08-20 07:17:43 +00004541 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004542 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004543 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004544 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004545
Douglas Gregor43959a92009-08-20 07:17:43 +00004546 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004547 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004548 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004549 Then.get() == S->getThen() &&
4550 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004551 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004552
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004553 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004554 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004555 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004556}
4557
4558template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004559StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004560TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004561 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004562 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004563 VarDecl *ConditionVar = 0;
4564 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004565 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004566 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004567 getDerived().TransformDefinition(
4568 S->getConditionVariable()->getLocation(),
4569 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004570 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004571 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004572 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004573 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004574
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004575 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004576 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004577 }
Mike Stump1eb44332009-09-09 15:08:12 +00004578
Douglas Gregor43959a92009-08-20 07:17:43 +00004579 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004580 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004581 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004582 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004583 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004584 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004585
Douglas Gregor43959a92009-08-20 07:17:43 +00004586 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004587 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004588 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004589 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004590
Douglas Gregor43959a92009-08-20 07:17:43 +00004591 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004592 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4593 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004594}
Mike Stump1eb44332009-09-09 15:08:12 +00004595
Douglas Gregor43959a92009-08-20 07:17:43 +00004596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004597StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004598TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004599 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004600 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004601 VarDecl *ConditionVar = 0;
4602 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004603 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004604 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004605 getDerived().TransformDefinition(
4606 S->getConditionVariable()->getLocation(),
4607 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004608 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004609 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004610 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004611 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004612
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004613 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004614 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004615
4616 if (S->getCond()) {
4617 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004618 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4619 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004620 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004621 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004622 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004623 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004624 }
Mike Stump1eb44332009-09-09 15:08:12 +00004625
John McCall9ae2f072010-08-23 23:25:46 +00004626 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4627 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004628 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004629
Douglas Gregor43959a92009-08-20 07:17:43 +00004630 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004631 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004632 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004633 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004634
Douglas Gregor43959a92009-08-20 07:17:43 +00004635 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004636 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004637 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004638 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004639 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004640
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004641 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004642 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004643}
Mike Stump1eb44332009-09-09 15:08:12 +00004644
Douglas Gregor43959a92009-08-20 07:17:43 +00004645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004646StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004647TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004648 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004649 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004650 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004651 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004652
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004653 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004654 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004655 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004656 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004657
Douglas Gregor43959a92009-08-20 07:17:43 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 Cond.get() == S->getCond() &&
4660 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004661 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004662
John McCall9ae2f072010-08-23 23:25:46 +00004663 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4664 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004665 S->getRParenLoc());
4666}
Mike Stump1eb44332009-09-09 15:08:12 +00004667
Douglas Gregor43959a92009-08-20 07:17:43 +00004668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004669StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004670TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004671 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004672 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004673 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004674 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregor43959a92009-08-20 07:17:43 +00004676 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004677 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004678 VarDecl *ConditionVar = 0;
4679 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004680 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004681 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004682 getDerived().TransformDefinition(
4683 S->getConditionVariable()->getLocation(),
4684 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004685 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004686 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004687 } else {
4688 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004689
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004690 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004691 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004692
4693 if (S->getCond()) {
4694 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004695 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4696 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004697 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004698 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004699
John McCall9ae2f072010-08-23 23:25:46 +00004700 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004701 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004702 }
Mike Stump1eb44332009-09-09 15:08:12 +00004703
John McCall9ae2f072010-08-23 23:25:46 +00004704 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4705 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004706 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004707
Douglas Gregor43959a92009-08-20 07:17:43 +00004708 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004709 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004710 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004711 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004712
John McCall9ae2f072010-08-23 23:25:46 +00004713 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4714 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004715 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004716
Douglas Gregor43959a92009-08-20 07:17:43 +00004717 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004718 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004719 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004720 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004721
Douglas Gregor43959a92009-08-20 07:17:43 +00004722 if (!getDerived().AlwaysRebuild() &&
4723 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004724 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004725 Inc.get() == S->getInc() &&
4726 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004727 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004728
Douglas Gregor43959a92009-08-20 07:17:43 +00004729 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004730 Init.get(), FullCond, ConditionVar,
4731 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004732}
4733
4734template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004735StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004736TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004737 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004738 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004739 S->getLabel());
4740}
4741
4742template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004743StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004744TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004745 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004746 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004747 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004748
Douglas Gregor43959a92009-08-20 07:17:43 +00004749 if (!getDerived().AlwaysRebuild() &&
4750 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004751 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004752
4753 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004754 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004755}
4756
4757template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004758StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004759TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004760 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004761}
Mike Stump1eb44332009-09-09 15:08:12 +00004762
Douglas Gregor43959a92009-08-20 07:17:43 +00004763template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004764StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004765TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004766 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004767}
Mike Stump1eb44332009-09-09 15:08:12 +00004768
Douglas Gregor43959a92009-08-20 07:17:43 +00004769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004770StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004771TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004772 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004773 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004774 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004775
Mike Stump1eb44332009-09-09 15:08:12 +00004776 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004777 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004778 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004779}
Mike Stump1eb44332009-09-09 15:08:12 +00004780
Douglas Gregor43959a92009-08-20 07:17:43 +00004781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004782StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004783TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004784 bool DeclChanged = false;
4785 llvm::SmallVector<Decl *, 4> Decls;
4786 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4787 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004788 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4789 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004790 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004791 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004792
Douglas Gregor43959a92009-08-20 07:17:43 +00004793 if (Transformed != *D)
4794 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004795
Douglas Gregor43959a92009-08-20 07:17:43 +00004796 Decls.push_back(Transformed);
4797 }
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregor43959a92009-08-20 07:17:43 +00004799 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004800 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004801
4802 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004803 S->getStartLoc(), S->getEndLoc());
4804}
Mike Stump1eb44332009-09-09 15:08:12 +00004805
Douglas Gregor43959a92009-08-20 07:17:43 +00004806template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004807StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004808TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004809 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004810 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004811}
4812
4813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004814StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004815TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004816
John McCallca0408f2010-08-23 06:44:23 +00004817 ASTOwningVector<Expr*> Constraints(getSema());
4818 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004819 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004820
John McCall60d7b3a2010-08-24 06:29:42 +00004821 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004822 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004823
4824 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004825
Anders Carlsson703e3942010-01-24 05:50:09 +00004826 // Go through the outputs.
4827 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004828 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004829
Anders Carlsson703e3942010-01-24 05:50:09 +00004830 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004831 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004832
Anders Carlsson703e3942010-01-24 05:50:09 +00004833 // Transform the output expr.
4834 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004835 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004836 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004837 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004838
Anders Carlsson703e3942010-01-24 05:50:09 +00004839 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004840
John McCall9ae2f072010-08-23 23:25:46 +00004841 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004842 }
Sean Huntc3021132010-05-05 15:23:54 +00004843
Anders Carlsson703e3942010-01-24 05:50:09 +00004844 // Go through the inputs.
4845 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004846 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004847
Anders Carlsson703e3942010-01-24 05:50:09 +00004848 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004849 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004850
Anders Carlsson703e3942010-01-24 05:50:09 +00004851 // Transform the input expr.
4852 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004853 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004854 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004855 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004856
Anders Carlsson703e3942010-01-24 05:50:09 +00004857 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004858
John McCall9ae2f072010-08-23 23:25:46 +00004859 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004860 }
Sean Huntc3021132010-05-05 15:23:54 +00004861
Anders Carlsson703e3942010-01-24 05:50:09 +00004862 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004863 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004864
4865 // Go through the clobbers.
4866 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004867 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004868
4869 // No need to transform the asm string literal.
4870 AsmString = SemaRef.Owned(S->getAsmString());
4871
4872 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4873 S->isSimple(),
4874 S->isVolatile(),
4875 S->getNumOutputs(),
4876 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004877 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004878 move_arg(Constraints),
4879 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004880 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004881 move_arg(Clobbers),
4882 S->getRParenLoc(),
4883 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004884}
4885
4886
4887template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004888StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004889TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004890 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004891 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004892 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004893 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004894
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004895 // Transform the @catch statements (if present).
4896 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004897 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004898 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004899 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004900 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004901 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004902 if (Catch.get() != S->getCatchStmt(I))
4903 AnyCatchChanged = true;
4904 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004905 }
Sean Huntc3021132010-05-05 15:23:54 +00004906
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004907 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004908 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004909 if (S->getFinallyStmt()) {
4910 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4911 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004912 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004913 }
4914
4915 // If nothing changed, just retain this statement.
4916 if (!getDerived().AlwaysRebuild() &&
4917 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004918 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004919 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004920 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004921
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004922 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004923 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4924 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004925}
Mike Stump1eb44332009-09-09 15:08:12 +00004926
Douglas Gregor43959a92009-08-20 07:17:43 +00004927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004928StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004929TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004930 // Transform the @catch parameter, if there is one.
4931 VarDecl *Var = 0;
4932 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4933 TypeSourceInfo *TSInfo = 0;
4934 if (FromVar->getTypeSourceInfo()) {
4935 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4936 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004937 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004938 }
Sean Huntc3021132010-05-05 15:23:54 +00004939
Douglas Gregorbe270a02010-04-26 17:57:08 +00004940 QualType T;
4941 if (TSInfo)
4942 T = TSInfo->getType();
4943 else {
4944 T = getDerived().TransformType(FromVar->getType());
4945 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004946 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004947 }
Sean Huntc3021132010-05-05 15:23:54 +00004948
Douglas Gregorbe270a02010-04-26 17:57:08 +00004949 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4950 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004951 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004952 }
Sean Huntc3021132010-05-05 15:23:54 +00004953
John McCall60d7b3a2010-08-24 06:29:42 +00004954 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004955 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004956 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004957
4958 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004959 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004960 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004961}
Mike Stump1eb44332009-09-09 15:08:12 +00004962
Douglas Gregor43959a92009-08-20 07:17:43 +00004963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004964StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004965TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004966 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004967 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004968 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004969 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004970
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004971 // If nothing changed, just retain this statement.
4972 if (!getDerived().AlwaysRebuild() &&
4973 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004974 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004975
4976 // Build a new statement.
4977 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004978 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004979}
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregor43959a92009-08-20 07:17:43 +00004981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004982StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004983TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004984 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004985 if (S->getThrowExpr()) {
4986 Operand = getDerived().TransformExpr(S->getThrowExpr());
4987 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004988 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004989 }
Sean Huntc3021132010-05-05 15:23:54 +00004990
Douglas Gregord1377b22010-04-22 21:44:01 +00004991 if (!getDerived().AlwaysRebuild() &&
4992 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004993 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004994
John McCall9ae2f072010-08-23 23:25:46 +00004995 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004996}
Mike Stump1eb44332009-09-09 15:08:12 +00004997
Douglas Gregor43959a92009-08-20 07:17:43 +00004998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004999StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005000TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005001 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005002 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005003 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005004 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005005 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005006
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005007 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005008 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005009 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005010 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005011
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005012 // If nothing change, just retain the current statement.
5013 if (!getDerived().AlwaysRebuild() &&
5014 Object.get() == S->getSynchExpr() &&
5015 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005016 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005017
5018 // Build a new statement.
5019 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005020 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005021}
5022
5023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005024StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005025TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005026 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005027 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005028 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005029 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005030 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005031
Douglas Gregorc3203e72010-04-22 23:10:45 +00005032 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005033 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005034 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005035 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005036
Douglas Gregorc3203e72010-04-22 23:10:45 +00005037 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005038 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005039 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005040 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005041
Douglas Gregorc3203e72010-04-22 23:10:45 +00005042 // If nothing changed, just retain this statement.
5043 if (!getDerived().AlwaysRebuild() &&
5044 Element.get() == S->getElement() &&
5045 Collection.get() == S->getCollection() &&
5046 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005047 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005048
Douglas Gregorc3203e72010-04-22 23:10:45 +00005049 // Build a new statement.
5050 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5051 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005052 Element.get(),
5053 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005054 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005055 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005056}
5057
5058
5059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005060StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005061TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5062 // Transform the exception declaration, if any.
5063 VarDecl *Var = 0;
5064 if (S->getExceptionDecl()) {
5065 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005066 TypeSourceInfo *T = getDerived().TransformType(
5067 ExceptionDecl->getTypeSourceInfo());
5068 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005069 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005070
Douglas Gregor83cb9422010-09-09 17:09:21 +00005071 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005072 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005073 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005074 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005075 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005076 }
Mike Stump1eb44332009-09-09 15:08:12 +00005077
Douglas Gregor43959a92009-08-20 07:17:43 +00005078 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005079 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005080 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005081 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregor43959a92009-08-20 07:17:43 +00005083 if (!getDerived().AlwaysRebuild() &&
5084 !Var &&
5085 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005086 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005087
5088 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5089 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005090 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005091}
Mike Stump1eb44332009-09-09 15:08:12 +00005092
Douglas Gregor43959a92009-08-20 07:17:43 +00005093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005094StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005095TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5096 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005097 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 = getDerived().TransformCompoundStmt(S->getTryBlock());
5099 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005100 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005101
Douglas Gregor43959a92009-08-20 07:17:43 +00005102 // Transform the handlers.
5103 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005104 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005105 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005106 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005107 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5108 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005109 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregor43959a92009-08-20 07:17:43 +00005111 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5112 Handlers.push_back(Handler.takeAs<Stmt>());
5113 }
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 if (!getDerived().AlwaysRebuild() &&
5116 TryBlock.get() == S->getTryBlock() &&
5117 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005118 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005119
John McCall9ae2f072010-08-23 23:25:46 +00005120 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005121 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005122}
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005125// Expression transformation
5126//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005128ExprResult
John McCall454feb92009-12-08 09:21:05 +00005129TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005130 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005131}
Mike Stump1eb44332009-09-09 15:08:12 +00005132
5133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134ExprResult
John McCall454feb92009-12-08 09:21:05 +00005135TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005136 NestedNameSpecifier *Qualifier = 0;
5137 if (E->getQualifier()) {
5138 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005139 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005140 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005141 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005142 }
John McCalldbd872f2009-12-08 09:08:17 +00005143
5144 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005145 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5146 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005147 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005148 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005149
John McCallec8045d2010-08-17 21:27:17 +00005150 DeclarationNameInfo NameInfo = E->getNameInfo();
5151 if (NameInfo.getName()) {
5152 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5153 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005154 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005155 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005156
5157 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005158 Qualifier == E->getQualifier() &&
5159 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005160 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005161 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005162
5163 // Mark it referenced in the new context regardless.
5164 // FIXME: this is a bit instantiation-specific.
5165 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5166
John McCall3fa5cae2010-10-26 07:05:15 +00005167 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005168 }
John McCalldbd872f2009-12-08 09:08:17 +00005169
5170 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005171 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005172 TemplateArgs = &TransArgs;
5173 TransArgs.setLAngleLoc(E->getLAngleLoc());
5174 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005175 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5176 E->getNumTemplateArgs(),
5177 TransArgs))
5178 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005179 }
5180
Douglas Gregora2813ce2009-10-23 18:54:35 +00005181 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005182 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005183}
Mike Stump1eb44332009-09-09 15:08:12 +00005184
Douglas Gregorb98b1992009-08-11 05:31:07 +00005185template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005186ExprResult
John McCall454feb92009-12-08 09:21:05 +00005187TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005188 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005189}
Mike Stump1eb44332009-09-09 15:08:12 +00005190
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005192ExprResult
John McCall454feb92009-12-08 09:21:05 +00005193TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005194 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005195}
Mike Stump1eb44332009-09-09 15:08:12 +00005196
Douglas Gregorb98b1992009-08-11 05:31:07 +00005197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005198ExprResult
John McCall454feb92009-12-08 09:21:05 +00005199TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005200 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005201}
Mike Stump1eb44332009-09-09 15:08:12 +00005202
Douglas Gregorb98b1992009-08-11 05:31:07 +00005203template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005204ExprResult
John McCall454feb92009-12-08 09:21:05 +00005205TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005206 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005207}
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005210ExprResult
John McCall454feb92009-12-08 09:21:05 +00005211TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005212 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005213}
5214
5215template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005216ExprResult
John McCall454feb92009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005218 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005219 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005220 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005221
Douglas Gregorb98b1992009-08-11 05:31:07 +00005222 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005224
John McCall9ae2f072010-08-23 23:25:46 +00005225 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005226 E->getRParen());
5227}
5228
Mike Stump1eb44332009-09-09 15:08:12 +00005229template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005230ExprResult
John McCall454feb92009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005232 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005234 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005235
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005237 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5240 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005241 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005242}
Mike Stump1eb44332009-09-09 15:08:12 +00005243
Douglas Gregorb98b1992009-08-11 05:31:07 +00005244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005245ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005246TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5247 // Transform the type.
5248 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5249 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005250 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005251
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005252 // Transform all of the components into components similar to what the
5253 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005254 // FIXME: It would be slightly more efficient in the non-dependent case to
5255 // just map FieldDecls, rather than requiring the rebuilder to look for
5256 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005257 // template code that we don't care.
5258 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005259 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005260 typedef OffsetOfExpr::OffsetOfNode Node;
5261 llvm::SmallVector<Component, 4> Components;
5262 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5263 const Node &ON = E->getComponent(I);
5264 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005265 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005266 Comp.LocStart = ON.getRange().getBegin();
5267 Comp.LocEnd = ON.getRange().getEnd();
5268 switch (ON.getKind()) {
5269 case Node::Array: {
5270 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005271 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005272 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005273 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005274
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005275 ExprChanged = ExprChanged || Index.get() != FromIndex;
5276 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005277 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005278 break;
5279 }
Sean Huntc3021132010-05-05 15:23:54 +00005280
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005281 case Node::Field:
5282 case Node::Identifier:
5283 Comp.isBrackets = false;
5284 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005285 if (!Comp.U.IdentInfo)
5286 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005287
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005288 break;
Sean Huntc3021132010-05-05 15:23:54 +00005289
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005290 case Node::Base:
5291 // Will be recomputed during the rebuild.
5292 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005293 }
Sean Huntc3021132010-05-05 15:23:54 +00005294
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005295 Components.push_back(Comp);
5296 }
Sean Huntc3021132010-05-05 15:23:54 +00005297
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005298 // If nothing changed, retain the existing expression.
5299 if (!getDerived().AlwaysRebuild() &&
5300 Type == E->getTypeSourceInfo() &&
5301 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005302 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005303
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005304 // Build a new offsetof expression.
5305 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5306 Components.data(), Components.size(),
5307 E->getRParenLoc());
5308}
5309
5310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005311ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005312TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5313 assert(getDerived().AlreadyTransformed(E->getType()) &&
5314 "opaque value expression requires transformation");
5315 return SemaRef.Owned(E);
5316}
5317
5318template<typename Derived>
5319ExprResult
John McCall454feb92009-12-08 09:21:05 +00005320TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005321 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005322 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005323
John McCalla93c9342009-12-07 02:54:59 +00005324 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005325 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005326 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005327
John McCall5ab75172009-11-04 07:28:41 +00005328 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005329 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005330
John McCall5ab75172009-11-04 07:28:41 +00005331 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005332 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005333 E->getSourceRange());
5334 }
Mike Stump1eb44332009-09-09 15:08:12 +00005335
John McCall60d7b3a2010-08-24 06:29:42 +00005336 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005337 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005338 // C++0x [expr.sizeof]p1:
5339 // The operand is either an expression, which is an unevaluated operand
5340 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Douglas Gregorb98b1992009-08-11 05:31:07 +00005343 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5344 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005346
Douglas Gregorb98b1992009-08-11 05:31:07 +00005347 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005348 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005349 }
Mike Stump1eb44332009-09-09 15:08:12 +00005350
John McCall9ae2f072010-08-23 23:25:46 +00005351 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005352 E->isSizeOf(),
5353 E->getSourceRange());
5354}
Mike Stump1eb44332009-09-09 15:08:12 +00005355
Douglas Gregorb98b1992009-08-11 05:31:07 +00005356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005357ExprResult
John McCall454feb92009-12-08 09:21:05 +00005358TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005359 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005360 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005361 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005362
John McCall60d7b3a2010-08-24 06:29:42 +00005363 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005364 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005365 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005366
5367
Douglas Gregorb98b1992009-08-11 05:31:07 +00005368 if (!getDerived().AlwaysRebuild() &&
5369 LHS.get() == E->getLHS() &&
5370 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005371 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005372
John McCall9ae2f072010-08-23 23:25:46 +00005373 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005374 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005375 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005376 E->getRBracketLoc());
5377}
Mike Stump1eb44332009-09-09 15:08:12 +00005378
5379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005380ExprResult
John McCall454feb92009-12-08 09:21:05 +00005381TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005383 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005384 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005385 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005386
5387 // Transform arguments.
5388 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005389 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005390 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5391 &ArgChanged))
5392 return ExprError();
5393
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394 if (!getDerived().AlwaysRebuild() &&
5395 Callee.get() == E->getCallee() &&
5396 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005397 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005398
Douglas Gregorb98b1992009-08-11 05:31:07 +00005399 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005400 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005401 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005402 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005403 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005404 E->getRParenLoc());
5405}
Mike Stump1eb44332009-09-09 15:08:12 +00005406
5407template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005408ExprResult
John McCall454feb92009-12-08 09:21:05 +00005409TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005410 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005411 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005412 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005413
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005414 NestedNameSpecifier *Qualifier = 0;
5415 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005416 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005417 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005418 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005419 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005420 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005421 }
Mike Stump1eb44332009-09-09 15:08:12 +00005422
Eli Friedmanf595cc42009-12-04 06:40:45 +00005423 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005424 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5425 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005426 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005427 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005428
John McCall6bb80172010-03-30 21:47:33 +00005429 NamedDecl *FoundDecl = E->getFoundDecl();
5430 if (FoundDecl == E->getMemberDecl()) {
5431 FoundDecl = Member;
5432 } else {
5433 FoundDecl = cast_or_null<NamedDecl>(
5434 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5435 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005436 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005437 }
5438
Douglas Gregorb98b1992009-08-11 05:31:07 +00005439 if (!getDerived().AlwaysRebuild() &&
5440 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005441 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005442 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005443 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005444 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005445
Anders Carlsson1f240322009-12-22 05:24:09 +00005446 // Mark it referenced in the new context regardless.
5447 // FIXME: this is a bit instantiation-specific.
5448 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005449 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005450 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451
John McCalld5532b62009-11-23 01:53:49 +00005452 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005453 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005454 TransArgs.setLAngleLoc(E->getLAngleLoc());
5455 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005456 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5457 E->getNumTemplateArgs(),
5458 TransArgs))
5459 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005460 }
Sean Huntc3021132010-05-05 15:23:54 +00005461
Douglas Gregorb98b1992009-08-11 05:31:07 +00005462 // FIXME: Bogus source location for the operator
5463 SourceLocation FakeOperatorLoc
5464 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5465
John McCallc2233c52010-01-15 08:34:02 +00005466 // FIXME: to do this check properly, we will need to preserve the
5467 // first-qualifier-in-scope here, just in case we had a dependent
5468 // base (and therefore couldn't do the check) and a
5469 // nested-name-qualifier (and therefore could do the lookup).
5470 NamedDecl *FirstQualifierInScope = 0;
5471
John McCall9ae2f072010-08-23 23:25:46 +00005472 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005473 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005474 Qualifier,
5475 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005476 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005477 Member,
John McCall6bb80172010-03-30 21:47:33 +00005478 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005479 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005480 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005481 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005482}
Mike Stump1eb44332009-09-09 15:08:12 +00005483
Douglas Gregorb98b1992009-08-11 05:31:07 +00005484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005485ExprResult
John McCall454feb92009-12-08 09:21:05 +00005486TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005487 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005488 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005490
John McCall60d7b3a2010-08-24 06:29:42 +00005491 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005492 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregorb98b1992009-08-11 05:31:07 +00005495 if (!getDerived().AlwaysRebuild() &&
5496 LHS.get() == E->getLHS() &&
5497 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005499
Douglas Gregorb98b1992009-08-11 05:31:07 +00005500 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005501 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005502}
5503
Mike Stump1eb44332009-09-09 15:08:12 +00005504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005505ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005506TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005507 CompoundAssignOperator *E) {
5508 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509}
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregorb98b1992009-08-11 05:31:07 +00005511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512ExprResult
John McCall454feb92009-12-08 09:21:05 +00005513TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005514 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005517
John McCall60d7b3a2010-08-24 06:29:42 +00005518 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005519 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005520 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005521
John McCall60d7b3a2010-08-24 06:29:42 +00005522 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005523 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005524 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregorb98b1992009-08-11 05:31:07 +00005526 if (!getDerived().AlwaysRebuild() &&
5527 Cond.get() == E->getCond() &&
5528 LHS.get() == E->getLHS() &&
5529 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005530 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005531
John McCall9ae2f072010-08-23 23:25:46 +00005532 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005533 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005534 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005535 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005536 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005537}
Mike Stump1eb44332009-09-09 15:08:12 +00005538
5539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005540ExprResult
John McCall454feb92009-12-08 09:21:05 +00005541TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005542 // Implicit casts are eliminated during transformation, since they
5543 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005544 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545}
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregorb98b1992009-08-11 05:31:07 +00005547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005548ExprResult
John McCall454feb92009-12-08 09:21:05 +00005549TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005550 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5551 if (!Type)
5552 return ExprError();
5553
John McCall60d7b3a2010-08-24 06:29:42 +00005554 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005555 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005558
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005560 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005562 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005563
John McCall9d125032010-01-15 18:39:57 +00005564 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005565 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005566 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005567 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005568}
Mike Stump1eb44332009-09-09 15:08:12 +00005569
Douglas Gregorb98b1992009-08-11 05:31:07 +00005570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005571ExprResult
John McCall454feb92009-12-08 09:21:05 +00005572TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005573 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5574 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5575 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005576 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005577
John McCall60d7b3a2010-08-24 06:29:42 +00005578 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005579 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005581
Douglas Gregorb98b1992009-08-11 05:31:07 +00005582 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005583 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005584 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005585 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005586
John McCall1d7d8d62010-01-19 22:33:45 +00005587 // Note: the expression type doesn't necessarily match the
5588 // type-as-written, but that's okay, because it should always be
5589 // derivable from the initializer.
5590
John McCall42f56b52010-01-18 19:35:47 +00005591 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005592 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005593 Init.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>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005599 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005600 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005601 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005602
Douglas Gregorb98b1992009-08-11 05:31:07 +00005603 if (!getDerived().AlwaysRebuild() &&
5604 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005605 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005606
Douglas Gregorb98b1992009-08-11 05:31:07 +00005607 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005608 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005609 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005610 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005611 E->getAccessorLoc(),
5612 E->getAccessor());
5613}
Mike Stump1eb44332009-09-09 15:08:12 +00005614
Douglas Gregorb98b1992009-08-11 05:31:07 +00005615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616ExprResult
John McCall454feb92009-12-08 09:21:05 +00005617TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005618 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005619
John McCallca0408f2010-08-23 06:44:23 +00005620 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005621 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5622 Inits, &InitChanged))
5623 return ExprError();
5624
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005626 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005627
Douglas Gregorb98b1992009-08-11 05:31:07 +00005628 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005629 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005630}
Mike Stump1eb44332009-09-09 15:08:12 +00005631
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005633ExprResult
John McCall454feb92009-12-08 09:21:05 +00005634TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005636
Douglas Gregor43959a92009-08-20 07:17:43 +00005637 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005638 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005639 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005640 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005641
Douglas Gregor43959a92009-08-20 07:17:43 +00005642 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005643 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 bool ExprChanged = false;
5645 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5646 DEnd = E->designators_end();
5647 D != DEnd; ++D) {
5648 if (D->isFieldDesignator()) {
5649 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5650 D->getDotLoc(),
5651 D->getFieldLoc()));
5652 continue;
5653 }
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregorb98b1992009-08-11 05:31:07 +00005655 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005656 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005657 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005659
5660 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005662
Douglas Gregorb98b1992009-08-11 05:31:07 +00005663 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5664 ArrayExprs.push_back(Index.release());
5665 continue;
5666 }
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregorb98b1992009-08-11 05:31:07 +00005668 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005669 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5671 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005672 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005673
John McCall60d7b3a2010-08-24 06:29:42 +00005674 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005675 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005676 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005677
5678 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005679 End.get(),
5680 D->getLBracketLoc(),
5681 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005682
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5684 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005685
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 ArrayExprs.push_back(Start.release());
5687 ArrayExprs.push_back(End.release());
5688 }
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregorb98b1992009-08-11 05:31:07 +00005690 if (!getDerived().AlwaysRebuild() &&
5691 Init.get() == E->getInit() &&
5692 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005693 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005694
Douglas Gregorb98b1992009-08-11 05:31:07 +00005695 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5696 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005697 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005698}
Mike Stump1eb44332009-09-09 15:08:12 +00005699
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005701ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005703 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005704 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005705
Douglas Gregor5557b252009-10-28 00:29:27 +00005706 // FIXME: Will we ever have proper type location here? Will we actually
5707 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708 QualType T = getDerived().TransformType(E->getType());
5709 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005710 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005711
Douglas Gregorb98b1992009-08-11 05:31:07 +00005712 if (!getDerived().AlwaysRebuild() &&
5713 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005714 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005715
Douglas Gregorb98b1992009-08-11 05:31:07 +00005716 return getDerived().RebuildImplicitValueInitExpr(T);
5717}
Mike Stump1eb44332009-09-09 15:08:12 +00005718
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005720ExprResult
John McCall454feb92009-12-08 09:21:05 +00005721TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005722 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5723 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005724 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005725
John McCall60d7b3a2010-08-24 06:29:42 +00005726 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005727 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005729
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005731 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005732 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005733 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005734
John McCall9ae2f072010-08-23 23:25:46 +00005735 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005736 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005737}
5738
5739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005740ExprResult
John McCall454feb92009-12-08 09:21:05 +00005741TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005743 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005744 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5745 &ArgumentChanged))
5746 return ExprError();
5747
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5749 move_arg(Inits),
5750 E->getRParenLoc());
5751}
Mike Stump1eb44332009-09-09 15:08:12 +00005752
Douglas Gregorb98b1992009-08-11 05:31:07 +00005753/// \brief Transform an address-of-label expression.
5754///
5755/// By default, the transformation of an address-of-label expression always
5756/// rebuilds the expression, so that the label identifier can be resolved to
5757/// the corresponding label statement by semantic analysis.
5758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005759ExprResult
John McCall454feb92009-12-08 09:21:05 +00005760TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005761 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5762 E->getLabel());
5763}
Mike Stump1eb44332009-09-09 15:08:12 +00005764
5765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005766ExprResult
John McCall454feb92009-12-08 09:21:05 +00005767TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005768 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005769 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5770 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005771 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005772
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773 if (!getDerived().AlwaysRebuild() &&
5774 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005775 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005776
5777 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005778 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779 E->getRParenLoc());
5780}
Mike Stump1eb44332009-09-09 15:08:12 +00005781
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005783ExprResult
John McCall454feb92009-12-08 09:21:05 +00005784TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005785 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005786 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005787 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005788
John McCall60d7b3a2010-08-24 06:29:42 +00005789 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005791 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005792
John McCall60d7b3a2010-08-24 06:29:42 +00005793 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005796
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797 if (!getDerived().AlwaysRebuild() &&
5798 Cond.get() == E->getCond() &&
5799 LHS.get() == E->getLHS() &&
5800 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005801 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005802
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005804 Cond.get(), LHS.get(), RHS.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>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005811 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812}
5813
5814template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005815ExprResult
John McCall454feb92009-12-08 09:21:05 +00005816TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005817 switch (E->getOperator()) {
5818 case OO_New:
5819 case OO_Delete:
5820 case OO_Array_New:
5821 case OO_Array_Delete:
5822 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005823 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005824
Douglas Gregor668d6d92009-12-13 20:44:55 +00005825 case OO_Call: {
5826 // This is a call to an object's operator().
5827 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5828
5829 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005830 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005831 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005832 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005833
5834 // FIXME: Poor location information
5835 SourceLocation FakeLParenLoc
5836 = SemaRef.PP.getLocForEndOfToken(
5837 static_cast<Expr *>(Object.get())->getLocEnd());
5838
5839 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005840 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005841 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5842 Args))
5843 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005844
John McCall9ae2f072010-08-23 23:25:46 +00005845 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005846 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005847 E->getLocEnd());
5848 }
5849
5850#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5851 case OO_##Name:
5852#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5853#include "clang/Basic/OperatorKinds.def"
5854 case OO_Subscript:
5855 // Handled below.
5856 break;
5857
5858 case OO_Conditional:
5859 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005860 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005861
5862 case OO_None:
5863 case NUM_OVERLOADED_OPERATORS:
5864 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005865 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005866 }
5867
John McCall60d7b3a2010-08-24 06:29:42 +00005868 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005869 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005870 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005871
John McCall60d7b3a2010-08-24 06:29:42 +00005872 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005873 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005874 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005875
John McCall60d7b3a2010-08-24 06:29:42 +00005876 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877 if (E->getNumArgs() == 2) {
5878 Second = getDerived().TransformExpr(E->getArg(1));
5879 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005880 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005881 }
Mike Stump1eb44332009-09-09 15:08:12 +00005882
Douglas Gregorb98b1992009-08-11 05:31:07 +00005883 if (!getDerived().AlwaysRebuild() &&
5884 Callee.get() == E->getCallee() &&
5885 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005886 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Douglas Gregorb98b1992009-08-11 05:31:07 +00005889 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5890 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005891 Callee.get(),
5892 First.get(),
5893 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894}
Mike Stump1eb44332009-09-09 15:08:12 +00005895
Douglas Gregorb98b1992009-08-11 05:31:07 +00005896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005897ExprResult
John McCall454feb92009-12-08 09:21:05 +00005898TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5899 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005900}
Mike Stump1eb44332009-09-09 15:08:12 +00005901
Douglas Gregorb98b1992009-08-11 05:31:07 +00005902template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005903ExprResult
John McCall454feb92009-12-08 09:21:05 +00005904TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005905 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5906 if (!Type)
5907 return ExprError();
5908
John McCall60d7b3a2010-08-24 06:29:42 +00005909 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005910 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005911 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005912 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005913
Douglas Gregorb98b1992009-08-11 05:31:07 +00005914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005915 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005916 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005917 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005918
Douglas Gregorb98b1992009-08-11 05:31:07 +00005919 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005920 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005921 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5922 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5923 SourceLocation FakeRParenLoc
5924 = SemaRef.PP.getLocForEndOfToken(
5925 E->getSubExpr()->getSourceRange().getEnd());
5926 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005927 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005928 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005929 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005930 FakeRAngleLoc,
5931 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005932 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933 FakeRParenLoc);
5934}
Mike Stump1eb44332009-09-09 15:08:12 +00005935
Douglas Gregorb98b1992009-08-11 05:31:07 +00005936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005937ExprResult
John McCall454feb92009-12-08 09:21:05 +00005938TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5939 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005940}
Mike Stump1eb44332009-09-09 15:08:12 +00005941
5942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005943ExprResult
John McCall454feb92009-12-08 09:21:05 +00005944TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5945 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005946}
5947
Douglas Gregorb98b1992009-08-11 05:31:07 +00005948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005949ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005951 CXXReinterpretCastExpr *E) {
5952 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005953}
Mike Stump1eb44332009-09-09 15:08:12 +00005954
Douglas Gregorb98b1992009-08-11 05:31:07 +00005955template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005956ExprResult
John McCall454feb92009-12-08 09:21:05 +00005957TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5958 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005959}
Mike Stump1eb44332009-09-09 15:08:12 +00005960
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005962ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005963TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005964 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005965 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5966 if (!Type)
5967 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005968
John McCall60d7b3a2010-08-24 06:29:42 +00005969 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005970 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005972 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005973
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005975 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005978
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005979 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005980 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005981 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005982 E->getRParenLoc());
5983}
Mike Stump1eb44332009-09-09 15:08:12 +00005984
Douglas Gregorb98b1992009-08-11 05:31:07 +00005985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005986ExprResult
John McCall454feb92009-12-08 09:21:05 +00005987TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005988 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005989 TypeSourceInfo *TInfo
5990 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5991 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005992 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005993
Douglas Gregorb98b1992009-08-11 05:31:07 +00005994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005995 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005997
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005998 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5999 E->getLocStart(),
6000 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001 E->getLocEnd());
6002 }
Mike Stump1eb44332009-09-09 15:08:12 +00006003
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004 // We don't know whether the expression is potentially evaluated until
6005 // after we perform semantic analysis, so the expression is potentially
6006 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006007 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006008 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006009
John McCall60d7b3a2010-08-24 06:29:42 +00006010 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006011 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006012 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006013
Douglas Gregorb98b1992009-08-11 05:31:07 +00006014 if (!getDerived().AlwaysRebuild() &&
6015 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006016 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006017
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006018 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6019 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006020 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006021 E->getLocEnd());
6022}
6023
6024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006025ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006026TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6027 if (E->isTypeOperand()) {
6028 TypeSourceInfo *TInfo
6029 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6030 if (!TInfo)
6031 return ExprError();
6032
6033 if (!getDerived().AlwaysRebuild() &&
6034 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006035 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006036
6037 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6038 E->getLocStart(),
6039 TInfo,
6040 E->getLocEnd());
6041 }
6042
6043 // We don't know whether the expression is potentially evaluated until
6044 // after we perform semantic analysis, so the expression is potentially
6045 // potentially evaluated.
6046 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6047
6048 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6049 if (SubExpr.isInvalid())
6050 return ExprError();
6051
6052 if (!getDerived().AlwaysRebuild() &&
6053 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006054 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006055
6056 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6057 E->getLocStart(),
6058 SubExpr.get(),
6059 E->getLocEnd());
6060}
6061
6062template<typename Derived>
6063ExprResult
John McCall454feb92009-12-08 09:21:05 +00006064TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006065 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066}
Mike Stump1eb44332009-09-09 15:08:12 +00006067
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006069ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006071 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006072 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073}
Mike Stump1eb44332009-09-09 15:08:12 +00006074
Douglas Gregorb98b1992009-08-11 05:31:07 +00006075template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006076ExprResult
John McCall454feb92009-12-08 09:21:05 +00006077TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006078 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6079 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6080 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006081
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006082 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006084
Douglas Gregor828a1972010-01-07 23:12:05 +00006085 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006086}
Mike Stump1eb44332009-09-09 15:08:12 +00006087
Douglas Gregorb98b1992009-08-11 05:31:07 +00006088template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006089ExprResult
John McCall454feb92009-12-08 09:21:05 +00006090TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006091 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006092 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006093 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006094
Douglas Gregorb98b1992009-08-11 05:31:07 +00006095 if (!getDerived().AlwaysRebuild() &&
6096 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006097 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006098
John McCall9ae2f072010-08-23 23:25:46 +00006099 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006100}
Mike Stump1eb44332009-09-09 15:08:12 +00006101
Douglas Gregorb98b1992009-08-11 05:31:07 +00006102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006103ExprResult
John McCall454feb92009-12-08 09:21:05 +00006104TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006105 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006106 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6107 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006109 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006110
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006111 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006113 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006114
Douglas Gregor036aed12009-12-23 23:03:06 +00006115 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116}
Mike Stump1eb44332009-09-09 15:08:12 +00006117
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006119ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006120TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6121 CXXScalarValueInitExpr *E) {
6122 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6123 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006124 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006125
Douglas Gregorb98b1992009-08-11 05:31:07 +00006126 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006127 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006128 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006129
Douglas Gregorab6677e2010-09-08 00:15:04 +00006130 return getDerived().RebuildCXXScalarValueInitExpr(T,
6131 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006132 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133}
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregorb98b1992009-08-11 05:31:07 +00006135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006136ExprResult
John McCall454feb92009-12-08 09:21:05 +00006137TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006139 TypeSourceInfo *AllocTypeInfo
6140 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6141 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006142 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006145 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006147 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006148
Douglas Gregorb98b1992009-08-11 05:31:07 +00006149 // Transform the placement arguments (if any).
6150 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006151 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006152 if (getDerived().TransformExprs(E->getPlacementArgs(),
6153 E->getNumPlacementArgs(), true,
6154 PlacementArgs, &ArgumentChanged))
6155 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006156
Douglas Gregor43959a92009-08-20 07:17:43 +00006157 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006158 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006159 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6160 ConstructorArgs, &ArgumentChanged))
6161 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006162
Douglas Gregor1af74512010-02-26 00:38:10 +00006163 // Transform constructor, new operator, and delete operator.
6164 CXXConstructorDecl *Constructor = 0;
6165 if (E->getConstructor()) {
6166 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006167 getDerived().TransformDecl(E->getLocStart(),
6168 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006169 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006170 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006171 }
6172
6173 FunctionDecl *OperatorNew = 0;
6174 if (E->getOperatorNew()) {
6175 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006176 getDerived().TransformDecl(E->getLocStart(),
6177 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006178 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006179 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006180 }
6181
6182 FunctionDecl *OperatorDelete = 0;
6183 if (E->getOperatorDelete()) {
6184 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006185 getDerived().TransformDecl(E->getLocStart(),
6186 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006187 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006188 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006189 }
Sean Huntc3021132010-05-05 15:23:54 +00006190
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006192 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006194 Constructor == E->getConstructor() &&
6195 OperatorNew == E->getOperatorNew() &&
6196 OperatorDelete == E->getOperatorDelete() &&
6197 !ArgumentChanged) {
6198 // Mark any declarations we need as referenced.
6199 // FIXME: instantiation-specific.
6200 if (Constructor)
6201 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6202 if (OperatorNew)
6203 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6204 if (OperatorDelete)
6205 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006206 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006207 }
Mike Stump1eb44332009-09-09 15:08:12 +00006208
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006209 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006210 if (!ArraySize.get()) {
6211 // If no array size was specified, but the new expression was
6212 // instantiated with an array type (e.g., "new T" where T is
6213 // instantiated with "int[4]"), extract the outer bound from the
6214 // array type as our array size. We do this with constant and
6215 // dependently-sized array types.
6216 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6217 if (!ArrayT) {
6218 // Do nothing
6219 } else if (const ConstantArrayType *ConsArrayT
6220 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006221 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006222 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6223 ConsArrayT->getSize(),
6224 SemaRef.Context.getSizeType(),
6225 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006226 AllocType = ConsArrayT->getElementType();
6227 } else if (const DependentSizedArrayType *DepArrayT
6228 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6229 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006230 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006231 AllocType = DepArrayT->getElementType();
6232 }
6233 }
6234 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006235
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6237 E->isGlobalNew(),
6238 /*FIXME:*/E->getLocStart(),
6239 move_arg(PlacementArgs),
6240 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006241 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006242 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006243 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006244 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245 /*FIXME:*/E->getLocStart(),
6246 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006247 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248}
Mike Stump1eb44332009-09-09 15:08:12 +00006249
Douglas Gregorb98b1992009-08-11 05:31:07 +00006250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006251ExprResult
John McCall454feb92009-12-08 09:21:05 +00006252TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006253 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006255 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006256
Douglas Gregor1af74512010-02-26 00:38:10 +00006257 // Transform the delete operator, if known.
6258 FunctionDecl *OperatorDelete = 0;
6259 if (E->getOperatorDelete()) {
6260 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006261 getDerived().TransformDecl(E->getLocStart(),
6262 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006263 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006264 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006265 }
Sean Huntc3021132010-05-05 15:23:54 +00006266
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006268 Operand.get() == E->getArgument() &&
6269 OperatorDelete == E->getOperatorDelete()) {
6270 // Mark any declarations we need as referenced.
6271 // FIXME: instantiation-specific.
6272 if (OperatorDelete)
6273 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006274
6275 if (!E->getArgument()->isTypeDependent()) {
6276 QualType Destroyed = SemaRef.Context.getBaseElementType(
6277 E->getDestroyedType());
6278 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6279 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6280 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6281 SemaRef.LookupDestructor(Record));
6282 }
6283 }
6284
John McCall3fa5cae2010-10-26 07:05:15 +00006285 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006286 }
Mike Stump1eb44332009-09-09 15:08:12 +00006287
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6289 E->isGlobalDelete(),
6290 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006291 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006292}
Mike Stump1eb44332009-09-09 15:08:12 +00006293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006295ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006296TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006297 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006298 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006299 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006300 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006301
John McCallb3d87482010-08-24 05:47:05 +00006302 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006303 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006304 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006305 E->getOperatorLoc(),
6306 E->isArrow()? tok::arrow : tok::period,
6307 ObjectTypePtr,
6308 MayBePseudoDestructor);
6309 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006310 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006311
John McCallb3d87482010-08-24 05:47:05 +00006312 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006313 NestedNameSpecifier *Qualifier = E->getQualifier();
6314 if (Qualifier) {
6315 Qualifier
6316 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6317 E->getQualifierRange(),
6318 ObjectType);
6319 if (!Qualifier)
6320 return ExprError();
6321 }
Mike Stump1eb44332009-09-09 15:08:12 +00006322
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006323 PseudoDestructorTypeStorage Destroyed;
6324 if (E->getDestroyedTypeInfo()) {
6325 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006326 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6327 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006328 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006329 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006330 Destroyed = DestroyedTypeInfo;
6331 } else if (ObjectType->isDependentType()) {
6332 // We aren't likely to be able to resolve the identifier down to a type
6333 // now anyway, so just retain the identifier.
6334 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6335 E->getDestroyedTypeLoc());
6336 } else {
6337 // Look for a destructor known with the given name.
6338 CXXScopeSpec SS;
6339 if (Qualifier) {
6340 SS.setScopeRep(Qualifier);
6341 SS.setRange(E->getQualifierRange());
6342 }
Sean Huntc3021132010-05-05 15:23:54 +00006343
John McCallb3d87482010-08-24 05:47:05 +00006344 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006345 *E->getDestroyedTypeIdentifier(),
6346 E->getDestroyedTypeLoc(),
6347 /*Scope=*/0,
6348 SS, ObjectTypePtr,
6349 false);
6350 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006351 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006352
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006353 Destroyed
6354 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6355 E->getDestroyedTypeLoc());
6356 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006357
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006358 TypeSourceInfo *ScopeTypeInfo = 0;
6359 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006360 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006361 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006362 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006363 }
Sean Huntc3021132010-05-05 15:23:54 +00006364
John McCall9ae2f072010-08-23 23:25:46 +00006365 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006366 E->getOperatorLoc(),
6367 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006368 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006369 E->getQualifierRange(),
6370 ScopeTypeInfo,
6371 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006372 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006373 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006374}
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Douglas Gregora71d8192009-09-04 17:36:40 +00006376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006377ExprResult
John McCallba135432009-11-21 08:51:07 +00006378TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006379 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006380 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6381
6382 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6383 Sema::LookupOrdinaryName);
6384
6385 // Transform all the decls.
6386 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6387 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006388 NamedDecl *InstD = static_cast<NamedDecl*>(
6389 getDerived().TransformDecl(Old->getNameLoc(),
6390 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006391 if (!InstD) {
6392 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6393 // This can happen because of dependent hiding.
6394 if (isa<UsingShadowDecl>(*I))
6395 continue;
6396 else
John McCallf312b1e2010-08-26 23:41:50 +00006397 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006398 }
John McCallf7a1a742009-11-24 19:00:30 +00006399
6400 // Expand using declarations.
6401 if (isa<UsingDecl>(InstD)) {
6402 UsingDecl *UD = cast<UsingDecl>(InstD);
6403 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6404 E = UD->shadow_end(); I != E; ++I)
6405 R.addDecl(*I);
6406 continue;
6407 }
6408
6409 R.addDecl(InstD);
6410 }
6411
6412 // Resolve a kind, but don't do any further analysis. If it's
6413 // ambiguous, the callee needs to deal with it.
6414 R.resolveKind();
6415
6416 // Rebuild the nested-name qualifier, if present.
6417 CXXScopeSpec SS;
6418 NestedNameSpecifier *Qualifier = 0;
6419 if (Old->getQualifier()) {
6420 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006421 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006422 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006423 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006424
John McCallf7a1a742009-11-24 19:00:30 +00006425 SS.setScopeRep(Qualifier);
6426 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006427 }
6428
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006429 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006430 CXXRecordDecl *NamingClass
6431 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6432 Old->getNameLoc(),
6433 Old->getNamingClass()));
6434 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006435 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006436
Douglas Gregor66c45152010-04-27 16:10:10 +00006437 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006438 }
6439
6440 // If we have no template arguments, it's a normal declaration name.
6441 if (!Old->hasExplicitTemplateArgs())
6442 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6443
6444 // If we have template arguments, rebuild them, then rebuild the
6445 // templateid expression.
6446 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006447 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6448 Old->getNumTemplateArgs(),
6449 TransArgs))
6450 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006451
6452 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6453 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454}
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006457ExprResult
John McCall454feb92009-12-08 09:21:05 +00006458TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006459 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6460 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006464 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006465 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006466
Mike Stump1eb44332009-09-09 15:08:12 +00006467 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006469 T,
6470 E->getLocEnd());
6471}
Mike Stump1eb44332009-09-09 15:08:12 +00006472
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006474ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006475TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6476 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6477 if (!LhsT)
6478 return ExprError();
6479
6480 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6481 if (!RhsT)
6482 return ExprError();
6483
6484 if (!getDerived().AlwaysRebuild() &&
6485 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6486 return SemaRef.Owned(E);
6487
6488 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6489 E->getLocStart(),
6490 LhsT, RhsT,
6491 E->getLocEnd());
6492}
6493
6494template<typename Derived>
6495ExprResult
John McCall865d4472009-11-19 22:55:06 +00006496TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006497 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006499 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006500 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006503
John McCall43fed0d2010-11-12 08:19:04 +00006504 // TODO: If this is a conversion-function-id, verify that the
6505 // destination type name (if present) resolves the same way after
6506 // instantiation as it did in the local scope.
6507
Abramo Bagnara25777432010-08-11 22:01:17 +00006508 DeclarationNameInfo NameInfo
6509 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6510 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006512
John McCallf7a1a742009-11-24 19:00:30 +00006513 if (!E->hasExplicitTemplateArgs()) {
6514 if (!getDerived().AlwaysRebuild() &&
6515 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006516 // Note: it is sufficient to compare the Name component of NameInfo:
6517 // if name has not changed, DNLoc has not changed either.
6518 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006519 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006520
John McCallf7a1a742009-11-24 19:00:30 +00006521 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6522 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006523 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006524 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006525 }
John McCalld5532b62009-11-23 01:53:49 +00006526
6527 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006528 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6529 E->getNumTemplateArgs(),
6530 TransArgs))
6531 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532
John McCallf7a1a742009-11-24 19:00:30 +00006533 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6534 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006535 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006536 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537}
6538
6539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006540ExprResult
John McCall454feb92009-12-08 09:21:05 +00006541TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006542 // CXXConstructExprs are always implicit, so when we have a
6543 // 1-argument construction we just transform that argument.
6544 if (E->getNumArgs() == 1 ||
6545 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6546 return getDerived().TransformExpr(E->getArg(0));
6547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6549
6550 QualType T = getDerived().TransformType(E->getType());
6551 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006552 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553
6554 CXXConstructorDecl *Constructor
6555 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006556 getDerived().TransformDecl(E->getLocStart(),
6557 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006560
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006562 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006563 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6564 &ArgumentChanged))
6565 return ExprError();
6566
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 if (!getDerived().AlwaysRebuild() &&
6568 T == E->getType() &&
6569 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006570 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006571 // Mark the constructor as referenced.
6572 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006573 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006574 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006575 }
Mike Stump1eb44332009-09-09 15:08:12 +00006576
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006577 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6578 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006579 move_arg(Args),
6580 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006581 E->getConstructionKind(),
6582 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583}
Mike Stump1eb44332009-09-09 15:08:12 +00006584
Douglas Gregorb98b1992009-08-11 05:31:07 +00006585/// \brief Transform a C++ temporary-binding expression.
6586///
Douglas Gregor51326552009-12-24 18:51:59 +00006587/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6588/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006590ExprResult
John McCall454feb92009-12-08 09:21:05 +00006591TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006592 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593}
Mike Stump1eb44332009-09-09 15:08:12 +00006594
John McCall4765fa02010-12-06 08:20:24 +00006595/// \brief Transform a C++ expression that contains cleanups that should
6596/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597///
John McCall4765fa02010-12-06 08:20:24 +00006598/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006599/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006601ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006602TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006603 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604}
Mike Stump1eb44332009-09-09 15:08:12 +00006605
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006607ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006609 CXXTemporaryObjectExpr *E) {
6610 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6611 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 CXXConstructorDecl *Constructor
6615 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006616 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006617 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006619 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006620
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006622 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006624 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6625 &ArgumentChanged))
6626 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006627
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006629 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006631 !ArgumentChanged) {
6632 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006633 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006634 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006635 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006636
6637 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6638 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 E->getLocEnd());
6641}
Mike Stump1eb44332009-09-09 15:08:12 +00006642
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006644ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006646 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006647 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6648 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006649 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006652 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006653 Args.reserve(E->arg_size());
6654 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6655 &ArgumentChanged))
6656 return ExprError();
6657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006659 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006661 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006662
Douglas Gregorb98b1992009-08-11 05:31:07 +00006663 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006664 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 E->getLParenLoc(),
6666 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 E->getRParenLoc());
6668}
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorb98b1992009-08-11 05:31:07 +00006670template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006671ExprResult
John McCall865d4472009-11-19 22:55:06 +00006672TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006673 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006674 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006675 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006676 Expr *OldBase;
6677 QualType BaseType;
6678 QualType ObjectType;
6679 if (!E->isImplicitAccess()) {
6680 OldBase = E->getBase();
6681 Base = getDerived().TransformExpr(OldBase);
6682 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
John McCallaa81e162009-12-01 22:10:20 +00006685 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006686 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006687 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006688 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006689 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006690 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006691 ObjectTy,
6692 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006693 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006694 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006695
John McCallb3d87482010-08-24 05:47:05 +00006696 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006697 BaseType = ((Expr*) Base.get())->getType();
6698 } else {
6699 OldBase = 0;
6700 BaseType = getDerived().TransformType(E->getBaseType());
6701 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6702 }
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregor6cd21982009-10-20 05:58:46 +00006704 // Transform the first part of the nested-name-specifier that qualifies
6705 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006706 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006707 = getDerived().TransformFirstQualifierInScope(
6708 E->getFirstQualifierFoundInScope(),
6709 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006710
Douglas Gregora38c6872009-09-03 16:14:30 +00006711 NestedNameSpecifier *Qualifier = 0;
6712 if (E->getQualifier()) {
6713 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6714 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006715 ObjectType,
6716 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006717 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006718 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006719 }
Mike Stump1eb44332009-09-09 15:08:12 +00006720
John McCall43fed0d2010-11-12 08:19:04 +00006721 // TODO: If this is a conversion-function-id, verify that the
6722 // destination type name (if present) resolves the same way after
6723 // instantiation as it did in the local scope.
6724
Abramo Bagnara25777432010-08-11 22:01:17 +00006725 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006726 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006727 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006729
John McCallaa81e162009-12-01 22:10:20 +00006730 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006731 // This is a reference to a member without an explicitly-specified
6732 // template argument list. Optimize for this common case.
6733 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006734 Base.get() == OldBase &&
6735 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006736 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006737 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006738 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006739 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006740
John McCall9ae2f072010-08-23 23:25:46 +00006741 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006742 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006743 E->isArrow(),
6744 E->getOperatorLoc(),
6745 Qualifier,
6746 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006747 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006748 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006749 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006750 }
6751
John McCalld5532b62009-11-23 01:53:49 +00006752 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006753 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6754 E->getNumTemplateArgs(),
6755 TransArgs))
6756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006757
John McCall9ae2f072010-08-23 23:25:46 +00006758 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006759 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 E->isArrow(),
6761 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006762 Qualifier,
6763 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006764 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006765 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006766 &TransArgs);
6767}
6768
6769template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006770ExprResult
John McCall454feb92009-12-08 09:21:05 +00006771TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006772 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006773 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006774 QualType BaseType;
6775 if (!Old->isImplicitAccess()) {
6776 Base = getDerived().TransformExpr(Old->getBase());
6777 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006778 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006779 BaseType = ((Expr*) Base.get())->getType();
6780 } else {
6781 BaseType = getDerived().TransformType(Old->getBaseType());
6782 }
John McCall129e2df2009-11-30 22:42:35 +00006783
6784 NestedNameSpecifier *Qualifier = 0;
6785 if (Old->getQualifier()) {
6786 Qualifier
6787 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006788 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006789 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006790 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006791 }
6792
Abramo Bagnara25777432010-08-11 22:01:17 +00006793 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006794 Sema::LookupOrdinaryName);
6795
6796 // Transform all the decls.
6797 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6798 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006799 NamedDecl *InstD = static_cast<NamedDecl*>(
6800 getDerived().TransformDecl(Old->getMemberLoc(),
6801 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006802 if (!InstD) {
6803 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6804 // This can happen because of dependent hiding.
6805 if (isa<UsingShadowDecl>(*I))
6806 continue;
6807 else
John McCallf312b1e2010-08-26 23:41:50 +00006808 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006809 }
John McCall129e2df2009-11-30 22:42:35 +00006810
6811 // Expand using declarations.
6812 if (isa<UsingDecl>(InstD)) {
6813 UsingDecl *UD = cast<UsingDecl>(InstD);
6814 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6815 E = UD->shadow_end(); I != E; ++I)
6816 R.addDecl(*I);
6817 continue;
6818 }
6819
6820 R.addDecl(InstD);
6821 }
6822
6823 R.resolveKind();
6824
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006825 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006826 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006827 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006828 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006829 Old->getMemberLoc(),
6830 Old->getNamingClass()));
6831 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006832 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006833
Douglas Gregor66c45152010-04-27 16:10:10 +00006834 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006835 }
Sean Huntc3021132010-05-05 15:23:54 +00006836
John McCall129e2df2009-11-30 22:42:35 +00006837 TemplateArgumentListInfo TransArgs;
6838 if (Old->hasExplicitTemplateArgs()) {
6839 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6840 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006841 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6842 Old->getNumTemplateArgs(),
6843 TransArgs))
6844 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006845 }
John McCallc2233c52010-01-15 08:34:02 +00006846
6847 // FIXME: to do this check properly, we will need to preserve the
6848 // first-qualifier-in-scope here, just in case we had a dependent
6849 // base (and therefore couldn't do the check) and a
6850 // nested-name-qualifier (and therefore could do the lookup).
6851 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006852
John McCall9ae2f072010-08-23 23:25:46 +00006853 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006854 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006855 Old->getOperatorLoc(),
6856 Old->isArrow(),
6857 Qualifier,
6858 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006859 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006860 R,
6861 (Old->hasExplicitTemplateArgs()
6862 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006863}
6864
6865template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006866ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006867TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6868 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6869 if (SubExpr.isInvalid())
6870 return ExprError();
6871
6872 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006873 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006874
6875 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6876}
6877
6878template<typename Derived>
6879ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006880TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00006881 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6882 if (Pattern.isInvalid())
6883 return ExprError();
6884
6885 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6886 return SemaRef.Owned(E);
6887
Douglas Gregor67fd1252011-01-14 21:20:45 +00006888 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6889 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00006890}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006891
6892template<typename Derived>
6893ExprResult
6894TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6895 // If E is not value-dependent, then nothing will change when we transform it.
6896 // Note: This is an instantiation-centric view.
6897 if (!E->isValueDependent())
6898 return SemaRef.Owned(E);
6899
6900 // Note: None of the implementations of TryExpandParameterPacks can ever
6901 // produce a diagnostic when given only a single unexpanded parameter pack,
6902 // so
6903 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6904 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00006905 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00006906 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00006907 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6908 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00006909 ShouldExpand, RetainExpansion,
6910 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00006911 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006912
Douglas Gregord3731192011-01-10 07:32:04 +00006913 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00006914 return SemaRef.Owned(E);
6915
6916 // We now know the length of the parameter pack, so build a new expression
6917 // that stores that length.
6918 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6919 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00006920 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00006921}
6922
Douglas Gregorbe230c32011-01-03 17:17:50 +00006923template<typename Derived>
6924ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00006925TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6926 SubstNonTypeTemplateParmPackExpr *E) {
6927 // Default behavior is to do nothing with this transformation.
6928 return SemaRef.Owned(E);
6929}
6930
6931template<typename Derived>
6932ExprResult
John McCall454feb92009-12-08 09:21:05 +00006933TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006934 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935}
6936
Mike Stump1eb44332009-09-09 15:08:12 +00006937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006938ExprResult
John McCall454feb92009-12-08 09:21:05 +00006939TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006940 TypeSourceInfo *EncodedTypeInfo
6941 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6942 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006943 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006946 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006947 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948
6949 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006950 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006951 E->getRParenLoc());
6952}
Mike Stump1eb44332009-09-09 15:08:12 +00006953
Douglas Gregorb98b1992009-08-11 05:31:07 +00006954template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006955ExprResult
John McCall454feb92009-12-08 09:21:05 +00006956TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006957 // Transform arguments.
6958 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006959 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006960 Args.reserve(E->getNumArgs());
6961 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6962 &ArgChanged))
6963 return ExprError();
6964
Douglas Gregor92e986e2010-04-22 16:44:27 +00006965 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6966 // Class message: transform the receiver type.
6967 TypeSourceInfo *ReceiverTypeInfo
6968 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6969 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006970 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006971
Douglas Gregor92e986e2010-04-22 16:44:27 +00006972 // If nothing changed, just retain the existing message send.
6973 if (!getDerived().AlwaysRebuild() &&
6974 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006975 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006976
6977 // Build a new class message send.
6978 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6979 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006980 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006981 E->getMethodDecl(),
6982 E->getLeftLoc(),
6983 move_arg(Args),
6984 E->getRightLoc());
6985 }
6986
6987 // Instance message: transform the receiver
6988 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6989 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006990 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006991 = getDerived().TransformExpr(E->getInstanceReceiver());
6992 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006993 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006994
6995 // If nothing changed, just retain the existing message send.
6996 if (!getDerived().AlwaysRebuild() &&
6997 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006998 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006999
Douglas Gregor92e986e2010-04-22 16:44:27 +00007000 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007001 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007002 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007003 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007004 E->getMethodDecl(),
7005 E->getLeftLoc(),
7006 move_arg(Args),
7007 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008}
7009
Mike Stump1eb44332009-09-09 15:08:12 +00007010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007011ExprResult
John McCall454feb92009-12-08 09:21:05 +00007012TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007013 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014}
7015
Mike Stump1eb44332009-09-09 15:08:12 +00007016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007017ExprResult
John McCall454feb92009-12-08 09:21:05 +00007018TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007019 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007020}
7021
Mike Stump1eb44332009-09-09 15:08:12 +00007022template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007023ExprResult
John McCall454feb92009-12-08 09:21:05 +00007024TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007025 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007026 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007027 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007028 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007029
7030 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007031
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007032 // If nothing changed, just retain the existing expression.
7033 if (!getDerived().AlwaysRebuild() &&
7034 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007036
John McCall9ae2f072010-08-23 23:25:46 +00007037 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007038 E->getLocation(),
7039 E->isArrow(), E->isFreeIvar());
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>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007045 // 'super' and types never change. Property never changes. Just
7046 // retain the existing expression.
7047 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007048 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007049
Douglas Gregore3303542010-04-26 20:47:02 +00007050 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007051 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007052 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007053 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007054
Douglas Gregore3303542010-04-26 20:47:02 +00007055 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007056
Douglas Gregore3303542010-04-26 20:47:02 +00007057 // If nothing changed, just retain the existing expression.
7058 if (!getDerived().AlwaysRebuild() &&
7059 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007060 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007061
John McCall12f78a62010-12-02 01:19:52 +00007062 if (E->isExplicitProperty())
7063 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7064 E->getExplicitProperty(),
7065 E->getLocation());
7066
7067 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7068 E->getType(),
7069 E->getImplicitPropertyGetter(),
7070 E->getImplicitPropertySetter(),
7071 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007072}
7073
Mike Stump1eb44332009-09-09 15:08:12 +00007074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007075ExprResult
John McCall454feb92009-12-08 09:21:05 +00007076TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007077 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007078 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007079 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007080 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007081
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007082 // If nothing changed, just retain the existing expression.
7083 if (!getDerived().AlwaysRebuild() &&
7084 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007085 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007086
John McCall9ae2f072010-08-23 23:25:46 +00007087 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007088 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089}
7090
Mike Stump1eb44332009-09-09 15:08:12 +00007091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007092ExprResult
John McCall454feb92009-12-08 09:21:05 +00007093TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007094 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007095 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007096 SubExprs.reserve(E->getNumSubExprs());
7097 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7098 SubExprs, &ArgumentChanged))
7099 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007100
Douglas Gregorb98b1992009-08-11 05:31:07 +00007101 if (!getDerived().AlwaysRebuild() &&
7102 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007103 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007104
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7106 move_arg(SubExprs),
7107 E->getRParenLoc());
7108}
7109
Mike Stump1eb44332009-09-09 15:08:12 +00007110template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007111ExprResult
John McCall454feb92009-12-08 09:21:05 +00007112TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007113 SourceLocation CaretLoc(E->getExprLoc());
7114
7115 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7116 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7117 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7118 llvm::SmallVector<ParmVarDecl*, 4> Params;
7119 llvm::SmallVector<QualType, 4> ParamTypes;
7120
7121 // Parameter substitution.
Douglas Gregor12c9c002011-01-07 16:43:16 +00007122 // FIXME: Variadic templates
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007123 const BlockDecl *BD = E->getBlockDecl();
7124 for (BlockDecl::param_const_iterator P = BD->param_begin(),
7125 EN = BD->param_end(); P != EN; ++P) {
7126 ParmVarDecl *OldParm = (*P);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00007127 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
7128 llvm::Optional<unsigned>());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007129 QualType NewType = NewParm->getType();
7130 Params.push_back(NewParm);
7131 ParamTypes.push_back(NewParm->getType());
7132 }
7133
7134 const FunctionType *BExprFunctionType = E->getFunctionType();
7135 QualType BExprResultType = BExprFunctionType->getResultType();
7136 if (!BExprResultType.isNull()) {
7137 if (!BExprResultType->isDependentType())
7138 CurBlock->ReturnType = BExprResultType;
7139 else if (BExprResultType != SemaRef.Context.DependentTy)
7140 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7141 }
John McCall711c52b2011-01-05 12:14:39 +00007142
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007143 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7144 CurBlock->ReturnType,
7145 ParamTypes.data(),
7146 ParamTypes.size(),
7147 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007148 0,
7149 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007150 CurBlock->FunctionType = FunctionType;
John McCall711c52b2011-01-05 12:14:39 +00007151
7152 // Set the parameters on the block decl.
7153 if (!Params.empty())
7154 CurBlock->TheDecl->setParams(Params.data(), Params.size());
7155
7156 // Transform the body
7157 StmtResult Body = getDerived().TransformStmt(E->getBody());
7158 if (Body.isInvalid())
7159 return ExprError();
7160
John McCall9ae2f072010-08-23 23:25:46 +00007161 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162}
7163
Mike Stump1eb44332009-09-09 15:08:12 +00007164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007165ExprResult
John McCall454feb92009-12-08 09:21:05 +00007166TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007167 NestedNameSpecifier *Qualifier = 0;
7168
7169 ValueDecl *ND
7170 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7171 E->getDecl()));
7172 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007173 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007174
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007175 if (!getDerived().AlwaysRebuild() &&
7176 ND == E->getDecl()) {
7177 // Mark it referenced in the new context regardless.
7178 // FIXME: this is a bit instantiation-specific.
7179 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7180
John McCall3fa5cae2010-10-26 07:05:15 +00007181 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007182 }
7183
Abramo Bagnara25777432010-08-11 22:01:17 +00007184 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007185 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007186 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187}
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007190// Type reconstruction
7191//===----------------------------------------------------------------------===//
7192
Mike Stump1eb44332009-09-09 15:08:12 +00007193template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007194QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7195 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007196 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007197 getDerived().getBaseEntity());
7198}
7199
Mike Stump1eb44332009-09-09 15:08:12 +00007200template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007201QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7202 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007203 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007204 getDerived().getBaseEntity());
7205}
7206
Mike Stump1eb44332009-09-09 15:08:12 +00007207template<typename Derived>
7208QualType
John McCall85737a72009-10-30 00:06:24 +00007209TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7210 bool WrittenAsLValue,
7211 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007212 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007213 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007214}
7215
7216template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007217QualType
John McCall85737a72009-10-30 00:06:24 +00007218TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7219 QualType ClassType,
7220 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007221 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007222 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007223}
7224
7225template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007226QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007227TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7228 ArrayType::ArraySizeModifier SizeMod,
7229 const llvm::APInt *Size,
7230 Expr *SizeExpr,
7231 unsigned IndexTypeQuals,
7232 SourceRange BracketsRange) {
7233 if (SizeExpr || !Size)
7234 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7235 IndexTypeQuals, BracketsRange,
7236 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007237
7238 QualType Types[] = {
7239 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7240 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7241 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007242 };
7243 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7244 QualType SizeType;
7245 for (unsigned I = 0; I != NumTypes; ++I)
7246 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7247 SizeType = Types[I];
7248 break;
7249 }
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007251 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7252 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007253 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007254 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007255 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007256}
Mike Stump1eb44332009-09-09 15:08:12 +00007257
Douglas Gregor577f75a2009-08-04 16:50:30 +00007258template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007259QualType
7260TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007261 ArrayType::ArraySizeModifier SizeMod,
7262 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007263 unsigned IndexTypeQuals,
7264 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007265 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007266 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007267}
7268
7269template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007270QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007271TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007272 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007273 unsigned IndexTypeQuals,
7274 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007275 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007276 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007277}
Mike Stump1eb44332009-09-09 15:08:12 +00007278
Douglas Gregor577f75a2009-08-04 16:50:30 +00007279template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007280QualType
7281TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007282 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007283 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007284 unsigned IndexTypeQuals,
7285 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007286 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007287 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007288 IndexTypeQuals, BracketsRange);
7289}
7290
7291template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007292QualType
7293TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007294 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007295 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007296 unsigned IndexTypeQuals,
7297 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007298 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007299 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007300 IndexTypeQuals, BracketsRange);
7301}
7302
7303template<typename Derived>
7304QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007305 unsigned NumElements,
7306 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007307 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007308 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007309}
Mike Stump1eb44332009-09-09 15:08:12 +00007310
Douglas Gregor577f75a2009-08-04 16:50:30 +00007311template<typename Derived>
7312QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7313 unsigned NumElements,
7314 SourceLocation AttributeLoc) {
7315 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7316 NumElements, true);
7317 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007318 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7319 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007320 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007321}
Mike Stump1eb44332009-09-09 15:08:12 +00007322
Douglas Gregor577f75a2009-08-04 16:50:30 +00007323template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007324QualType
7325TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007326 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007327 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007328 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007329}
Mike Stump1eb44332009-09-09 15:08:12 +00007330
Douglas Gregor577f75a2009-08-04 16:50:30 +00007331template<typename Derived>
7332QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007333 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007334 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007335 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007336 unsigned Quals,
7337 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007338 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007339 Quals,
7340 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007341 getDerived().getBaseEntity(),
7342 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007343}
Mike Stump1eb44332009-09-09 15:08:12 +00007344
Douglas Gregor577f75a2009-08-04 16:50:30 +00007345template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007346QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7347 return SemaRef.Context.getFunctionNoProtoType(T);
7348}
7349
7350template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007351QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7352 assert(D && "no decl found");
7353 if (D->isInvalidDecl()) return QualType();
7354
Douglas Gregor92e986e2010-04-22 16:44:27 +00007355 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007356 TypeDecl *Ty;
7357 if (isa<UsingDecl>(D)) {
7358 UsingDecl *Using = cast<UsingDecl>(D);
7359 assert(Using->isTypeName() &&
7360 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7361
7362 // A valid resolved using typename decl points to exactly one type decl.
7363 assert(++Using->shadow_begin() == Using->shadow_end());
7364 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007365
John McCalled976492009-12-04 22:46:56 +00007366 } else {
7367 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7368 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7369 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7370 }
7371
7372 return SemaRef.Context.getTypeDeclType(Ty);
7373}
7374
7375template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007376QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7377 SourceLocation Loc) {
7378 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007379}
7380
7381template<typename Derived>
7382QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7383 return SemaRef.Context.getTypeOfType(Underlying);
7384}
7385
7386template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007387QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7388 SourceLocation Loc) {
7389 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007390}
7391
7392template<typename Derived>
7393QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007394 TemplateName Template,
7395 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007396 const TemplateArgumentListInfo &TemplateArgs) {
7397 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007398}
Mike Stump1eb44332009-09-09 15:08:12 +00007399
Douglas Gregordcee1a12009-08-06 05:28:30 +00007400template<typename Derived>
7401NestedNameSpecifier *
7402TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7403 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007404 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007405 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007406 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007407 CXXScopeSpec SS;
7408 // FIXME: The source location information is all wrong.
7409 SS.setRange(Range);
7410 SS.setScopeRep(Prefix);
7411 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007412 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007413 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007414 ObjectType,
7415 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007416 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007417}
7418
7419template<typename Derived>
7420NestedNameSpecifier *
7421TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7422 SourceRange Range,
7423 NamespaceDecl *NS) {
7424 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7425}
7426
7427template<typename Derived>
7428NestedNameSpecifier *
7429TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7430 SourceRange Range,
7431 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007432 QualType T) {
7433 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007434 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007435 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007436 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7437 T.getTypePtr());
7438 }
Mike Stump1eb44332009-09-09 15:08:12 +00007439
Douglas Gregordcee1a12009-08-06 05:28:30 +00007440 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7441 return 0;
7442}
Mike Stump1eb44332009-09-09 15:08:12 +00007443
Douglas Gregord1067e52009-08-06 06:41:21 +00007444template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007445TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007446TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7447 bool TemplateKW,
7448 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007449 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007450 Template);
7451}
7452
7453template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007454TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007455TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007456 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007457 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007458 QualType ObjectType,
7459 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007460 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007461 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007462 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007463 UnqualifiedId Name;
7464 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007465 Sema::TemplateTy Template;
7466 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7467 /*FIXME:*/getDerived().getBaseLocation(),
7468 SS,
7469 Name,
John McCallb3d87482010-08-24 05:47:05 +00007470 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007471 /*EnteringContext=*/false,
7472 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007473 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007474}
Mike Stump1eb44332009-09-09 15:08:12 +00007475
Douglas Gregorb98b1992009-08-11 05:31:07 +00007476template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007477TemplateName
7478TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7479 OverloadedOperatorKind Operator,
7480 QualType ObjectType) {
7481 CXXScopeSpec SS;
7482 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7483 SS.setScopeRep(Qualifier);
7484 UnqualifiedId Name;
7485 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7486 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7487 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007488 Sema::TemplateTy Template;
7489 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007490 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007491 SS,
7492 Name,
John McCallb3d87482010-08-24 05:47:05 +00007493 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007494 /*EnteringContext=*/false,
7495 Template);
7496 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007497}
Sean Huntc3021132010-05-05 15:23:54 +00007498
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007499template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007500ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007501TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7502 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007503 Expr *OrigCallee,
7504 Expr *First,
7505 Expr *Second) {
7506 Expr *Callee = OrigCallee->IgnoreParenCasts();
7507 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007508
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007510 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007511 if (!First->getType()->isOverloadableType() &&
7512 !Second->getType()->isOverloadableType())
7513 return getSema().CreateBuiltinArraySubscriptExpr(First,
7514 Callee->getLocStart(),
7515 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007516 } else if (Op == OO_Arrow) {
7517 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007518 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7519 } else if (Second == 0 || isPostIncDec) {
7520 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521 // The argument is not of overloadable type, so try to create a
7522 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007523 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007525
John McCall9ae2f072010-08-23 23:25:46 +00007526 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527 }
7528 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007529 if (!First->getType()->isOverloadableType() &&
7530 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531 // Neither of the arguments is an overloadable type, so try to
7532 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007533 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007534 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007535 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007537 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007538
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539 return move(Result);
7540 }
7541 }
Mike Stump1eb44332009-09-09 15:08:12 +00007542
7543 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007544 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007545 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007546
John McCall9ae2f072010-08-23 23:25:46 +00007547 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007548 assert(ULE->requiresADL());
7549
7550 // FIXME: Do we have to check
7551 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007552 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007553 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007554 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007555 }
Mike Stump1eb44332009-09-09 15:08:12 +00007556
Douglas Gregorb98b1992009-08-11 05:31:07 +00007557 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007558 Expr *Args[2] = { First, Second };
7559 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007560
Douglas Gregorb98b1992009-08-11 05:31:07 +00007561 // Create the overloaded operator invocation for unary operators.
7562 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007563 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007564 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007565 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007566 }
Mike Stump1eb44332009-09-09 15:08:12 +00007567
Sebastian Redlf322ed62009-10-29 20:17:01 +00007568 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007569 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007570 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007571 First,
7572 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007573
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007575 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007576 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007577 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7578 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007580
Mike Stump1eb44332009-09-09 15:08:12 +00007581 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007582}
Mike Stump1eb44332009-09-09 15:08:12 +00007583
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007585ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007586TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007587 SourceLocation OperatorLoc,
7588 bool isArrow,
7589 NestedNameSpecifier *Qualifier,
7590 SourceRange QualifierRange,
7591 TypeSourceInfo *ScopeType,
7592 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007593 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007594 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007595 CXXScopeSpec SS;
7596 if (Qualifier) {
7597 SS.setRange(QualifierRange);
7598 SS.setScopeRep(Qualifier);
7599 }
7600
John McCall9ae2f072010-08-23 23:25:46 +00007601 QualType BaseType = Base->getType();
7602 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007603 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007604 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007605 !BaseType->getAs<PointerType>()->getPointeeType()
7606 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007607 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007608 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007609 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007610 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007611 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007612 /*FIXME?*/true);
7613 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007614
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007615 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007616 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7617 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7618 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7619 NameInfo.setNamedTypeInfo(DestroyedType);
7620
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007621 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007622
John McCall9ae2f072010-08-23 23:25:46 +00007623 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007624 OperatorLoc, isArrow,
7625 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007626 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007627 /*TemplateArgs*/ 0);
7628}
7629
Douglas Gregor577f75a2009-08-04 16:50:30 +00007630} // end namespace clang
7631
7632#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H