blob: 02c95bdb13ced89b685552817ec5c75581c6ac39 [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);
Sean Huntc3021132010-05-05 15:23:54 +0000894
Douglas Gregor43959a92009-08-20 07:17:43 +0000895 /// \brief Build a new compound statement.
896 ///
897 /// By default, performs semantic analysis to build the new statement.
898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000899 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000900 MultiStmtArg Statements,
901 SourceLocation RBraceLoc,
902 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000903 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000904 IsStmtExpr);
905 }
906
907 /// \brief Build a new case 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 RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000912 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000913 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000914 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000915 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000916 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000917 ColonLoc);
918 }
Mike Stump1eb44332009-09-09 15:08:12 +0000919
Douglas Gregor43959a92009-08-20 07:17:43 +0000920 /// \brief Attach the body to a new case statement.
921 ///
922 /// By default, performs semantic analysis to build the new statement.
923 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000924 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000925 getSema().ActOnCaseStmtBody(S, Body);
926 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000927 }
Mike Stump1eb44332009-09-09 15:08:12 +0000928
Douglas Gregor43959a92009-08-20 07:17:43 +0000929 /// \brief Build a new default statement.
930 ///
931 /// By default, performs semantic analysis to build the new statement.
932 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000933 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000934 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000935 Stmt *SubStmt) {
936 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000937 /*CurScope=*/0);
938 }
Mike Stump1eb44332009-09-09 15:08:12 +0000939
Douglas Gregor43959a92009-08-20 07:17:43 +0000940 /// \brief Build a new label statement.
941 ///
942 /// By default, performs semantic analysis to build the new statement.
943 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000944 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000945 IdentifierInfo *Id,
946 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000947 Stmt *SubStmt, bool HasUnusedAttr) {
948 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
949 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000950 }
Mike Stump1eb44332009-09-09 15:08:12 +0000951
Douglas Gregor43959a92009-08-20 07:17:43 +0000952 /// \brief Build a new "if" 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 RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000957 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000958 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000959 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000960 }
Mike Stump1eb44332009-09-09 15:08:12 +0000961
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 /// \brief Start building a new switch statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000966 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000967 Expr *Cond, VarDecl *CondVar) {
968 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000969 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000970 }
Mike Stump1eb44332009-09-09 15:08:12 +0000971
Douglas Gregor43959a92009-08-20 07:17:43 +0000972 /// \brief Attach the body to the switch statement.
973 ///
974 /// By default, performs semantic analysis to build the new statement.
975 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000976 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000977 Stmt *Switch, Stmt *Body) {
978 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 }
980
981 /// \brief Build a new while statement.
982 ///
983 /// By default, performs semantic analysis to build the new statement.
984 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000985 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000986 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000987 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000988 Stmt *Body) {
989 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000990 }
Mike Stump1eb44332009-09-09 15:08:12 +0000991
Douglas Gregor43959a92009-08-20 07:17:43 +0000992 /// \brief Build a new do-while statement.
993 ///
994 /// By default, performs semantic analysis to build the new statement.
995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000996 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000997 SourceLocation WhileLoc,
998 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000999 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001001 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1002 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 }
1004
1005 /// \brief Build a new for statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001009 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001010 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001011 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00001012 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +00001013 SourceLocation RParenLoc, Stmt *Body) {
1014 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +00001015 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +00001016 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 }
Mike Stump1eb44332009-09-09 15:08:12 +00001018
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 /// \brief Build a new goto statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001023 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001024 SourceLocation LabelLoc,
1025 LabelStmt *Label) {
1026 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1027 }
1028
1029 /// \brief Build a new indirect goto statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001033 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001035 Expr *Target) {
1036 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 }
Mike Stump1eb44332009-09-09 15:08:12 +00001038
Douglas Gregor43959a92009-08-20 07:17:43 +00001039 /// \brief Build a new return statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001043 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001044 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +00001045
John McCall9ae2f072010-08-23 23:25:46 +00001046 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 }
Mike Stump1eb44332009-09-09 15:08:12 +00001048
Douglas Gregor43959a92009-08-20 07:17:43 +00001049 /// \brief Build a new declaration statement.
1050 ///
1051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001053 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001054 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 SourceLocation EndLoc) {
1056 return getSema().Owned(
1057 new (getSema().Context) DeclStmt(
1058 DeclGroupRef::Create(getSema().Context,
1059 Decls, NumDecls),
1060 StartLoc, EndLoc));
1061 }
Mike Stump1eb44332009-09-09 15:08:12 +00001062
Anders Carlsson703e3942010-01-24 05:50:09 +00001063 /// \brief Build a new inline asm statement.
1064 ///
1065 /// By default, performs semantic analysis to build the new statement.
1066 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001067 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001068 bool IsSimple,
1069 bool IsVolatile,
1070 unsigned NumOutputs,
1071 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001072 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001073 MultiExprArg Constraints,
1074 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001075 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001076 MultiExprArg Clobbers,
1077 SourceLocation RParenLoc,
1078 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001079 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001080 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001081 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001082 RParenLoc, MSAsm);
1083 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001084
1085 /// \brief Build a new Objective-C @try statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001090 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001091 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001092 Stmt *Finally) {
1093 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1094 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001095 }
1096
Douglas Gregorbe270a02010-04-26 17:57:08 +00001097 /// \brief Rebuild an Objective-C exception declaration.
1098 ///
1099 /// By default, performs semantic analysis to build the new declaration.
1100 /// Subclasses may override this routine to provide different behavior.
1101 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1102 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001103 return getSema().BuildObjCExceptionDecl(TInfo, T,
1104 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001105 ExceptionDecl->getLocation());
1106 }
Sean Huntc3021132010-05-05 15:23:54 +00001107
Douglas Gregorbe270a02010-04-26 17:57:08 +00001108 /// \brief Build a new Objective-C @catch statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001112 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001113 SourceLocation RParenLoc,
1114 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001115 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001116 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001117 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001118 }
Sean Huntc3021132010-05-05 15:23:54 +00001119
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001120 /// \brief Build a new Objective-C @finally 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 RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001125 Stmt *Body) {
1126 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001127 }
Sean Huntc3021132010-05-05 15:23:54 +00001128
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001129 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001130 ///
1131 /// By default, performs semantic analysis to build the new statement.
1132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001133 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001134 Expr *Operand) {
1135 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001136 }
Sean Huntc3021132010-05-05 15:23:54 +00001137
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001138 /// \brief Build a new Objective-C @synchronized statement.
1139 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001142 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Expr *Object,
1144 Stmt *Body) {
1145 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1146 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001147 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001148
1149 /// \brief Build a new Objective-C fast enumeration statement.
1150 ///
1151 /// By default, performs semantic analysis to build the new statement.
1152 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001153 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001154 SourceLocation LParenLoc,
1155 Stmt *Element,
1156 Expr *Collection,
1157 SourceLocation RParenLoc,
1158 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001159 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001160 Element,
1161 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001162 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001163 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001164 }
Sean Huntc3021132010-05-05 15:23:54 +00001165
Douglas Gregor43959a92009-08-20 07:17:43 +00001166 /// \brief Build a new C++ exception declaration.
1167 ///
1168 /// By default, performs semantic analysis to build the new decaration.
1169 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001170 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001171 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001172 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001173 SourceLocation Loc) {
1174 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001175 }
1176
1177 /// \brief Build a new C++ catch statement.
1178 ///
1179 /// By default, performs semantic analysis to build the new statement.
1180 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001181 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001182 VarDecl *ExceptionDecl,
1183 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001184 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1185 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001186 }
Mike Stump1eb44332009-09-09 15:08:12 +00001187
Douglas Gregor43959a92009-08-20 07:17:43 +00001188 /// \brief Build a new C++ try statement.
1189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001192 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001193 Stmt *TryBlock,
1194 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001195 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001196 }
Mike Stump1eb44332009-09-09 15:08:12 +00001197
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// \brief Build a new expression that references a declaration.
1199 ///
1200 /// By default, performs semantic analysis to build the new expression.
1201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001202 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001203 LookupResult &R,
1204 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001205 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1206 }
1207
1208
1209 /// \brief Build a new expression that references a declaration.
1210 ///
1211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001213 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001214 SourceRange QualifierRange,
1215 ValueDecl *VD,
1216 const DeclarationNameInfo &NameInfo,
1217 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001218 CXXScopeSpec SS;
1219 SS.setScopeRep(Qualifier);
1220 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001221
1222 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001223
1224 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001225 }
Mike Stump1eb44332009-09-09 15:08:12 +00001226
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001228 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 /// By default, performs semantic analysis to build the new expression.
1230 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001231 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001233 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001234 }
1235
Douglas Gregora71d8192009-09-04 17:36:40 +00001236 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001237 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001238 /// By default, performs semantic analysis to build the new expression.
1239 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001240 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001241 SourceLocation OperatorLoc,
1242 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001243 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001244 SourceRange QualifierRange,
1245 TypeSourceInfo *ScopeType,
1246 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001247 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001248 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001249
Douglas Gregorb98b1992009-08-11 05:31:07 +00001250 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001251 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001252 /// By default, performs semantic analysis to build the new expression.
1253 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001254 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001255 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001256 Expr *SubExpr) {
1257 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 }
Mike Stump1eb44332009-09-09 15:08:12 +00001259
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001260 /// \brief Build a new builtin offsetof expression.
1261 ///
1262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001265 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001266 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001267 unsigned NumComponents,
1268 SourceLocation RParenLoc) {
1269 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1270 NumComponents, RParenLoc);
1271 }
Sean Huntc3021132010-05-05 15:23:54 +00001272
Douglas Gregorb98b1992009-08-11 05:31:07 +00001273 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001274 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001277 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001278 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001279 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001280 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 }
1282
Mike Stump1eb44332009-09-09 15:08:12 +00001283 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001285 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 /// By default, performs semantic analysis to build the new expression.
1287 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001288 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001290 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001291 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001292 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001294
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 return move(Result);
1296 }
Mike Stump1eb44332009-09-09 15:08:12 +00001297
Douglas Gregorb98b1992009-08-11 05:31:07 +00001298 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001299 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001302 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001303 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001304 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001305 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001306 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1307 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 RBracketLoc);
1309 }
1310
1311 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001312 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001315 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001317 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001318 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001319 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 }
1321
1322 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001323 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001326 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001327 bool isArrow,
1328 NestedNameSpecifier *Qualifier,
1329 SourceRange QualifierRange,
1330 const DeclarationNameInfo &MemberNameInfo,
1331 ValueDecl *Member,
1332 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001333 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001334 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001335 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001336 // We have a reference to an unnamed field. This is always the
1337 // base of an anonymous struct/union member access, i.e. the
1338 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001339 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001340 assert(Member->getType()->isRecordType() &&
1341 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001342
John McCall9ae2f072010-08-23 23:25:46 +00001343 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001344 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001345 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001346
John McCallf89e55a2010-11-18 06:31:45 +00001347 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001348 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001349 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001350 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001351 cast<FieldDecl>(Member)->getType(),
1352 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001353 return getSema().Owned(ME);
1354 }
Mike Stump1eb44332009-09-09 15:08:12 +00001355
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001356 CXXScopeSpec SS;
1357 if (Qualifier) {
1358 SS.setRange(QualifierRange);
1359 SS.setScopeRep(Qualifier);
1360 }
1361
John McCall9ae2f072010-08-23 23:25:46 +00001362 getSema().DefaultFunctionArrayConversion(Base);
1363 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001364
John McCall6bb80172010-03-30 21:47:33 +00001365 // FIXME: this involves duplicating earlier analysis in a lot of
1366 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001367 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001368 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001369 R.resolveKind();
1370
John McCall9ae2f072010-08-23 23:25:46 +00001371 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001372 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001373 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 }
Mike Stump1eb44332009-09-09 15:08:12 +00001375
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001377 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001378 /// By default, performs semantic analysis to build the new expression.
1379 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001380 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001381 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001382 Expr *LHS, Expr *RHS) {
1383 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 }
1385
1386 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001387 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 /// By default, performs semantic analysis to build the new expression.
1389 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001390 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001392 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001394 Expr *RHS) {
1395 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1396 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001397 }
1398
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001400 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001403 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001404 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001406 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001407 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001408 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 }
Mike Stump1eb44332009-09-09 15:08:12 +00001410
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 /// \brief Build a new compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001416 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001418 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001419 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001420 Init);
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 extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 SourceLocation OpLoc,
1429 SourceLocation AccessorLoc,
1430 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001431
John McCall129e2df2009-11-30 22:42:35 +00001432 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001433 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001434 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001435 OpLoc, /*IsArrow*/ false,
1436 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001437 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001438 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 }
Mike Stump1eb44332009-09-09 15:08:12 +00001440
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001442 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001443 /// By default, performs semantic analysis to build the new expression.
1444 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001445 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001447 SourceLocation RBraceLoc,
1448 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001449 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001450 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1451 if (Result.isInvalid() || ResultTy->isDependentType())
1452 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001453
Douglas Gregore48319a2009-11-09 17:16:50 +00001454 // Patch in the result type we were given, which may have been computed
1455 // when the initial InitListExpr was built.
1456 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1457 ILE->setType(ResultTy);
1458 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 }
Mike Stump1eb44332009-09-09 15:08:12 +00001460
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001465 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 MultiExprArg ArrayExprs,
1467 SourceLocation EqualOrColonLoc,
1468 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001469 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001470 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001475
Douglas Gregorb98b1992009-08-11 05:31:07 +00001476 ArrayExprs.release();
1477 return move(Result);
1478 }
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001481 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// By default, builds the implicit value initialization without performing
1483 /// any semantic analysis. Subclasses may override this routine to provide
1484 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001485 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1487 }
Mike Stump1eb44332009-09-09 15:08:12 +00001488
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001490 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001493 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001494 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001495 SourceLocation RParenLoc) {
1496 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001497 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001498 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001499 }
1500
1501 /// \brief Build a new expression list in parentheses.
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 RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 MultiExprArg SubExprs,
1507 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001508 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001509 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
Mike Stump1eb44332009-09-09 15:08:12 +00001511
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
1514 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// rather than attempting to map the label statement itself.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 SourceLocation LabelLoc,
1519 LabelStmt *Label) {
1520 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001524 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001528 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001530 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 }
Mike Stump1eb44332009-09-09 15:08:12 +00001532
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 /// \brief Build a new __builtin_choose_expr expression.
1534 ///
1535 /// By default, performs semantic analysis to build the new expression.
1536 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001537 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001538 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 SourceLocation RParenLoc) {
1540 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001541 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 RParenLoc);
1543 }
Mike Stump1eb44332009-09-09 15:08:12 +00001544
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// \brief Build a new overloaded operator call expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// The semantic analysis provides the behavior of template instantiation,
1549 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001550 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// argument-dependent lookup, etc. Subclasses may override this routine to
1552 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001555 Expr *Callee,
1556 Expr *First,
1557 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001558
1559 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 /// reinterpret_cast.
1561 ///
1562 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001563 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001565 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 Stmt::StmtClass Class,
1567 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001568 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 SourceLocation RAngleLoc,
1570 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001571 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 SourceLocation RParenLoc) {
1573 switch (Class) {
1574 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001575 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001576 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001577 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578
1579 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001580 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001581 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001582 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001585 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001586 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001587 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001588 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001589
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001591 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001592 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001593 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 default:
1596 assert(false && "Invalid C++ named cast");
1597 break;
1598 }
Mike Stump1eb44332009-09-09 15:08:12 +00001599
John McCallf312b1e2010-08-26 23:41:50 +00001600 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 }
Mike Stump1eb44332009-09-09 15:08:12 +00001602
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 /// \brief Build a new C++ static_cast expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001607 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001609 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 SourceLocation RAngleLoc,
1611 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001612 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001614 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001615 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001616 SourceRange(LAngleLoc, RAngleLoc),
1617 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 }
1619
1620 /// \brief Build a new C++ dynamic_cast expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001624 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001626 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 SourceLocation RAngleLoc,
1628 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001629 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001631 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001632 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001633 SourceRange(LAngleLoc, RAngleLoc),
1634 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 }
1636
1637 /// \brief Build a new C++ reinterpret_cast expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001643 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 SourceLocation RAngleLoc,
1645 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001646 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001648 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001649 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001650 SourceRange(LAngleLoc, RAngleLoc),
1651 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
1653
1654 /// \brief Build a new C++ const_cast expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001660 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 SourceLocation RAngleLoc,
1662 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001665 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001666 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001667 SourceRange(LAngleLoc, RAngleLoc),
1668 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
Mike Stump1eb44332009-09-09 15:08:12 +00001670
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 /// \brief Build a new C++ functional-style cast expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001675 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1676 SourceLocation LParenLoc,
1677 Expr *Sub,
1678 SourceLocation RParenLoc) {
1679 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001680 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 RParenLoc);
1682 }
Mike Stump1eb44332009-09-09 15:08:12 +00001683
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 /// \brief Build a new C++ typeid(type) expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001688 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001689 SourceLocation TypeidLoc,
1690 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001692 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001693 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001694 }
Mike Stump1eb44332009-09-09 15:08:12 +00001695
Francois Pichet01b7c302010-09-08 12:20:18 +00001696
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// \brief Build a new C++ typeid(expr) expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001701 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001702 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001703 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001705 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001706 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001707 }
1708
Francois Pichet01b7c302010-09-08 12:20:18 +00001709 /// \brief Build a new C++ __uuidof(type) expression.
1710 ///
1711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
1713 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1714 SourceLocation TypeidLoc,
1715 TypeSourceInfo *Operand,
1716 SourceLocation RParenLoc) {
1717 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1718 RParenLoc);
1719 }
1720
1721 /// \brief Build a new C++ __uuidof(expr) 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 Expr *Operand,
1728 SourceLocation RParenLoc) {
1729 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1730 RParenLoc);
1731 }
1732
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 /// \brief Build a new C++ "this" expression.
1734 ///
1735 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001736 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001738 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001739 QualType ThisType,
1740 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001742 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1743 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 }
1745
1746 /// \brief Build a new C++ throw expression.
1747 ///
1748 /// By default, performs semantic analysis to build the new expression.
1749 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001750 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001751 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 }
1753
1754 /// \brief Build a new C++ default-argument expression.
1755 ///
1756 /// By default, builds a new default-argument expression, which does not
1757 /// require any semantic analysis. Subclasses may override this routine to
1758 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001759 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001760 ParmVarDecl *Param) {
1761 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1762 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 }
1764
1765 /// \brief Build a new C++ zero-initialization expression.
1766 ///
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001769 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1770 SourceLocation LParenLoc,
1771 SourceLocation RParenLoc) {
1772 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001773 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001774 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 }
Mike Stump1eb44332009-09-09 15:08:12 +00001776
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 /// \brief Build a new C++ "new" expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001781 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001782 bool UseGlobal,
1783 SourceLocation PlacementLParen,
1784 MultiExprArg PlacementArgs,
1785 SourceLocation PlacementRParen,
1786 SourceRange TypeIdParens,
1787 QualType AllocatedType,
1788 TypeSourceInfo *AllocatedTypeInfo,
1789 Expr *ArraySize,
1790 SourceLocation ConstructorLParen,
1791 MultiExprArg ConstructorArgs,
1792 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001793 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 PlacementLParen,
1795 move(PlacementArgs),
1796 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001797 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001798 AllocatedType,
1799 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001800 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 ConstructorLParen,
1802 move(ConstructorArgs),
1803 ConstructorRParen);
1804 }
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 /// \brief Build a new C++ "delete" expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001810 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 bool IsGlobalDelete,
1812 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001813 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001815 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 }
Mike Stump1eb44332009-09-09 15:08:12 +00001817
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 /// \brief Build a new unary type trait 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 RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001823 SourceLocation StartLoc,
1824 TypeSourceInfo *T,
1825 SourceLocation RParenLoc) {
1826 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 }
1828
Francois Pichet6ad6f282010-12-07 00:08:36 +00001829 /// \brief Build a new binary type trait expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
1833 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1834 SourceLocation StartLoc,
1835 TypeSourceInfo *LhsT,
1836 TypeSourceInfo *RhsT,
1837 SourceLocation RParenLoc) {
1838 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1839 }
1840
Mike Stump1eb44332009-09-09 15:08:12 +00001841 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 /// expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001848 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001849 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 CXXScopeSpec SS;
1851 SS.setRange(QualifierRange);
1852 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001853
1854 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001855 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001856 *TemplateArgs);
1857
Abramo Bagnara25777432010-08-11 22:01:17 +00001858 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001859 }
1860
1861 /// \brief Build a new template-id expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001865 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001866 LookupResult &R,
1867 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001868 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001869 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001870 }
1871
1872 /// \brief Build a new object-construction expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001876 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001877 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 CXXConstructorDecl *Constructor,
1879 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001880 MultiExprArg Args,
1881 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001882 CXXConstructExpr::ConstructionKind ConstructKind,
1883 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001884 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001885 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001886 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001887 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001888
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001889 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001890 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001891 RequiresZeroInit, ConstructKind,
1892 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new object-construction expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001899 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1900 SourceLocation LParenLoc,
1901 MultiExprArg Args,
1902 SourceLocation RParenLoc) {
1903 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 LParenLoc,
1905 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 RParenLoc);
1907 }
1908
1909 /// \brief Build a new object-construction expression.
1910 ///
1911 /// By default, performs semantic analysis to build the new expression.
1912 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001913 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1914 SourceLocation LParenLoc,
1915 MultiExprArg Args,
1916 SourceLocation RParenLoc) {
1917 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 LParenLoc,
1919 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 RParenLoc);
1921 }
Mike Stump1eb44332009-09-09 15:08:12 +00001922
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 /// \brief Build a new member reference expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001927 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001928 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001929 bool IsArrow,
1930 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001931 NestedNameSpecifier *Qualifier,
1932 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001933 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001934 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001935 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001937 SS.setRange(QualifierRange);
1938 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001939
John McCall9ae2f072010-08-23 23:25:46 +00001940 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001941 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001942 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001943 MemberNameInfo,
1944 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001945 }
1946
John McCall129e2df2009-11-30 22:42:35 +00001947 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001951 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001952 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001953 SourceLocation OperatorLoc,
1954 bool IsArrow,
1955 NestedNameSpecifier *Qualifier,
1956 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001957 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001958 LookupResult &R,
1959 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001960 CXXScopeSpec SS;
1961 SS.setRange(QualifierRange);
1962 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001963
John McCall9ae2f072010-08-23 23:25:46 +00001964 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001965 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001966 SS, FirstQualifierInScope,
1967 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001968 }
Mike Stump1eb44332009-09-09 15:08:12 +00001969
Sebastian Redl2e156222010-09-10 20:55:43 +00001970 /// \brief Build a new noexcept expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1975 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1976 }
1977
Douglas Gregoree8aff02011-01-04 17:33:58 +00001978 /// \brief Build a new expression to compute the length of a parameter pack.
1979 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1980 SourceLocation PackLoc,
1981 SourceLocation RParenLoc,
1982 unsigned Length) {
1983 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1984 OperatorLoc, Pack, PackLoc,
1985 RParenLoc, Length);
1986 }
1987
Douglas Gregorb98b1992009-08-11 05:31:07 +00001988 /// \brief Build a new Objective-C @encode expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001992 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001993 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001995 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001996 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001997 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998
Douglas Gregor92e986e2010-04-22 16:44:27 +00001999 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002000 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002001 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002002 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002003 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002004 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002005 MultiExprArg Args,
2006 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002007 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2008 ReceiverTypeInfo->getType(),
2009 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002010 Sel, Method, LBracLoc, SelectorLoc,
2011 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002012 }
2013
2014 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002015 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002016 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002017 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002018 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002019 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002020 MultiExprArg Args,
2021 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002022 return SemaRef.BuildInstanceMessage(Receiver,
2023 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002024 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002025 Sel, Method, LBracLoc, SelectorLoc,
2026 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002027 }
2028
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002029 /// \brief Build a new Objective-C ivar reference expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002033 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002034 SourceLocation IvarLoc,
2035 bool IsArrow, bool IsFreeIvar) {
2036 // FIXME: We lose track of the IsFreeIvar bit.
2037 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002038 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002039 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2040 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002041 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002042 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002043 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002044 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002045 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002046 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002047
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002048 if (Result.get())
2049 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002050
John McCall9ae2f072010-08-23 23:25:46 +00002051 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002052 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002053 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002054 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002055 /*TemplateArgs=*/0);
2056 }
Douglas Gregore3303542010-04-26 20:47:02 +00002057
2058 /// \brief Build a new Objective-C property reference expression.
2059 ///
2060 /// By default, performs semantic analysis to build the new expression.
2061 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002062 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002063 ObjCPropertyDecl *Property,
2064 SourceLocation PropertyLoc) {
2065 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002066 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002067 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2068 Sema::LookupMemberName);
2069 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002070 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002071 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002072 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002073 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002074 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002075
Douglas Gregore3303542010-04-26 20:47:02 +00002076 if (Result.get())
2077 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002078
John McCall9ae2f072010-08-23 23:25:46 +00002079 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002080 /*FIXME:*/PropertyLoc, IsArrow,
2081 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002082 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002083 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002084 /*TemplateArgs=*/0);
2085 }
Sean Huntc3021132010-05-05 15:23:54 +00002086
John McCall12f78a62010-12-02 01:19:52 +00002087 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002088 ///
2089 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002090 /// Subclasses may override this routine to provide different behavior.
2091 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2092 ObjCMethodDecl *Getter,
2093 ObjCMethodDecl *Setter,
2094 SourceLocation PropertyLoc) {
2095 // Since these expressions can only be value-dependent, we do not
2096 // need to perform semantic analysis again.
2097 return Owned(
2098 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2099 VK_LValue, OK_ObjCProperty,
2100 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002101 }
2102
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002103 /// \brief Build a new Objective-C "isa" expression.
2104 ///
2105 /// By default, performs semantic analysis to build the new expression.
2106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002107 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002108 bool IsArrow) {
2109 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002110 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002111 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2112 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002113 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002114 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002115 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002116 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002117 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002118
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002119 if (Result.get())
2120 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002121
John McCall9ae2f072010-08-23 23:25:46 +00002122 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002123 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002124 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002125 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002126 /*TemplateArgs=*/0);
2127 }
Sean Huntc3021132010-05-05 15:23:54 +00002128
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 /// \brief Build a new shuffle vector expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002133 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002134 MultiExprArg SubExprs,
2135 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002136 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002137 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002138 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2139 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2140 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2141 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002142
Douglas Gregorb98b1992009-08-11 05:31:07 +00002143 // Build a reference to the __builtin_shufflevector builtin
2144 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002145 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002146 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002147 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002148 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002149
2150 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002151 unsigned NumSubExprs = SubExprs.size();
2152 Expr **Subs = (Expr **)SubExprs.release();
2153 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2154 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002155 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002156 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002157 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002158 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002159
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002161 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002162 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002163 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002164
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002166 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 }
John McCall43fed0d2010-11-12 08:19:04 +00002168
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002169 /// \brief Build a new template argument pack expansion.
2170 ///
2171 /// By default, performs semantic analysis to build a new pack expansion
2172 /// for a template argument. Subclasses may override this routine to provide
2173 /// different behavior.
2174 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002175 SourceLocation EllipsisLoc,
2176 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002177 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002178 case TemplateArgument::Expression: {
2179 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002180 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2181 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002182 if (Result.isInvalid())
2183 return TemplateArgumentLoc();
2184
2185 return TemplateArgumentLoc(Result.get(), Result.get());
2186 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002187
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002188 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002189 return TemplateArgumentLoc(TemplateArgument(
2190 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002191 NumExpansions),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002192 Pattern.getTemplateQualifierRange(),
2193 Pattern.getTemplateNameLoc(),
2194 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002195
2196 case TemplateArgument::Null:
2197 case TemplateArgument::Integral:
2198 case TemplateArgument::Declaration:
2199 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002200 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002201 llvm_unreachable("Pack expansion pattern has no parameter packs");
2202
2203 case TemplateArgument::Type:
2204 if (TypeSourceInfo *Expansion
2205 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002206 EllipsisLoc,
2207 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002208 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2209 Expansion);
2210 break;
2211 }
2212
2213 return TemplateArgumentLoc();
2214 }
2215
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002216 /// \brief Build a new expression pack expansion.
2217 ///
2218 /// By default, performs semantic analysis to build a new pack expansion
2219 /// for an expression. Subclasses may override this routine to provide
2220 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002221 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2222 llvm::Optional<unsigned> NumExpansions) {
2223 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002224 }
2225
John McCall43fed0d2010-11-12 08:19:04 +00002226private:
2227 QualType TransformTypeInObjectScope(QualType T,
2228 QualType ObjectType,
2229 NamedDecl *FirstQualifierInScope,
2230 NestedNameSpecifier *Prefix);
2231
2232 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2233 QualType ObjectType,
2234 NamedDecl *FirstQualifierInScope,
2235 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002236};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002237
Douglas Gregor43959a92009-08-20 07:17:43 +00002238template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002239StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002240 if (!S)
2241 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002242
Douglas Gregor43959a92009-08-20 07:17:43 +00002243 switch (S->getStmtClass()) {
2244 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002245
Douglas Gregor43959a92009-08-20 07:17:43 +00002246 // Transform individual statement nodes
2247#define STMT(Node, Parent) \
2248 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2249#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002250#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002251
Douglas Gregor43959a92009-08-20 07:17:43 +00002252 // Transform expressions by calling TransformExpr.
2253#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002254#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002255#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002256#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002257 {
John McCall60d7b3a2010-08-24 06:29:42 +00002258 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002259 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002260 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002261
John McCall9ae2f072010-08-23 23:25:46 +00002262 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002263 }
Mike Stump1eb44332009-09-09 15:08:12 +00002264 }
2265
John McCall3fa5cae2010-10-26 07:05:15 +00002266 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002267}
Mike Stump1eb44332009-09-09 15:08:12 +00002268
2269
Douglas Gregor670444e2009-08-04 22:27:00 +00002270template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002271ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002272 if (!E)
2273 return SemaRef.Owned(E);
2274
2275 switch (E->getStmtClass()) {
2276 case Stmt::NoStmtClass: break;
2277#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002278#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002279#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002280 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002281#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002282 }
2283
John McCall3fa5cae2010-10-26 07:05:15 +00002284 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002285}
2286
2287template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002288bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2289 unsigned NumInputs,
2290 bool IsCall,
2291 llvm::SmallVectorImpl<Expr *> &Outputs,
2292 bool *ArgChanged) {
2293 for (unsigned I = 0; I != NumInputs; ++I) {
2294 // If requested, drop call arguments that need to be dropped.
2295 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2296 if (ArgChanged)
2297 *ArgChanged = true;
2298
2299 break;
2300 }
2301
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002302 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2303 Expr *Pattern = Expansion->getPattern();
2304
2305 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2306 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2307 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2308
2309 // Determine whether the set of unexpanded parameter packs can and should
2310 // be expanded.
2311 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002312 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002313 llvm::Optional<unsigned> OrigNumExpansions
2314 = Expansion->getNumExpansions();
2315 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002316 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2317 Pattern->getSourceRange(),
2318 Unexpanded.data(),
2319 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002320 Expand, RetainExpansion,
2321 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002322 return true;
2323
2324 if (!Expand) {
2325 // The transform has determined that we should perform a simple
2326 // transformation on the pack expansion, producing another pack
2327 // expansion.
2328 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2329 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2330 if (OutPattern.isInvalid())
2331 return true;
2332
2333 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002334 Expansion->getEllipsisLoc(),
2335 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002336 if (Out.isInvalid())
2337 return true;
2338
2339 if (ArgChanged)
2340 *ArgChanged = true;
2341 Outputs.push_back(Out.get());
2342 continue;
2343 }
2344
2345 // The transform has determined that we should perform an elementwise
2346 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002347 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002348 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2349 ExprResult Out = getDerived().TransformExpr(Pattern);
2350 if (Out.isInvalid())
2351 return true;
2352
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002353 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002354 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2355 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002356 if (Out.isInvalid())
2357 return true;
2358 }
2359
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002360 if (ArgChanged)
2361 *ArgChanged = true;
2362 Outputs.push_back(Out.get());
2363 }
2364
2365 continue;
2366 }
2367
Douglas Gregoraa165f82011-01-03 19:04:46 +00002368 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2369 if (Result.isInvalid())
2370 return true;
2371
2372 if (Result.get() != Inputs[I] && ArgChanged)
2373 *ArgChanged = true;
2374
2375 Outputs.push_back(Result.get());
2376 }
2377
2378 return false;
2379}
2380
2381template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002382NestedNameSpecifier *
2383TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002384 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002385 QualType ObjectType,
2386 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002387 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002388
Douglas Gregor43959a92009-08-20 07:17:43 +00002389 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002390 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002391 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002392 ObjectType,
2393 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002394 if (!Prefix)
2395 return 0;
2396 }
Mike Stump1eb44332009-09-09 15:08:12 +00002397
Douglas Gregordcee1a12009-08-06 05:28:30 +00002398 switch (NNS->getKind()) {
2399 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002400 if (Prefix) {
2401 // The object type and qualifier-in-scope really apply to the
2402 // leftmost entity.
2403 ObjectType = QualType();
2404 FirstQualifierInScope = 0;
2405 }
2406
Mike Stump1eb44332009-09-09 15:08:12 +00002407 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002408 "Identifier nested-name-specifier with no prefix or object type");
2409 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2410 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002411 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002412
2413 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002414 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002415 ObjectType,
2416 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002417
Douglas Gregordcee1a12009-08-06 05:28:30 +00002418 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002419 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002420 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002421 getDerived().TransformDecl(Range.getBegin(),
2422 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002423 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002424 Prefix == NNS->getPrefix() &&
2425 NS == NNS->getAsNamespace())
2426 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Douglas Gregordcee1a12009-08-06 05:28:30 +00002428 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2429 }
Mike Stump1eb44332009-09-09 15:08:12 +00002430
Douglas Gregordcee1a12009-08-06 05:28:30 +00002431 case NestedNameSpecifier::Global:
2432 // There is no meaningful transformation that one could perform on the
2433 // global scope.
2434 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002435
Douglas Gregordcee1a12009-08-06 05:28:30 +00002436 case NestedNameSpecifier::TypeSpecWithTemplate:
2437 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002438 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002439 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2440 ObjectType,
2441 FirstQualifierInScope,
2442 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002443 if (T.isNull())
2444 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002445
Douglas Gregordcee1a12009-08-06 05:28:30 +00002446 if (!getDerived().AlwaysRebuild() &&
2447 Prefix == NNS->getPrefix() &&
2448 T == QualType(NNS->getAsType(), 0))
2449 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002450
2451 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2452 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002453 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002454 }
2455 }
Mike Stump1eb44332009-09-09 15:08:12 +00002456
Douglas Gregordcee1a12009-08-06 05:28:30 +00002457 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002458 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002459}
2460
2461template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002462DeclarationNameInfo
2463TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002464::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002465 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002466 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002467 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002468
2469 switch (Name.getNameKind()) {
2470 case DeclarationName::Identifier:
2471 case DeclarationName::ObjCZeroArgSelector:
2472 case DeclarationName::ObjCOneArgSelector:
2473 case DeclarationName::ObjCMultiArgSelector:
2474 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002475 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002476 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002477 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002478
Douglas Gregor81499bb2009-09-03 22:13:48 +00002479 case DeclarationName::CXXConstructorName:
2480 case DeclarationName::CXXDestructorName:
2481 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002482 TypeSourceInfo *NewTInfo;
2483 CanQualType NewCanTy;
2484 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002485 NewTInfo = getDerived().TransformType(OldTInfo);
2486 if (!NewTInfo)
2487 return DeclarationNameInfo();
2488 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002489 }
2490 else {
2491 NewTInfo = 0;
2492 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002493 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002494 if (NewT.isNull())
2495 return DeclarationNameInfo();
2496 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2497 }
Mike Stump1eb44332009-09-09 15:08:12 +00002498
Abramo Bagnara25777432010-08-11 22:01:17 +00002499 DeclarationName NewName
2500 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2501 NewCanTy);
2502 DeclarationNameInfo NewNameInfo(NameInfo);
2503 NewNameInfo.setName(NewName);
2504 NewNameInfo.setNamedTypeInfo(NewTInfo);
2505 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002506 }
Mike Stump1eb44332009-09-09 15:08:12 +00002507 }
2508
Abramo Bagnara25777432010-08-11 22:01:17 +00002509 assert(0 && "Unknown name kind.");
2510 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002511}
2512
2513template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002514TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002515TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002516 QualType ObjectType,
2517 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002518 SourceLocation Loc = getDerived().getBaseLocation();
2519
Douglas Gregord1067e52009-08-06 06:41:21 +00002520 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002521 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002522 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002523 /*FIXME*/ SourceRange(Loc),
2524 ObjectType,
2525 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002526 if (!NNS)
2527 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002528
Douglas Gregord1067e52009-08-06 06:41:21 +00002529 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002530 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002531 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002532 if (!TransTemplate)
2533 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002534
Douglas Gregord1067e52009-08-06 06:41:21 +00002535 if (!getDerived().AlwaysRebuild() &&
2536 NNS == QTN->getQualifier() &&
2537 TransTemplate == Template)
2538 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002539
Douglas Gregord1067e52009-08-06 06:41:21 +00002540 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2541 TransTemplate);
2542 }
Mike Stump1eb44332009-09-09 15:08:12 +00002543
John McCallf7a1a742009-11-24 19:00:30 +00002544 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002545 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002546 }
Mike Stump1eb44332009-09-09 15:08:12 +00002547
Douglas Gregord1067e52009-08-06 06:41:21 +00002548 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002549 NestedNameSpecifier *NNS = DTN->getQualifier();
2550 if (NNS) {
2551 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2552 /*FIXME:*/SourceRange(Loc),
2553 ObjectType,
2554 FirstQualifierInScope);
2555 if (!NNS) return TemplateName();
2556
2557 // These apply to the scope specifier, not the template.
2558 ObjectType = QualType();
2559 FirstQualifierInScope = 0;
2560 }
Mike Stump1eb44332009-09-09 15:08:12 +00002561
Douglas Gregord1067e52009-08-06 06:41:21 +00002562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002563 NNS == DTN->getQualifier() &&
2564 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002565 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002566
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002567 if (DTN->isIdentifier()) {
2568 // FIXME: Bad range
2569 SourceRange QualifierRange(getDerived().getBaseLocation());
2570 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2571 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002572 ObjectType,
2573 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002574 }
Sean Huntc3021132010-05-05 15:23:54 +00002575
2576 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002577 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002578 }
Mike Stump1eb44332009-09-09 15:08:12 +00002579
Douglas Gregord1067e52009-08-06 06:41:21 +00002580 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002581 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002582 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002583 if (!TransTemplate)
2584 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002585
Douglas Gregord1067e52009-08-06 06:41:21 +00002586 if (!getDerived().AlwaysRebuild() &&
2587 TransTemplate == Template)
2588 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002589
Douglas Gregord1067e52009-08-06 06:41:21 +00002590 return TemplateName(TransTemplate);
2591 }
Mike Stump1eb44332009-09-09 15:08:12 +00002592
John McCallf7a1a742009-11-24 19:00:30 +00002593 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002594 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002595 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002596}
2597
2598template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002599void TreeTransform<Derived>::InventTemplateArgumentLoc(
2600 const TemplateArgument &Arg,
2601 TemplateArgumentLoc &Output) {
2602 SourceLocation Loc = getDerived().getBaseLocation();
2603 switch (Arg.getKind()) {
2604 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002605 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002606 break;
2607
2608 case TemplateArgument::Type:
2609 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002610 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002611
John McCall833ca992009-10-29 08:12:44 +00002612 break;
2613
Douglas Gregor788cd062009-11-11 01:00:40 +00002614 case TemplateArgument::Template:
2615 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2616 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002617
2618 case TemplateArgument::TemplateExpansion:
2619 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2620 break;
2621
John McCall833ca992009-10-29 08:12:44 +00002622 case TemplateArgument::Expression:
2623 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2624 break;
2625
2626 case TemplateArgument::Declaration:
2627 case TemplateArgument::Integral:
2628 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002629 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002630 break;
2631 }
2632}
2633
2634template<typename Derived>
2635bool TreeTransform<Derived>::TransformTemplateArgument(
2636 const TemplateArgumentLoc &Input,
2637 TemplateArgumentLoc &Output) {
2638 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002639 switch (Arg.getKind()) {
2640 case TemplateArgument::Null:
2641 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002642 Output = Input;
2643 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002644
Douglas Gregor670444e2009-08-04 22:27:00 +00002645 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002646 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002647 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002648 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002649
2650 DI = getDerived().TransformType(DI);
2651 if (!DI) return true;
2652
2653 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2654 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002655 }
Mike Stump1eb44332009-09-09 15:08:12 +00002656
Douglas Gregor670444e2009-08-04 22:27:00 +00002657 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002658 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002659 DeclarationName Name;
2660 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2661 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002662 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002663 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002664 if (!D) return true;
2665
John McCall828bff22009-10-29 18:45:58 +00002666 Expr *SourceExpr = Input.getSourceDeclExpression();
2667 if (SourceExpr) {
2668 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002669 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002670 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002671 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002672 }
2673
2674 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002675 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002676 }
Mike Stump1eb44332009-09-09 15:08:12 +00002677
Douglas Gregor788cd062009-11-11 01:00:40 +00002678 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002679 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002680 TemplateName Template
2681 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2682 if (Template.isNull())
2683 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002684
Douglas Gregor788cd062009-11-11 01:00:40 +00002685 Output = TemplateArgumentLoc(TemplateArgument(Template),
2686 Input.getTemplateQualifierRange(),
2687 Input.getTemplateNameLoc());
2688 return false;
2689 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002690
2691 case TemplateArgument::TemplateExpansion:
2692 llvm_unreachable("Caller should expand pack expansions");
2693
Douglas Gregor670444e2009-08-04 22:27:00 +00002694 case TemplateArgument::Expression: {
2695 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002696 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002697 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002698
John McCall833ca992009-10-29 08:12:44 +00002699 Expr *InputExpr = Input.getSourceExpression();
2700 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2701
John McCall60d7b3a2010-08-24 06:29:42 +00002702 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002703 = getDerived().TransformExpr(InputExpr);
2704 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002705 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002706 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002707 }
Mike Stump1eb44332009-09-09 15:08:12 +00002708
Douglas Gregor670444e2009-08-04 22:27:00 +00002709 case TemplateArgument::Pack: {
2710 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2711 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002712 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002713 AEnd = Arg.pack_end();
2714 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002715
John McCall833ca992009-10-29 08:12:44 +00002716 // FIXME: preserve source information here when we start
2717 // caring about parameter packs.
2718
John McCall828bff22009-10-29 18:45:58 +00002719 TemplateArgumentLoc InputArg;
2720 TemplateArgumentLoc OutputArg;
2721 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2722 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002723 return true;
2724
John McCall828bff22009-10-29 18:45:58 +00002725 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002726 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002727
2728 TemplateArgument *TransformedArgsPtr
2729 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2730 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2731 TransformedArgsPtr);
2732 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2733 TransformedArgs.size()),
2734 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002735 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002736 }
2737 }
Mike Stump1eb44332009-09-09 15:08:12 +00002738
Douglas Gregor670444e2009-08-04 22:27:00 +00002739 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002740 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002741}
2742
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002743/// \brief Iterator adaptor that invents template argument location information
2744/// for each of the template arguments in its underlying iterator.
2745template<typename Derived, typename InputIterator>
2746class TemplateArgumentLocInventIterator {
2747 TreeTransform<Derived> &Self;
2748 InputIterator Iter;
2749
2750public:
2751 typedef TemplateArgumentLoc value_type;
2752 typedef TemplateArgumentLoc reference;
2753 typedef typename std::iterator_traits<InputIterator>::difference_type
2754 difference_type;
2755 typedef std::input_iterator_tag iterator_category;
2756
2757 class pointer {
2758 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002759
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002760 public:
2761 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2762
2763 const TemplateArgumentLoc *operator->() const { return &Arg; }
2764 };
2765
2766 TemplateArgumentLocInventIterator() { }
2767
2768 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2769 InputIterator Iter)
2770 : Self(Self), Iter(Iter) { }
2771
2772 TemplateArgumentLocInventIterator &operator++() {
2773 ++Iter;
2774 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002775 }
2776
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002777 TemplateArgumentLocInventIterator operator++(int) {
2778 TemplateArgumentLocInventIterator Old(*this);
2779 ++(*this);
2780 return Old;
2781 }
2782
2783 reference operator*() const {
2784 TemplateArgumentLoc Result;
2785 Self.InventTemplateArgumentLoc(*Iter, Result);
2786 return Result;
2787 }
2788
2789 pointer operator->() const { return pointer(**this); }
2790
2791 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2792 const TemplateArgumentLocInventIterator &Y) {
2793 return X.Iter == Y.Iter;
2794 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002795
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002796 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2797 const TemplateArgumentLocInventIterator &Y) {
2798 return X.Iter != Y.Iter;
2799 }
2800};
2801
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002802template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002803template<typename InputIterator>
2804bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2805 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002806 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002807 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002808 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002809 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002810
2811 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2812 // Unpack argument packs, which we translate them into separate
2813 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002814 // FIXME: We could do much better if we could guarantee that the
2815 // TemplateArgumentLocInfo for the pack expansion would be usable for
2816 // all of the template arguments in the argument pack.
2817 typedef TemplateArgumentLocInventIterator<Derived,
2818 TemplateArgument::pack_iterator>
2819 PackLocIterator;
2820 if (TransformTemplateArguments(PackLocIterator(*this,
2821 In.getArgument().pack_begin()),
2822 PackLocIterator(*this,
2823 In.getArgument().pack_end()),
2824 Outputs))
2825 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002826
2827 continue;
2828 }
2829
2830 if (In.getArgument().isPackExpansion()) {
2831 // We have a pack expansion, for which we will be substituting into
2832 // the pattern.
2833 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002834 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002835 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00002836 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2837 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002838
2839 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2840 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2841 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2842
2843 // Determine whether the set of unexpanded parameter packs can and should
2844 // be expanded.
2845 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002846 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002847 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002848 if (getDerived().TryExpandParameterPacks(Ellipsis,
2849 Pattern.getSourceRange(),
2850 Unexpanded.data(),
2851 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002852 Expand,
2853 RetainExpansion,
2854 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002855 return true;
2856
2857 if (!Expand) {
2858 // The transform has determined that we should perform a simple
2859 // transformation on the pack expansion, producing another pack
2860 // expansion.
2861 TemplateArgumentLoc OutPattern;
2862 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2863 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2864 return true;
2865
Douglas Gregorcded4f62011-01-14 17:04:44 +00002866 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2867 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002868 if (Out.getArgument().isNull())
2869 return true;
2870
2871 Outputs.addArgument(Out);
2872 continue;
2873 }
2874
2875 // The transform has determined that we should perform an elementwise
2876 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002877 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002878 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2879
2880 if (getDerived().TransformTemplateArgument(Pattern, Out))
2881 return true;
2882
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002883 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00002884 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2885 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002886 if (Out.getArgument().isNull())
2887 return true;
2888 }
2889
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002890 Outputs.addArgument(Out);
2891 }
2892
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002893 // If we're supposed to retain a pack expansion, do so by temporarily
2894 // forgetting the partially-substituted parameter pack.
2895 if (RetainExpansion) {
2896 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2897
2898 if (getDerived().TransformTemplateArgument(Pattern, Out))
2899 return true;
2900
Douglas Gregorcded4f62011-01-14 17:04:44 +00002901 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2902 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002903 if (Out.getArgument().isNull())
2904 return true;
2905
2906 Outputs.addArgument(Out);
2907 }
Douglas Gregord3731192011-01-10 07:32:04 +00002908
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002909 continue;
2910 }
2911
2912 // The simple case:
2913 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002914 return true;
2915
2916 Outputs.addArgument(Out);
2917 }
2918
2919 return false;
2920
2921}
2922
Douglas Gregor577f75a2009-08-04 16:50:30 +00002923//===----------------------------------------------------------------------===//
2924// Type transformation
2925//===----------------------------------------------------------------------===//
2926
2927template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002928QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002929 if (getDerived().AlreadyTransformed(T))
2930 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002931
John McCalla2becad2009-10-21 00:40:46 +00002932 // Temporary workaround. All of these transformations should
2933 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002934 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002935 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002936
John McCall43fed0d2010-11-12 08:19:04 +00002937 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002938
John McCalla2becad2009-10-21 00:40:46 +00002939 if (!NewDI)
2940 return QualType();
2941
2942 return NewDI->getType();
2943}
2944
2945template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002946TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002947 if (getDerived().AlreadyTransformed(DI->getType()))
2948 return DI;
2949
2950 TypeLocBuilder TLB;
2951
2952 TypeLoc TL = DI->getTypeLoc();
2953 TLB.reserve(TL.getFullDataSize());
2954
John McCall43fed0d2010-11-12 08:19:04 +00002955 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002956 if (Result.isNull())
2957 return 0;
2958
John McCalla93c9342009-12-07 02:54:59 +00002959 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002960}
2961
2962template<typename Derived>
2963QualType
John McCall43fed0d2010-11-12 08:19:04 +00002964TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002965 switch (T.getTypeLocClass()) {
2966#define ABSTRACT_TYPELOC(CLASS, PARENT)
2967#define TYPELOC(CLASS, PARENT) \
2968 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002969 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002970#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002971 }
Mike Stump1eb44332009-09-09 15:08:12 +00002972
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002973 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002974 return QualType();
2975}
2976
2977/// FIXME: By default, this routine adds type qualifiers only to types
2978/// that can have qualifiers, and silently suppresses those qualifiers
2979/// that are not permitted (e.g., qualifiers on reference or function
2980/// types). This is the right thing for template instantiation, but
2981/// probably not for other clients.
2982template<typename Derived>
2983QualType
2984TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002985 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002986 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002987
John McCall43fed0d2010-11-12 08:19:04 +00002988 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002989 if (Result.isNull())
2990 return QualType();
2991
2992 // Silently suppress qualifiers if the result type can't be qualified.
2993 // FIXME: this is the right thing for template instantiation, but
2994 // probably not for other clients.
2995 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002996 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002997
John McCall28654742010-06-05 06:41:15 +00002998 if (!Quals.empty()) {
2999 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3000 TLB.push<QualifiedTypeLoc>(Result);
3001 // No location information to preserve.
3002 }
John McCalla2becad2009-10-21 00:40:46 +00003003
3004 return Result;
3005}
3006
John McCall43fed0d2010-11-12 08:19:04 +00003007/// \brief Transforms a type that was written in a scope specifier,
3008/// given an object type, the results of unqualified lookup, and
3009/// an already-instantiated prefix.
3010///
3011/// The object type is provided iff the scope specifier qualifies the
3012/// member of a dependent member-access expression. The prefix is
3013/// provided iff the the scope specifier in which this appears has a
3014/// prefix.
3015///
3016/// This is private to TreeTransform.
3017template<typename Derived>
3018QualType
3019TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3020 QualType ObjectType,
3021 NamedDecl *UnqualLookup,
3022 NestedNameSpecifier *Prefix) {
3023 if (getDerived().AlreadyTransformed(T))
3024 return T;
3025
3026 TypeSourceInfo *TSI =
3027 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
3028
3029 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3030 UnqualLookup, Prefix);
3031 if (!TSI) return QualType();
3032 return TSI->getType();
3033}
3034
3035template<typename Derived>
3036TypeSourceInfo *
3037TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3038 QualType ObjectType,
3039 NamedDecl *UnqualLookup,
3040 NestedNameSpecifier *Prefix) {
3041 // TODO: in some cases, we might be some verification to do here.
3042 if (ObjectType.isNull())
3043 return getDerived().TransformType(TSI);
3044
3045 QualType T = TSI->getType();
3046 if (getDerived().AlreadyTransformed(T))
3047 return TSI;
3048
3049 TypeLocBuilder TLB;
3050 QualType Result;
3051
3052 if (isa<TemplateSpecializationType>(T)) {
3053 TemplateSpecializationTypeLoc TL
3054 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3055
3056 TemplateName Template =
3057 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3058 ObjectType, UnqualLookup);
3059 if (Template.isNull()) return 0;
3060
3061 Result = getDerived()
3062 .TransformTemplateSpecializationType(TLB, TL, Template);
3063 } else if (isa<DependentTemplateSpecializationType>(T)) {
3064 DependentTemplateSpecializationTypeLoc TL
3065 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3066
3067 Result = getDerived()
3068 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3069 } else {
3070 // Nothing special needs to be done for these.
3071 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3072 }
3073
3074 if (Result.isNull()) return 0;
3075 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3076}
3077
John McCalla2becad2009-10-21 00:40:46 +00003078template <class TyLoc> static inline
3079QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3080 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3081 NewT.setNameLoc(T.getNameLoc());
3082 return T.getType();
3083}
3084
John McCalla2becad2009-10-21 00:40:46 +00003085template<typename Derived>
3086QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003087 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003088 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3089 NewT.setBuiltinLoc(T.getBuiltinLoc());
3090 if (T.needsExtraLocalData())
3091 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3092 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003093}
Mike Stump1eb44332009-09-09 15:08:12 +00003094
Douglas Gregor577f75a2009-08-04 16:50:30 +00003095template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003097 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003098 // FIXME: recurse?
3099 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003100}
Mike Stump1eb44332009-09-09 15:08:12 +00003101
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003103QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003104 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003105 QualType PointeeType
3106 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003107 if (PointeeType.isNull())
3108 return QualType();
3109
3110 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003111 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003112 // A dependent pointer type 'T *' has is being transformed such
3113 // that an Objective-C class type is being replaced for 'T'. The
3114 // resulting pointer type is an ObjCObjectPointerType, not a
3115 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003116 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003117
John McCallc12c5bb2010-05-15 11:32:37 +00003118 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3119 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003120 return Result;
3121 }
John McCall43fed0d2010-11-12 08:19:04 +00003122
Douglas Gregor92e986e2010-04-22 16:44:27 +00003123 if (getDerived().AlwaysRebuild() ||
3124 PointeeType != TL.getPointeeLoc().getType()) {
3125 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3126 if (Result.isNull())
3127 return QualType();
3128 }
Sean Huntc3021132010-05-05 15:23:54 +00003129
Douglas Gregor92e986e2010-04-22 16:44:27 +00003130 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3131 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003132 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003133}
Mike Stump1eb44332009-09-09 15:08:12 +00003134
3135template<typename Derived>
3136QualType
John McCalla2becad2009-10-21 00:40:46 +00003137TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003138 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003139 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003140 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3141 if (PointeeType.isNull())
3142 return QualType();
3143
3144 QualType Result = TL.getType();
3145 if (getDerived().AlwaysRebuild() ||
3146 PointeeType != TL.getPointeeLoc().getType()) {
3147 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003148 TL.getSigilLoc());
3149 if (Result.isNull())
3150 return QualType();
3151 }
3152
Douglas Gregor39968ad2010-04-22 16:50:51 +00003153 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003154 NewT.setSigilLoc(TL.getSigilLoc());
3155 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003156}
3157
John McCall85737a72009-10-30 00:06:24 +00003158/// Transforms a reference type. Note that somewhat paradoxically we
3159/// don't care whether the type itself is an l-value type or an r-value
3160/// type; we only care if the type was *written* as an l-value type
3161/// or an r-value type.
3162template<typename Derived>
3163QualType
3164TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003165 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003166 const ReferenceType *T = TL.getTypePtr();
3167
3168 // Note that this works with the pointee-as-written.
3169 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3170 if (PointeeType.isNull())
3171 return QualType();
3172
3173 QualType Result = TL.getType();
3174 if (getDerived().AlwaysRebuild() ||
3175 PointeeType != T->getPointeeTypeAsWritten()) {
3176 Result = getDerived().RebuildReferenceType(PointeeType,
3177 T->isSpelledAsLValue(),
3178 TL.getSigilLoc());
3179 if (Result.isNull())
3180 return QualType();
3181 }
3182
3183 // r-value references can be rebuilt as l-value references.
3184 ReferenceTypeLoc NewTL;
3185 if (isa<LValueReferenceType>(Result))
3186 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3187 else
3188 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3189 NewTL.setSigilLoc(TL.getSigilLoc());
3190
3191 return Result;
3192}
3193
Mike Stump1eb44332009-09-09 15:08:12 +00003194template<typename Derived>
3195QualType
John McCalla2becad2009-10-21 00:40:46 +00003196TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003197 LValueReferenceTypeLoc TL) {
3198 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003199}
3200
Mike Stump1eb44332009-09-09 15:08:12 +00003201template<typename Derived>
3202QualType
John McCalla2becad2009-10-21 00:40:46 +00003203TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003204 RValueReferenceTypeLoc TL) {
3205 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003206}
Mike Stump1eb44332009-09-09 15:08:12 +00003207
Douglas Gregor577f75a2009-08-04 16:50:30 +00003208template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003209QualType
John McCalla2becad2009-10-21 00:40:46 +00003210TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003211 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003212 MemberPointerType *T = TL.getTypePtr();
3213
3214 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003215 if (PointeeType.isNull())
3216 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003217
John McCalla2becad2009-10-21 00:40:46 +00003218 // TODO: preserve source information for this.
3219 QualType ClassType
3220 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003221 if (ClassType.isNull())
3222 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003223
John McCalla2becad2009-10-21 00:40:46 +00003224 QualType Result = TL.getType();
3225 if (getDerived().AlwaysRebuild() ||
3226 PointeeType != T->getPointeeType() ||
3227 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003228 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3229 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003230 if (Result.isNull())
3231 return QualType();
3232 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003233
John McCalla2becad2009-10-21 00:40:46 +00003234 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3235 NewTL.setSigilLoc(TL.getSigilLoc());
3236
3237 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003238}
3239
Mike Stump1eb44332009-09-09 15:08:12 +00003240template<typename Derived>
3241QualType
John McCalla2becad2009-10-21 00:40:46 +00003242TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003243 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003244 ConstantArrayType *T = TL.getTypePtr();
3245 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003246 if (ElementType.isNull())
3247 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003248
John McCalla2becad2009-10-21 00:40:46 +00003249 QualType Result = TL.getType();
3250 if (getDerived().AlwaysRebuild() ||
3251 ElementType != T->getElementType()) {
3252 Result = getDerived().RebuildConstantArrayType(ElementType,
3253 T->getSizeModifier(),
3254 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003255 T->getIndexTypeCVRQualifiers(),
3256 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003257 if (Result.isNull())
3258 return QualType();
3259 }
Sean Huntc3021132010-05-05 15:23:54 +00003260
John McCalla2becad2009-10-21 00:40:46 +00003261 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3262 NewTL.setLBracketLoc(TL.getLBracketLoc());
3263 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003264
John McCalla2becad2009-10-21 00:40:46 +00003265 Expr *Size = TL.getSizeExpr();
3266 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003267 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003268 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3269 }
3270 NewTL.setSizeExpr(Size);
3271
3272 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003273}
Mike Stump1eb44332009-09-09 15:08:12 +00003274
Douglas Gregor577f75a2009-08-04 16:50:30 +00003275template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003276QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003277 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003278 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003279 IncompleteArrayType *T = TL.getTypePtr();
3280 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003281 if (ElementType.isNull())
3282 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003283
John McCalla2becad2009-10-21 00:40:46 +00003284 QualType Result = TL.getType();
3285 if (getDerived().AlwaysRebuild() ||
3286 ElementType != T->getElementType()) {
3287 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003288 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003289 T->getIndexTypeCVRQualifiers(),
3290 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003291 if (Result.isNull())
3292 return QualType();
3293 }
Sean Huntc3021132010-05-05 15:23:54 +00003294
John McCalla2becad2009-10-21 00:40:46 +00003295 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3296 NewTL.setLBracketLoc(TL.getLBracketLoc());
3297 NewTL.setRBracketLoc(TL.getRBracketLoc());
3298 NewTL.setSizeExpr(0);
3299
3300 return Result;
3301}
3302
3303template<typename Derived>
3304QualType
3305TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003306 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003307 VariableArrayType *T = TL.getTypePtr();
3308 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3309 if (ElementType.isNull())
3310 return QualType();
3311
3312 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003313 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003314
John McCall60d7b3a2010-08-24 06:29:42 +00003315 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003316 = getDerived().TransformExpr(T->getSizeExpr());
3317 if (SizeResult.isInvalid())
3318 return QualType();
3319
John McCall9ae2f072010-08-23 23:25:46 +00003320 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003321
3322 QualType Result = TL.getType();
3323 if (getDerived().AlwaysRebuild() ||
3324 ElementType != T->getElementType() ||
3325 Size != T->getSizeExpr()) {
3326 Result = getDerived().RebuildVariableArrayType(ElementType,
3327 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003328 Size,
John McCalla2becad2009-10-21 00:40:46 +00003329 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003330 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003331 if (Result.isNull())
3332 return QualType();
3333 }
Sean Huntc3021132010-05-05 15:23:54 +00003334
John McCalla2becad2009-10-21 00:40:46 +00003335 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3336 NewTL.setLBracketLoc(TL.getLBracketLoc());
3337 NewTL.setRBracketLoc(TL.getRBracketLoc());
3338 NewTL.setSizeExpr(Size);
3339
3340 return Result;
3341}
3342
3343template<typename Derived>
3344QualType
3345TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003346 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003347 DependentSizedArrayType *T = TL.getTypePtr();
3348 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3349 if (ElementType.isNull())
3350 return QualType();
3351
3352 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003353 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003354
John McCall60d7b3a2010-08-24 06:29:42 +00003355 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003356 = getDerived().TransformExpr(T->getSizeExpr());
3357 if (SizeResult.isInvalid())
3358 return QualType();
3359
3360 Expr *Size = static_cast<Expr*>(SizeResult.get());
3361
3362 QualType Result = TL.getType();
3363 if (getDerived().AlwaysRebuild() ||
3364 ElementType != T->getElementType() ||
3365 Size != T->getSizeExpr()) {
3366 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3367 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003368 Size,
John McCalla2becad2009-10-21 00:40:46 +00003369 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003370 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003371 if (Result.isNull())
3372 return QualType();
3373 }
3374 else SizeResult.take();
3375
3376 // We might have any sort of array type now, but fortunately they
3377 // all have the same location layout.
3378 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3379 NewTL.setLBracketLoc(TL.getLBracketLoc());
3380 NewTL.setRBracketLoc(TL.getRBracketLoc());
3381 NewTL.setSizeExpr(Size);
3382
3383 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003384}
Mike Stump1eb44332009-09-09 15:08:12 +00003385
3386template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003387QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003388 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003389 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003390 DependentSizedExtVectorType *T = TL.getTypePtr();
3391
3392 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003393 QualType ElementType = getDerived().TransformType(T->getElementType());
3394 if (ElementType.isNull())
3395 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003396
Douglas Gregor670444e2009-08-04 22:27:00 +00003397 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003398 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003399
John McCall60d7b3a2010-08-24 06:29:42 +00003400 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003401 if (Size.isInvalid())
3402 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003403
John McCalla2becad2009-10-21 00:40:46 +00003404 QualType Result = TL.getType();
3405 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003406 ElementType != T->getElementType() ||
3407 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003408 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003409 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003410 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003411 if (Result.isNull())
3412 return QualType();
3413 }
John McCalla2becad2009-10-21 00:40:46 +00003414
3415 // Result might be dependent or not.
3416 if (isa<DependentSizedExtVectorType>(Result)) {
3417 DependentSizedExtVectorTypeLoc NewTL
3418 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3419 NewTL.setNameLoc(TL.getNameLoc());
3420 } else {
3421 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3422 NewTL.setNameLoc(TL.getNameLoc());
3423 }
3424
3425 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003426}
Mike Stump1eb44332009-09-09 15:08:12 +00003427
3428template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003429QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003430 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003431 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003432 QualType ElementType = getDerived().TransformType(T->getElementType());
3433 if (ElementType.isNull())
3434 return QualType();
3435
John McCalla2becad2009-10-21 00:40:46 +00003436 QualType Result = TL.getType();
3437 if (getDerived().AlwaysRebuild() ||
3438 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003439 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003440 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003441 if (Result.isNull())
3442 return QualType();
3443 }
Sean Huntc3021132010-05-05 15:23:54 +00003444
John McCalla2becad2009-10-21 00:40:46 +00003445 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3446 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003447
John McCalla2becad2009-10-21 00:40:46 +00003448 return Result;
3449}
3450
3451template<typename Derived>
3452QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003453 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003454 VectorType *T = TL.getTypePtr();
3455 QualType ElementType = getDerived().TransformType(T->getElementType());
3456 if (ElementType.isNull())
3457 return QualType();
3458
3459 QualType Result = TL.getType();
3460 if (getDerived().AlwaysRebuild() ||
3461 ElementType != T->getElementType()) {
3462 Result = getDerived().RebuildExtVectorType(ElementType,
3463 T->getNumElements(),
3464 /*FIXME*/ SourceLocation());
3465 if (Result.isNull())
3466 return QualType();
3467 }
Sean Huntc3021132010-05-05 15:23:54 +00003468
John McCalla2becad2009-10-21 00:40:46 +00003469 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3470 NewTL.setNameLoc(TL.getNameLoc());
3471
3472 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003473}
Mike Stump1eb44332009-09-09 15:08:12 +00003474
3475template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003476ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003477TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3478 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003479 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003480 TypeSourceInfo *NewDI = 0;
3481
3482 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3483 // If we're substituting into a pack expansion type and we know the
3484 TypeLoc OldTL = OldDI->getTypeLoc();
3485 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3486
3487 TypeLocBuilder TLB;
3488 TypeLoc NewTL = OldDI->getTypeLoc();
3489 TLB.reserve(NewTL.getFullDataSize());
3490
3491 QualType Result = getDerived().TransformType(TLB,
3492 OldExpansionTL.getPatternLoc());
3493 if (Result.isNull())
3494 return 0;
3495
3496 Result = RebuildPackExpansionType(Result,
3497 OldExpansionTL.getPatternLoc().getSourceRange(),
3498 OldExpansionTL.getEllipsisLoc(),
3499 NumExpansions);
3500 if (Result.isNull())
3501 return 0;
3502
3503 PackExpansionTypeLoc NewExpansionTL
3504 = TLB.push<PackExpansionTypeLoc>(Result);
3505 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3506 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3507 } else
3508 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003509 if (!NewDI)
3510 return 0;
3511
3512 if (NewDI == OldDI)
3513 return OldParm;
3514 else
3515 return ParmVarDecl::Create(SemaRef.Context,
3516 OldParm->getDeclContext(),
3517 OldParm->getLocation(),
3518 OldParm->getIdentifier(),
3519 NewDI->getType(),
3520 NewDI,
3521 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003522 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003523 /* DefArg */ NULL);
3524}
3525
3526template<typename Derived>
3527bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003528 TransformFunctionTypeParams(SourceLocation Loc,
3529 ParmVarDecl **Params, unsigned NumParams,
3530 const QualType *ParamTypes,
3531 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3532 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3533 for (unsigned i = 0; i != NumParams; ++i) {
3534 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003535 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003536 if (OldParm->isParameterPack()) {
3537 // We have a function parameter pack that may need to be expanded.
3538 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003539
Douglas Gregor603cfb42011-01-05 23:12:31 +00003540 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003541 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3542 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3543 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3544 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003545
3546 // Determine whether we should expand the parameter packs.
3547 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003548 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003549 llvm::Optional<unsigned> OrigNumExpansions
3550 = ExpansionTL.getTypePtr()->getNumExpansions();
3551 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003552 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3553 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003554 Unexpanded.data(),
3555 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003556 ShouldExpand,
3557 RetainExpansion,
3558 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003559 return true;
3560 }
3561
3562 if (ShouldExpand) {
3563 // Expand the function parameter pack into multiple, separate
3564 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003565 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003566 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003567 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3568 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003569 = getDerived().TransformFunctionTypeParam(OldParm,
3570 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003571 if (!NewParm)
3572 return true;
3573
Douglas Gregora009b592011-01-07 00:20:55 +00003574 OutParamTypes.push_back(NewParm->getType());
3575 if (PVars)
3576 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003577 }
Douglas Gregord3731192011-01-10 07:32:04 +00003578
3579 // If we're supposed to retain a pack expansion, do so by temporarily
3580 // forgetting the partially-substituted parameter pack.
3581 if (RetainExpansion) {
3582 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3583 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003584 = getDerived().TransformFunctionTypeParam(OldParm,
3585 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003586 if (!NewParm)
3587 return true;
3588
3589 OutParamTypes.push_back(NewParm->getType());
3590 if (PVars)
3591 PVars->push_back(NewParm);
3592 }
3593
Douglas Gregor603cfb42011-01-05 23:12:31 +00003594 // We're done with the pack expansion.
3595 continue;
3596 }
3597
3598 // We'll substitute the parameter now without expanding the pack
3599 // expansion.
3600 }
3601
3602 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003603 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3604 NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +00003605 if (!NewParm)
3606 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003607
Douglas Gregora009b592011-01-07 00:20:55 +00003608 OutParamTypes.push_back(NewParm->getType());
3609 if (PVars)
3610 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003611 continue;
3612 }
John McCall21ef0fa2010-03-11 09:03:00 +00003613
3614 // Deal with the possibility that we don't have a parameter
3615 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003616 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003617 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003618 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003619 if (const PackExpansionType *Expansion
3620 = dyn_cast<PackExpansionType>(OldType)) {
3621 // We have a function parameter pack that may need to be expanded.
3622 QualType Pattern = Expansion->getPattern();
3623 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3624 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3625
3626 // Determine whether we should expand the parameter packs.
3627 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003628 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003629 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003630 Unexpanded.data(),
3631 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003632 ShouldExpand,
3633 RetainExpansion,
3634 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003635 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003636 }
3637
3638 if (ShouldExpand) {
3639 // Expand the function parameter pack into multiple, separate
3640 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003641 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003642 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3643 QualType NewType = getDerived().TransformType(Pattern);
3644 if (NewType.isNull())
3645 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003646
Douglas Gregora009b592011-01-07 00:20:55 +00003647 OutParamTypes.push_back(NewType);
3648 if (PVars)
3649 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003650 }
3651
3652 // We're done with the pack expansion.
3653 continue;
3654 }
3655
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003656 // If we're supposed to retain a pack expansion, do so by temporarily
3657 // forgetting the partially-substituted parameter pack.
3658 if (RetainExpansion) {
3659 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3660 QualType NewType = getDerived().TransformType(Pattern);
3661 if (NewType.isNull())
3662 return true;
3663
3664 OutParamTypes.push_back(NewType);
3665 if (PVars)
3666 PVars->push_back(0);
3667 }
Douglas Gregord3731192011-01-10 07:32:04 +00003668
Douglas Gregor603cfb42011-01-05 23:12:31 +00003669 // We'll substitute the parameter now without expanding the pack
3670 // expansion.
3671 OldType = Expansion->getPattern();
3672 IsPackExpansion = true;
3673 }
3674
3675 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3676 QualType NewType = getDerived().TransformType(OldType);
3677 if (NewType.isNull())
3678 return true;
3679
3680 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003681 NewType = getSema().Context.getPackExpansionType(NewType,
3682 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003683
Douglas Gregora009b592011-01-07 00:20:55 +00003684 OutParamTypes.push_back(NewType);
3685 if (PVars)
3686 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003687 }
3688
3689 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003690 }
John McCall21ef0fa2010-03-11 09:03:00 +00003691
3692template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003693QualType
John McCalla2becad2009-10-21 00:40:46 +00003694TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003695 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003696 // Transform the parameters and return type.
3697 //
3698 // We instantiate in source order, with the return type first followed by
3699 // the parameters, because users tend to expect this (even if they shouldn't
3700 // rely on it!).
3701 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003702 // When the function has a trailing return type, we instantiate the
3703 // parameters before the return type, since the return type can then refer
3704 // to the parameters themselves (via decltype, sizeof, etc.).
3705 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003706 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003707 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003708 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003709
Douglas Gregordab60ad2010-10-01 18:44:50 +00003710 QualType ResultType;
3711
3712 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003713 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3714 TL.getParmArray(),
3715 TL.getNumArgs(),
3716 TL.getTypePtr()->arg_type_begin(),
3717 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003718 return QualType();
3719
3720 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3721 if (ResultType.isNull())
3722 return QualType();
3723 }
3724 else {
3725 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3726 if (ResultType.isNull())
3727 return QualType();
3728
Douglas Gregora009b592011-01-07 00:20:55 +00003729 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3730 TL.getParmArray(),
3731 TL.getNumArgs(),
3732 TL.getTypePtr()->arg_type_begin(),
3733 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003734 return QualType();
3735 }
3736
John McCalla2becad2009-10-21 00:40:46 +00003737 QualType Result = TL.getType();
3738 if (getDerived().AlwaysRebuild() ||
3739 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003740 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003741 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3742 Result = getDerived().RebuildFunctionProtoType(ResultType,
3743 ParamTypes.data(),
3744 ParamTypes.size(),
3745 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003746 T->getTypeQuals(),
3747 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003748 if (Result.isNull())
3749 return QualType();
3750 }
Mike Stump1eb44332009-09-09 15:08:12 +00003751
John McCalla2becad2009-10-21 00:40:46 +00003752 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3753 NewTL.setLParenLoc(TL.getLParenLoc());
3754 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003755 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003756 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3757 NewTL.setArg(i, ParamDecls[i]);
3758
3759 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003760}
Mike Stump1eb44332009-09-09 15:08:12 +00003761
Douglas Gregor577f75a2009-08-04 16:50:30 +00003762template<typename Derived>
3763QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003764 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003765 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003766 FunctionNoProtoType *T = TL.getTypePtr();
3767 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3768 if (ResultType.isNull())
3769 return QualType();
3770
3771 QualType Result = TL.getType();
3772 if (getDerived().AlwaysRebuild() ||
3773 ResultType != T->getResultType())
3774 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3775
3776 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3777 NewTL.setLParenLoc(TL.getLParenLoc());
3778 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003779 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003780
3781 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782}
Mike Stump1eb44332009-09-09 15:08:12 +00003783
John McCalled976492009-12-04 22:46:56 +00003784template<typename Derived> QualType
3785TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003786 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003787 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003788 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003789 if (!D)
3790 return QualType();
3791
3792 QualType Result = TL.getType();
3793 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3794 Result = getDerived().RebuildUnresolvedUsingType(D);
3795 if (Result.isNull())
3796 return QualType();
3797 }
3798
3799 // We might get an arbitrary type spec type back. We should at
3800 // least always get a type spec type, though.
3801 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3802 NewTL.setNameLoc(TL.getNameLoc());
3803
3804 return Result;
3805}
3806
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003808QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003809 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003810 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003811 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003812 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3813 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814 if (!Typedef)
3815 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003816
John McCalla2becad2009-10-21 00:40:46 +00003817 QualType Result = TL.getType();
3818 if (getDerived().AlwaysRebuild() ||
3819 Typedef != T->getDecl()) {
3820 Result = getDerived().RebuildTypedefType(Typedef);
3821 if (Result.isNull())
3822 return QualType();
3823 }
Mike Stump1eb44332009-09-09 15:08:12 +00003824
John McCalla2becad2009-10-21 00:40:46 +00003825 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3826 NewTL.setNameLoc(TL.getNameLoc());
3827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
Douglas Gregor577f75a2009-08-04 16:50:30 +00003831template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003832QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003833 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003834 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003835 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003836
John McCall60d7b3a2010-08-24 06:29:42 +00003837 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003838 if (E.isInvalid())
3839 return QualType();
3840
John McCalla2becad2009-10-21 00:40:46 +00003841 QualType Result = TL.getType();
3842 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003843 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003844 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003845 if (Result.isNull())
3846 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003847 }
John McCalla2becad2009-10-21 00:40:46 +00003848 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003849
John McCalla2becad2009-10-21 00:40:46 +00003850 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003851 NewTL.setTypeofLoc(TL.getTypeofLoc());
3852 NewTL.setLParenLoc(TL.getLParenLoc());
3853 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003854
3855 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003856}
Mike Stump1eb44332009-09-09 15:08:12 +00003857
3858template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003859QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003860 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003861 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3862 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3863 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003864 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003865
John McCalla2becad2009-10-21 00:40:46 +00003866 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003867 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3868 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003869 if (Result.isNull())
3870 return QualType();
3871 }
Mike Stump1eb44332009-09-09 15:08:12 +00003872
John McCalla2becad2009-10-21 00:40:46 +00003873 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003874 NewTL.setTypeofLoc(TL.getTypeofLoc());
3875 NewTL.setLParenLoc(TL.getLParenLoc());
3876 NewTL.setRParenLoc(TL.getRParenLoc());
3877 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003878
3879 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003880}
Mike Stump1eb44332009-09-09 15:08:12 +00003881
3882template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003883QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003884 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003885 DecltypeType *T = TL.getTypePtr();
3886
Douglas Gregor670444e2009-08-04 22:27:00 +00003887 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003888 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003889
John McCall60d7b3a2010-08-24 06:29:42 +00003890 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003891 if (E.isInvalid())
3892 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003893
John McCalla2becad2009-10-21 00:40:46 +00003894 QualType Result = TL.getType();
3895 if (getDerived().AlwaysRebuild() ||
3896 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003897 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003898 if (Result.isNull())
3899 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003900 }
John McCalla2becad2009-10-21 00:40:46 +00003901 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003902
John McCalla2becad2009-10-21 00:40:46 +00003903 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3904 NewTL.setNameLoc(TL.getNameLoc());
3905
3906 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003907}
3908
3909template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003910QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003911 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003912 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003913 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003914 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3915 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003916 if (!Record)
3917 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003918
John McCalla2becad2009-10-21 00:40:46 +00003919 QualType Result = TL.getType();
3920 if (getDerived().AlwaysRebuild() ||
3921 Record != T->getDecl()) {
3922 Result = getDerived().RebuildRecordType(Record);
3923 if (Result.isNull())
3924 return QualType();
3925 }
Mike Stump1eb44332009-09-09 15:08:12 +00003926
John McCalla2becad2009-10-21 00:40:46 +00003927 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3928 NewTL.setNameLoc(TL.getNameLoc());
3929
3930 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003931}
Mike Stump1eb44332009-09-09 15:08:12 +00003932
3933template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003934QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003935 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003936 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003937 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003938 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3939 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003940 if (!Enum)
3941 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003942
John McCalla2becad2009-10-21 00:40:46 +00003943 QualType Result = TL.getType();
3944 if (getDerived().AlwaysRebuild() ||
3945 Enum != T->getDecl()) {
3946 Result = getDerived().RebuildEnumType(Enum);
3947 if (Result.isNull())
3948 return QualType();
3949 }
Mike Stump1eb44332009-09-09 15:08:12 +00003950
John McCalla2becad2009-10-21 00:40:46 +00003951 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3952 NewTL.setNameLoc(TL.getNameLoc());
3953
3954 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003955}
John McCall7da24312009-09-05 00:15:47 +00003956
John McCall3cb0ebd2010-03-10 03:28:59 +00003957template<typename Derived>
3958QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3959 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003960 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003961 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3962 TL.getTypePtr()->getDecl());
3963 if (!D) return QualType();
3964
3965 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3966 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3967 return T;
3968}
3969
Douglas Gregor577f75a2009-08-04 16:50:30 +00003970template<typename Derived>
3971QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003972 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003973 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003974 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003975}
3976
Mike Stump1eb44332009-09-09 15:08:12 +00003977template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003978QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003979 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003980 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003981 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003982}
3983
3984template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00003985QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
3986 TypeLocBuilder &TLB,
3987 SubstTemplateTypeParmPackTypeLoc TL) {
3988 return TransformTypeSpecType(TLB, TL);
3989}
3990
3991template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003992QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003993 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003994 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003995 const TemplateSpecializationType *T = TL.getTypePtr();
3996
Mike Stump1eb44332009-09-09 15:08:12 +00003997 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003998 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003999 if (Template.isNull())
4000 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004001
John McCall43fed0d2010-11-12 08:19:04 +00004002 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4003}
4004
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004005namespace {
4006 /// \brief Simple iterator that traverses the template arguments in a
4007 /// container that provides a \c getArgLoc() member function.
4008 ///
4009 /// This iterator is intended to be used with the iterator form of
4010 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4011 template<typename ArgLocContainer>
4012 class TemplateArgumentLocContainerIterator {
4013 ArgLocContainer *Container;
4014 unsigned Index;
4015
4016 public:
4017 typedef TemplateArgumentLoc value_type;
4018 typedef TemplateArgumentLoc reference;
4019 typedef int difference_type;
4020 typedef std::input_iterator_tag iterator_category;
4021
4022 class pointer {
4023 TemplateArgumentLoc Arg;
4024
4025 public:
4026 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4027
4028 const TemplateArgumentLoc *operator->() const {
4029 return &Arg;
4030 }
4031 };
4032
4033
4034 TemplateArgumentLocContainerIterator() {}
4035
4036 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4037 unsigned Index)
4038 : Container(&Container), Index(Index) { }
4039
4040 TemplateArgumentLocContainerIterator &operator++() {
4041 ++Index;
4042 return *this;
4043 }
4044
4045 TemplateArgumentLocContainerIterator operator++(int) {
4046 TemplateArgumentLocContainerIterator Old(*this);
4047 ++(*this);
4048 return Old;
4049 }
4050
4051 TemplateArgumentLoc operator*() const {
4052 return Container->getArgLoc(Index);
4053 }
4054
4055 pointer operator->() const {
4056 return pointer(Container->getArgLoc(Index));
4057 }
4058
4059 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004060 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004061 return X.Container == Y.Container && X.Index == Y.Index;
4062 }
4063
4064 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004065 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004066 return !(X == Y);
4067 }
4068 };
4069}
4070
4071
John McCall43fed0d2010-11-12 08:19:04 +00004072template <typename Derived>
4073QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4074 TypeLocBuilder &TLB,
4075 TemplateSpecializationTypeLoc TL,
4076 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004077 TemplateArgumentListInfo NewTemplateArgs;
4078 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4079 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004080 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4081 ArgIterator;
4082 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4083 ArgIterator(TL, TL.getNumArgs()),
4084 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004085 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004086
John McCall833ca992009-10-29 08:12:44 +00004087 // FIXME: maybe don't rebuild if all the template arguments are the same.
4088
4089 QualType Result =
4090 getDerived().RebuildTemplateSpecializationType(Template,
4091 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004092 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004093
4094 if (!Result.isNull()) {
4095 TemplateSpecializationTypeLoc NewTL
4096 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4097 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4098 NewTL.setLAngleLoc(TL.getLAngleLoc());
4099 NewTL.setRAngleLoc(TL.getRAngleLoc());
4100 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4101 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004102 }
Mike Stump1eb44332009-09-09 15:08:12 +00004103
John McCall833ca992009-10-29 08:12:44 +00004104 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004105}
Mike Stump1eb44332009-09-09 15:08:12 +00004106
4107template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004108QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004109TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004110 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004111 ElaboratedType *T = TL.getTypePtr();
4112
4113 NestedNameSpecifier *NNS = 0;
4114 // NOTE: the qualifier in an ElaboratedType is optional.
4115 if (T->getQualifier() != 0) {
4116 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004117 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004118 if (!NNS)
4119 return QualType();
4120 }
Mike Stump1eb44332009-09-09 15:08:12 +00004121
John McCall43fed0d2010-11-12 08:19:04 +00004122 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4123 if (NamedT.isNull())
4124 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004125
John McCalla2becad2009-10-21 00:40:46 +00004126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
4128 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004129 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004130 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4131 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004132 if (Result.isNull())
4133 return QualType();
4134 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004135
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004136 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004137 NewTL.setKeywordLoc(TL.getKeywordLoc());
4138 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004139
4140 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004141}
Mike Stump1eb44332009-09-09 15:08:12 +00004142
4143template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004144QualType TreeTransform<Derived>::TransformAttributedType(
4145 TypeLocBuilder &TLB,
4146 AttributedTypeLoc TL) {
4147 const AttributedType *oldType = TL.getTypePtr();
4148 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4149 if (modifiedType.isNull())
4150 return QualType();
4151
4152 QualType result = TL.getType();
4153
4154 // FIXME: dependent operand expressions?
4155 if (getDerived().AlwaysRebuild() ||
4156 modifiedType != oldType->getModifiedType()) {
4157 // TODO: this is really lame; we should really be rebuilding the
4158 // equivalent type from first principles.
4159 QualType equivalentType
4160 = getDerived().TransformType(oldType->getEquivalentType());
4161 if (equivalentType.isNull())
4162 return QualType();
4163 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4164 modifiedType,
4165 equivalentType);
4166 }
4167
4168 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4169 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4170 if (TL.hasAttrOperand())
4171 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4172 if (TL.hasAttrExprOperand())
4173 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4174 else if (TL.hasAttrEnumOperand())
4175 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4176
4177 return result;
4178}
4179
4180template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004181QualType
4182TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4183 ParenTypeLoc TL) {
4184 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4185 if (Inner.isNull())
4186 return QualType();
4187
4188 QualType Result = TL.getType();
4189 if (getDerived().AlwaysRebuild() ||
4190 Inner != TL.getInnerLoc().getType()) {
4191 Result = getDerived().RebuildParenType(Inner);
4192 if (Result.isNull())
4193 return QualType();
4194 }
4195
4196 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4197 NewTL.setLParenLoc(TL.getLParenLoc());
4198 NewTL.setRParenLoc(TL.getRParenLoc());
4199 return Result;
4200}
4201
4202template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004203QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004204 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00004205 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004206
Douglas Gregor577f75a2009-08-04 16:50:30 +00004207 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004208 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004209 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210 if (!NNS)
4211 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004212
John McCall33500952010-06-11 00:33:02 +00004213 QualType Result
4214 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4215 T->getIdentifier(),
4216 TL.getKeywordLoc(),
4217 TL.getQualifierRange(),
4218 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004219 if (Result.isNull())
4220 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004221
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004222 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4223 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004224 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4225
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004226 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4227 NewTL.setKeywordLoc(TL.getKeywordLoc());
4228 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004229 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004230 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4231 NewTL.setKeywordLoc(TL.getKeywordLoc());
4232 NewTL.setQualifierRange(TL.getQualifierRange());
4233 NewTL.setNameLoc(TL.getNameLoc());
4234 }
John McCalla2becad2009-10-21 00:40:46 +00004235 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004236}
Mike Stump1eb44332009-09-09 15:08:12 +00004237
Douglas Gregor577f75a2009-08-04 16:50:30 +00004238template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004239QualType TreeTransform<Derived>::
4240 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004241 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00004242 DependentTemplateSpecializationType *T = TL.getTypePtr();
4243
4244 NestedNameSpecifier *NNS
4245 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004246 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004247 if (!NNS)
4248 return QualType();
4249
John McCall43fed0d2010-11-12 08:19:04 +00004250 return getDerived()
4251 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4252}
4253
4254template<typename Derived>
4255QualType TreeTransform<Derived>::
4256 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4257 DependentTemplateSpecializationTypeLoc TL,
4258 NestedNameSpecifier *NNS) {
4259 DependentTemplateSpecializationType *T = TL.getTypePtr();
4260
John McCall33500952010-06-11 00:33:02 +00004261 TemplateArgumentListInfo NewTemplateArgs;
4262 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4263 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004264
4265 typedef TemplateArgumentLocContainerIterator<
4266 DependentTemplateSpecializationTypeLoc> ArgIterator;
4267 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4268 ArgIterator(TL, TL.getNumArgs()),
4269 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004270 return QualType();
John McCall33500952010-06-11 00:33:02 +00004271
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004272 QualType Result
4273 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4274 NNS,
4275 TL.getQualifierRange(),
4276 T->getIdentifier(),
4277 TL.getNameLoc(),
4278 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004279 if (Result.isNull())
4280 return QualType();
4281
4282 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4283 QualType NamedT = ElabT->getNamedType();
4284
4285 // Copy information relevant to the template specialization.
4286 TemplateSpecializationTypeLoc NamedTL
4287 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4288 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4289 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4290 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4291 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4292
4293 // Copy information relevant to the elaborated type.
4294 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4295 NewTL.setKeywordLoc(TL.getKeywordLoc());
4296 NewTL.setQualifierRange(TL.getQualifierRange());
4297 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004298 TypeLoc NewTL(Result, TL.getOpaqueData());
4299 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004300 }
4301 return Result;
4302}
4303
4304template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004305QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4306 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004307 QualType Pattern
4308 = getDerived().TransformType(TLB, TL.getPatternLoc());
4309 if (Pattern.isNull())
4310 return QualType();
4311
4312 QualType Result = TL.getType();
4313 if (getDerived().AlwaysRebuild() ||
4314 Pattern != TL.getPatternLoc().getType()) {
4315 Result = getDerived().RebuildPackExpansionType(Pattern,
4316 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004317 TL.getEllipsisLoc(),
4318 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004319 if (Result.isNull())
4320 return QualType();
4321 }
4322
4323 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4324 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4325 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004326}
4327
4328template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004329QualType
4330TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004331 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004332 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004333 TLB.pushFullCopy(TL);
4334 return TL.getType();
4335}
4336
4337template<typename Derived>
4338QualType
4339TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004340 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004341 // ObjCObjectType is never dependent.
4342 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004343 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004344}
Mike Stump1eb44332009-09-09 15:08:12 +00004345
4346template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004347QualType
4348TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004349 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004350 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004351 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004352 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004353}
4354
Douglas Gregor577f75a2009-08-04 16:50:30 +00004355//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004356// Statement transformation
4357//===----------------------------------------------------------------------===//
4358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004359StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004360TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004361 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004362}
4363
4364template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004365StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004366TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4367 return getDerived().TransformCompoundStmt(S, false);
4368}
4369
4370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004371StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004372TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004373 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004374 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004375 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004376 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004377 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4378 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004379 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004380 if (Result.isInvalid()) {
4381 // Immediately fail if this was a DeclStmt, since it's very
4382 // likely that this will cause problems for future statements.
4383 if (isa<DeclStmt>(*B))
4384 return StmtError();
4385
4386 // Otherwise, just keep processing substatements and fail later.
4387 SubStmtInvalid = true;
4388 continue;
4389 }
Mike Stump1eb44332009-09-09 15:08:12 +00004390
Douglas Gregor43959a92009-08-20 07:17:43 +00004391 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4392 Statements.push_back(Result.takeAs<Stmt>());
4393 }
Mike Stump1eb44332009-09-09 15:08:12 +00004394
John McCall7114cba2010-08-27 19:56:05 +00004395 if (SubStmtInvalid)
4396 return StmtError();
4397
Douglas Gregor43959a92009-08-20 07:17:43 +00004398 if (!getDerived().AlwaysRebuild() &&
4399 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004400 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004401
4402 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4403 move_arg(Statements),
4404 S->getRBracLoc(),
4405 IsStmtExpr);
4406}
Mike Stump1eb44332009-09-09 15:08:12 +00004407
Douglas Gregor43959a92009-08-20 07:17:43 +00004408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004409StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004410TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004411 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004412 {
4413 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004414 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004415
Eli Friedman264c1f82009-11-19 03:14:00 +00004416 // Transform the left-hand case value.
4417 LHS = getDerived().TransformExpr(S->getLHS());
4418 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004419 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004420
Eli Friedman264c1f82009-11-19 03:14:00 +00004421 // Transform the right-hand case value (for the GNU case-range extension).
4422 RHS = getDerived().TransformExpr(S->getRHS());
4423 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004424 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004425 }
Mike Stump1eb44332009-09-09 15:08:12 +00004426
Douglas Gregor43959a92009-08-20 07:17:43 +00004427 // Build the case statement.
4428 // Case statements are always rebuilt so that they will attached to their
4429 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004430 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004431 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004432 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004433 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004434 S->getColonLoc());
4435 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004436 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004437
Douglas Gregor43959a92009-08-20 07:17:43 +00004438 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004439 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004440 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004441 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004442
Douglas Gregor43959a92009-08-20 07:17:43 +00004443 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004444 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004445}
4446
4447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004448StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004449TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004450 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004451 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004452 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004453 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregor43959a92009-08-20 07:17:43 +00004455 // Default statements are always rebuilt
4456 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004457 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004458}
Mike Stump1eb44332009-09-09 15:08:12 +00004459
Douglas Gregor43959a92009-08-20 07:17:43 +00004460template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004461StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004462TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004463 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004464 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004465 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004466
Douglas Gregor43959a92009-08-20 07:17:43 +00004467 // FIXME: Pass the real colon location in.
4468 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4469 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004470 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004471}
Mike Stump1eb44332009-09-09 15:08:12 +00004472
Douglas Gregor43959a92009-08-20 07:17:43 +00004473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004474StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004475TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004476 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004477 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004478 VarDecl *ConditionVar = 0;
4479 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004480 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004481 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004482 getDerived().TransformDefinition(
4483 S->getConditionVariable()->getLocation(),
4484 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004485 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004486 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004487 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004488 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004489
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004490 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004491 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004492
4493 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004494 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004495 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4496 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004497 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004498 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004499
John McCall9ae2f072010-08-23 23:25:46 +00004500 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004501 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004502 }
Sean Huntc3021132010-05-05 15:23:54 +00004503
John McCall9ae2f072010-08-23 23:25:46 +00004504 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4505 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004506 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004507
Douglas Gregor43959a92009-08-20 07:17:43 +00004508 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004509 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004510 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004511 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004512
Douglas Gregor43959a92009-08-20 07:17:43 +00004513 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004514 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004515 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004516 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004517
Douglas Gregor43959a92009-08-20 07:17:43 +00004518 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004519 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004520 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004521 Then.get() == S->getThen() &&
4522 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004523 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004524
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004525 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004526 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004527 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004528}
4529
4530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004531StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004532TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004533 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004534 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004535 VarDecl *ConditionVar = 0;
4536 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004537 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004538 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004539 getDerived().TransformDefinition(
4540 S->getConditionVariable()->getLocation(),
4541 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004542 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004543 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004544 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004545 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004546
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004547 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004548 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004549 }
Mike Stump1eb44332009-09-09 15:08:12 +00004550
Douglas Gregor43959a92009-08-20 07:17:43 +00004551 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004552 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004553 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004554 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004555 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004556 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004557
Douglas Gregor43959a92009-08-20 07:17:43 +00004558 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004559 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004560 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004561 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004562
Douglas Gregor43959a92009-08-20 07:17:43 +00004563 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004564 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4565 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004566}
Mike Stump1eb44332009-09-09 15:08:12 +00004567
Douglas Gregor43959a92009-08-20 07:17:43 +00004568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004569StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004570TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004571 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004572 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004573 VarDecl *ConditionVar = 0;
4574 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004575 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004576 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004577 getDerived().TransformDefinition(
4578 S->getConditionVariable()->getLocation(),
4579 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004580 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004581 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004582 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004583 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004584
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004585 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004586 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004587
4588 if (S->getCond()) {
4589 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004590 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4591 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004592 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004593 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004594 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004595 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004596 }
Mike Stump1eb44332009-09-09 15:08:12 +00004597
John McCall9ae2f072010-08-23 23:25:46 +00004598 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4599 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004600 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004601
Douglas Gregor43959a92009-08-20 07:17:43 +00004602 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004603 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004604 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004605 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004606
Douglas Gregor43959a92009-08-20 07:17:43 +00004607 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004608 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004609 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004610 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004611 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004612
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004613 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004614 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004615}
Mike Stump1eb44332009-09-09 15:08:12 +00004616
Douglas Gregor43959a92009-08-20 07:17:43 +00004617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004618StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004619TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004620 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004621 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004622 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004623 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004624
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004625 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004626 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004627 if (Cond.isInvalid())
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 if (!getDerived().AlwaysRebuild() &&
4631 Cond.get() == S->getCond() &&
4632 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004633 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004634
John McCall9ae2f072010-08-23 23:25:46 +00004635 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4636 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004637 S->getRParenLoc());
4638}
Mike Stump1eb44332009-09-09 15:08:12 +00004639
Douglas Gregor43959a92009-08-20 07:17:43 +00004640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004641StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004642TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004643 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004644 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004645 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004646 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004647
Douglas Gregor43959a92009-08-20 07:17:43 +00004648 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004649 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004650 VarDecl *ConditionVar = 0;
4651 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004652 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004653 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004654 getDerived().TransformDefinition(
4655 S->getConditionVariable()->getLocation(),
4656 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004657 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004658 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004659 } else {
4660 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004661
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004662 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004663 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004664
4665 if (S->getCond()) {
4666 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004667 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4668 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004669 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004670 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004671
John McCall9ae2f072010-08-23 23:25:46 +00004672 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004673 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004674 }
Mike Stump1eb44332009-09-09 15:08:12 +00004675
John McCall9ae2f072010-08-23 23:25:46 +00004676 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4677 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004678 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004679
Douglas Gregor43959a92009-08-20 07:17:43 +00004680 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004681 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004682 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004683 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004684
John McCall9ae2f072010-08-23 23:25:46 +00004685 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4686 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004687 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004688
Douglas Gregor43959a92009-08-20 07:17:43 +00004689 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004690 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004691 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004692 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004693
Douglas Gregor43959a92009-08-20 07:17:43 +00004694 if (!getDerived().AlwaysRebuild() &&
4695 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004696 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004697 Inc.get() == S->getInc() &&
4698 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004699 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004700
Douglas Gregor43959a92009-08-20 07:17:43 +00004701 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004702 Init.get(), FullCond, ConditionVar,
4703 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004704}
4705
4706template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004707StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004708TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004709 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004710 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004711 S->getLabel());
4712}
4713
4714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004715StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004716TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004717 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004718 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004719 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004720
Douglas Gregor43959a92009-08-20 07:17:43 +00004721 if (!getDerived().AlwaysRebuild() &&
4722 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004723 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004724
4725 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004726 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004727}
4728
4729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004730StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004731TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004732 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004733}
Mike Stump1eb44332009-09-09 15:08:12 +00004734
Douglas Gregor43959a92009-08-20 07:17:43 +00004735template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004736StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004737TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004738 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004739}
Mike Stump1eb44332009-09-09 15:08:12 +00004740
Douglas Gregor43959a92009-08-20 07:17:43 +00004741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004742StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004743TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004744 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004745 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004746 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004747
Mike Stump1eb44332009-09-09 15:08:12 +00004748 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004749 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004750 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004751}
Mike Stump1eb44332009-09-09 15:08:12 +00004752
Douglas Gregor43959a92009-08-20 07:17:43 +00004753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004754StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004755TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004756 bool DeclChanged = false;
4757 llvm::SmallVector<Decl *, 4> Decls;
4758 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4759 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004760 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4761 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004762 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004763 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004764
Douglas Gregor43959a92009-08-20 07:17:43 +00004765 if (Transformed != *D)
4766 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004767
Douglas Gregor43959a92009-08-20 07:17:43 +00004768 Decls.push_back(Transformed);
4769 }
Mike Stump1eb44332009-09-09 15:08:12 +00004770
Douglas Gregor43959a92009-08-20 07:17:43 +00004771 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004772 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004773
4774 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004775 S->getStartLoc(), S->getEndLoc());
4776}
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregor43959a92009-08-20 07:17:43 +00004778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004779StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004780TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004781 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004782 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004783}
4784
4785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004786StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004787TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004788
John McCallca0408f2010-08-23 06:44:23 +00004789 ASTOwningVector<Expr*> Constraints(getSema());
4790 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004791 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004792
John McCall60d7b3a2010-08-24 06:29:42 +00004793 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004794 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004795
4796 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004797
Anders Carlsson703e3942010-01-24 05:50:09 +00004798 // Go through the outputs.
4799 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004800 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004801
Anders Carlsson703e3942010-01-24 05:50:09 +00004802 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004803 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004804
Anders Carlsson703e3942010-01-24 05:50:09 +00004805 // Transform the output expr.
4806 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004807 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004808 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004809 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004810
Anders Carlsson703e3942010-01-24 05:50:09 +00004811 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004812
John McCall9ae2f072010-08-23 23:25:46 +00004813 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004814 }
Sean Huntc3021132010-05-05 15:23:54 +00004815
Anders Carlsson703e3942010-01-24 05:50:09 +00004816 // Go through the inputs.
4817 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004818 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004819
Anders Carlsson703e3942010-01-24 05:50:09 +00004820 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004821 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004822
Anders Carlsson703e3942010-01-24 05:50:09 +00004823 // Transform the input expr.
4824 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004825 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004826 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004827 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004828
Anders Carlsson703e3942010-01-24 05:50:09 +00004829 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004830
John McCall9ae2f072010-08-23 23:25:46 +00004831 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004832 }
Sean Huntc3021132010-05-05 15:23:54 +00004833
Anders Carlsson703e3942010-01-24 05:50:09 +00004834 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004835 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004836
4837 // Go through the clobbers.
4838 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004839 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004840
4841 // No need to transform the asm string literal.
4842 AsmString = SemaRef.Owned(S->getAsmString());
4843
4844 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4845 S->isSimple(),
4846 S->isVolatile(),
4847 S->getNumOutputs(),
4848 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004849 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004850 move_arg(Constraints),
4851 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004852 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004853 move_arg(Clobbers),
4854 S->getRParenLoc(),
4855 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004856}
4857
4858
4859template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004860StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004861TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004862 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004863 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004864 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004865 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004866
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004867 // Transform the @catch statements (if present).
4868 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004869 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004870 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004871 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004872 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004873 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004874 if (Catch.get() != S->getCatchStmt(I))
4875 AnyCatchChanged = true;
4876 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004877 }
Sean Huntc3021132010-05-05 15:23:54 +00004878
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004879 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004880 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004881 if (S->getFinallyStmt()) {
4882 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4883 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004884 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004885 }
4886
4887 // If nothing changed, just retain this statement.
4888 if (!getDerived().AlwaysRebuild() &&
4889 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004890 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004891 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004892 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004893
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004894 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004895 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4896 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004897}
Mike Stump1eb44332009-09-09 15:08:12 +00004898
Douglas Gregor43959a92009-08-20 07:17:43 +00004899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004900StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004901TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004902 // Transform the @catch parameter, if there is one.
4903 VarDecl *Var = 0;
4904 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4905 TypeSourceInfo *TSInfo = 0;
4906 if (FromVar->getTypeSourceInfo()) {
4907 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4908 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004909 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004910 }
Sean Huntc3021132010-05-05 15:23:54 +00004911
Douglas Gregorbe270a02010-04-26 17:57:08 +00004912 QualType T;
4913 if (TSInfo)
4914 T = TSInfo->getType();
4915 else {
4916 T = getDerived().TransformType(FromVar->getType());
4917 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004918 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004919 }
Sean Huntc3021132010-05-05 15:23:54 +00004920
Douglas Gregorbe270a02010-04-26 17:57:08 +00004921 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4922 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004924 }
Sean Huntc3021132010-05-05 15:23:54 +00004925
John McCall60d7b3a2010-08-24 06:29:42 +00004926 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004927 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004928 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004929
4930 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004931 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004932 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004933}
Mike Stump1eb44332009-09-09 15:08:12 +00004934
Douglas Gregor43959a92009-08-20 07:17:43 +00004935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004936StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004937TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004938 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004939 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004940 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004941 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004942
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004943 // If nothing changed, just retain this statement.
4944 if (!getDerived().AlwaysRebuild() &&
4945 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004946 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004947
4948 // Build a new statement.
4949 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004950 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004951}
Mike Stump1eb44332009-09-09 15:08:12 +00004952
Douglas Gregor43959a92009-08-20 07:17:43 +00004953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004954StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004955TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004956 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004957 if (S->getThrowExpr()) {
4958 Operand = getDerived().TransformExpr(S->getThrowExpr());
4959 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004960 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004961 }
Sean Huntc3021132010-05-05 15:23:54 +00004962
Douglas Gregord1377b22010-04-22 21:44:01 +00004963 if (!getDerived().AlwaysRebuild() &&
4964 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004965 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004966
John McCall9ae2f072010-08-23 23:25:46 +00004967 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004968}
Mike Stump1eb44332009-09-09 15:08:12 +00004969
Douglas Gregor43959a92009-08-20 07:17:43 +00004970template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004971StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004972TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004973 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004974 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004975 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004976 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004977 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004978
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004979 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004980 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004981 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004982 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004983
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004984 // If nothing change, just retain the current statement.
4985 if (!getDerived().AlwaysRebuild() &&
4986 Object.get() == S->getSynchExpr() &&
4987 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004988 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004989
4990 // Build a new statement.
4991 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004992 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004993}
4994
4995template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004996StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004997TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004998 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004999 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005000 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005001 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005002 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005003
Douglas Gregorc3203e72010-04-22 23:10:45 +00005004 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005005 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005006 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005007 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005008
Douglas Gregorc3203e72010-04-22 23:10:45 +00005009 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005010 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005011 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005012 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005013
Douglas Gregorc3203e72010-04-22 23:10:45 +00005014 // If nothing changed, just retain this statement.
5015 if (!getDerived().AlwaysRebuild() &&
5016 Element.get() == S->getElement() &&
5017 Collection.get() == S->getCollection() &&
5018 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005019 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005020
Douglas Gregorc3203e72010-04-22 23:10:45 +00005021 // Build a new statement.
5022 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5023 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005024 Element.get(),
5025 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005026 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005027 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005028}
5029
5030
5031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005032StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005033TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5034 // Transform the exception declaration, if any.
5035 VarDecl *Var = 0;
5036 if (S->getExceptionDecl()) {
5037 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005038 TypeSourceInfo *T = getDerived().TransformType(
5039 ExceptionDecl->getTypeSourceInfo());
5040 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005041 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005042
Douglas Gregor83cb9422010-09-09 17:09:21 +00005043 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005045 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005046 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005047 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005048 }
Mike Stump1eb44332009-09-09 15:08:12 +00005049
Douglas Gregor43959a92009-08-20 07:17:43 +00005050 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005051 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005052 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005053 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005054
Douglas Gregor43959a92009-08-20 07:17:43 +00005055 if (!getDerived().AlwaysRebuild() &&
5056 !Var &&
5057 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005058 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005059
5060 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5061 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005062 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005063}
Mike Stump1eb44332009-09-09 15:08:12 +00005064
Douglas Gregor43959a92009-08-20 07:17:43 +00005065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005066StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005067TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5068 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005069 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005070 = getDerived().TransformCompoundStmt(S->getTryBlock());
5071 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005072 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005073
Douglas Gregor43959a92009-08-20 07:17:43 +00005074 // Transform the handlers.
5075 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005076 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005077 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005078 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005079 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5080 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 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5084 Handlers.push_back(Handler.takeAs<Stmt>());
5085 }
Mike Stump1eb44332009-09-09 15:08:12 +00005086
Douglas Gregor43959a92009-08-20 07:17:43 +00005087 if (!getDerived().AlwaysRebuild() &&
5088 TryBlock.get() == S->getTryBlock() &&
5089 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005090 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005091
John McCall9ae2f072010-08-23 23:25:46 +00005092 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005093 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005094}
Mike Stump1eb44332009-09-09 15:08:12 +00005095
Douglas Gregor43959a92009-08-20 07:17:43 +00005096//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097// Expression transformation
5098//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005100ExprResult
John McCall454feb92009-12-08 09:21:05 +00005101TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005102 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005103}
Mike Stump1eb44332009-09-09 15:08:12 +00005104
5105template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005106ExprResult
John McCall454feb92009-12-08 09:21:05 +00005107TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005108 NestedNameSpecifier *Qualifier = 0;
5109 if (E->getQualifier()) {
5110 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005111 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005112 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005113 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005114 }
John McCalldbd872f2009-12-08 09:08:17 +00005115
5116 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005117 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5118 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005121
John McCallec8045d2010-08-17 21:27:17 +00005122 DeclarationNameInfo NameInfo = E->getNameInfo();
5123 if (NameInfo.getName()) {
5124 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5125 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005127 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005128
5129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005130 Qualifier == E->getQualifier() &&
5131 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005132 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005133 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005134
5135 // Mark it referenced in the new context regardless.
5136 // FIXME: this is a bit instantiation-specific.
5137 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5138
John McCall3fa5cae2010-10-26 07:05:15 +00005139 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005140 }
John McCalldbd872f2009-12-08 09:08:17 +00005141
5142 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005143 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005144 TemplateArgs = &TransArgs;
5145 TransArgs.setLAngleLoc(E->getLAngleLoc());
5146 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005147 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5148 E->getNumTemplateArgs(),
5149 TransArgs))
5150 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005151 }
5152
Douglas Gregora2813ce2009-10-23 18:54:35 +00005153 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005154 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005155}
Mike Stump1eb44332009-09-09 15:08:12 +00005156
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005158ExprResult
John McCall454feb92009-12-08 09:21:05 +00005159TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005160 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005161}
Mike Stump1eb44332009-09-09 15:08:12 +00005162
Douglas Gregorb98b1992009-08-11 05:31:07 +00005163template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005164ExprResult
John McCall454feb92009-12-08 09:21:05 +00005165TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005166 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005167}
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregorb98b1992009-08-11 05:31:07 +00005169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005170ExprResult
John McCall454feb92009-12-08 09:21:05 +00005171TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005172 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005173}
Mike Stump1eb44332009-09-09 15:08:12 +00005174
Douglas Gregorb98b1992009-08-11 05:31:07 +00005175template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005176ExprResult
John McCall454feb92009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005178 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005179}
Mike Stump1eb44332009-09-09 15:08:12 +00005180
Douglas Gregorb98b1992009-08-11 05:31:07 +00005181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005182ExprResult
John McCall454feb92009-12-08 09:21:05 +00005183TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005184 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005185}
5186
5187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005188ExprResult
John McCall454feb92009-12-08 09:21:05 +00005189TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005190 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005191 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005192 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005193
Douglas Gregorb98b1992009-08-11 05:31:07 +00005194 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005195 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005196
John McCall9ae2f072010-08-23 23:25:46 +00005197 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005198 E->getRParen());
5199}
5200
Mike Stump1eb44332009-09-09 15:08:12 +00005201template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005202ExprResult
John McCall454feb92009-12-08 09:21:05 +00005203TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005204 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005205 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005206 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005207
Douglas Gregorb98b1992009-08-11 05:31:07 +00005208 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005209 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005210
Douglas Gregorb98b1992009-08-11 05:31:07 +00005211 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5212 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005213 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214}
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregorb98b1992009-08-11 05:31:07 +00005216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005217ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005218TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5219 // Transform the type.
5220 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5221 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005222 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005223
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005224 // Transform all of the components into components similar to what the
5225 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005226 // FIXME: It would be slightly more efficient in the non-dependent case to
5227 // just map FieldDecls, rather than requiring the rebuilder to look for
5228 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005229 // template code that we don't care.
5230 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005231 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005232 typedef OffsetOfExpr::OffsetOfNode Node;
5233 llvm::SmallVector<Component, 4> Components;
5234 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5235 const Node &ON = E->getComponent(I);
5236 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005237 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005238 Comp.LocStart = ON.getRange().getBegin();
5239 Comp.LocEnd = ON.getRange().getEnd();
5240 switch (ON.getKind()) {
5241 case Node::Array: {
5242 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005243 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005244 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005246
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005247 ExprChanged = ExprChanged || Index.get() != FromIndex;
5248 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005249 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005250 break;
5251 }
Sean Huntc3021132010-05-05 15:23:54 +00005252
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005253 case Node::Field:
5254 case Node::Identifier:
5255 Comp.isBrackets = false;
5256 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005257 if (!Comp.U.IdentInfo)
5258 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005259
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005260 break;
Sean Huntc3021132010-05-05 15:23:54 +00005261
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005262 case Node::Base:
5263 // Will be recomputed during the rebuild.
5264 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005265 }
Sean Huntc3021132010-05-05 15:23:54 +00005266
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005267 Components.push_back(Comp);
5268 }
Sean Huntc3021132010-05-05 15:23:54 +00005269
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005270 // If nothing changed, retain the existing expression.
5271 if (!getDerived().AlwaysRebuild() &&
5272 Type == E->getTypeSourceInfo() &&
5273 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005274 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005275
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005276 // Build a new offsetof expression.
5277 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5278 Components.data(), Components.size(),
5279 E->getRParenLoc());
5280}
5281
5282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005283ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005284TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5285 assert(getDerived().AlreadyTransformed(E->getType()) &&
5286 "opaque value expression requires transformation");
5287 return SemaRef.Owned(E);
5288}
5289
5290template<typename Derived>
5291ExprResult
John McCall454feb92009-12-08 09:21:05 +00005292TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005293 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005294 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005295
John McCalla93c9342009-12-07 02:54:59 +00005296 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005297 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005298 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005299
John McCall5ab75172009-11-04 07:28:41 +00005300 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005301 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005302
John McCall5ab75172009-11-04 07:28:41 +00005303 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005304 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005305 E->getSourceRange());
5306 }
Mike Stump1eb44332009-09-09 15:08:12 +00005307
John McCall60d7b3a2010-08-24 06:29:42 +00005308 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005309 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005310 // C++0x [expr.sizeof]p1:
5311 // The operand is either an expression, which is an unevaluated operand
5312 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005313 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005314
Douglas Gregorb98b1992009-08-11 05:31:07 +00005315 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5316 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregorb98b1992009-08-11 05:31:07 +00005319 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005320 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005321 }
Mike Stump1eb44332009-09-09 15:08:12 +00005322
John McCall9ae2f072010-08-23 23:25:46 +00005323 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005324 E->isSizeOf(),
5325 E->getSourceRange());
5326}
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregorb98b1992009-08-11 05:31:07 +00005328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005329ExprResult
John McCall454feb92009-12-08 09:21:05 +00005330TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005331 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005332 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005333 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005334
John McCall60d7b3a2010-08-24 06:29:42 +00005335 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005336 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005337 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005338
5339
Douglas Gregorb98b1992009-08-11 05:31:07 +00005340 if (!getDerived().AlwaysRebuild() &&
5341 LHS.get() == E->getLHS() &&
5342 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005343 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005344
John McCall9ae2f072010-08-23 23:25:46 +00005345 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005346 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005347 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005348 E->getRBracketLoc());
5349}
Mike Stump1eb44332009-09-09 15:08:12 +00005350
5351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005352ExprResult
John McCall454feb92009-12-08 09:21:05 +00005353TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005354 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005355 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005356 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005357 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005358
5359 // Transform arguments.
5360 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005361 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005362 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5363 &ArgChanged))
5364 return ExprError();
5365
Douglas Gregorb98b1992009-08-11 05:31:07 +00005366 if (!getDerived().AlwaysRebuild() &&
5367 Callee.get() == E->getCallee() &&
5368 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregorb98b1992009-08-11 05:31:07 +00005371 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005372 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005373 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005374 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005375 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005376 E->getRParenLoc());
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>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005382 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005383 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005384 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005385
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005386 NestedNameSpecifier *Qualifier = 0;
5387 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005388 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005389 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005390 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005391 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005392 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005393 }
Mike Stump1eb44332009-09-09 15:08:12 +00005394
Eli Friedmanf595cc42009-12-04 06:40:45 +00005395 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005396 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5397 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005398 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005400
John McCall6bb80172010-03-30 21:47:33 +00005401 NamedDecl *FoundDecl = E->getFoundDecl();
5402 if (FoundDecl == E->getMemberDecl()) {
5403 FoundDecl = Member;
5404 } else {
5405 FoundDecl = cast_or_null<NamedDecl>(
5406 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5407 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005408 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005409 }
5410
Douglas Gregorb98b1992009-08-11 05:31:07 +00005411 if (!getDerived().AlwaysRebuild() &&
5412 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005413 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005414 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005415 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005416 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005417
Anders Carlsson1f240322009-12-22 05:24:09 +00005418 // Mark it referenced in the new context regardless.
5419 // FIXME: this is a bit instantiation-specific.
5420 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005421 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005422 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005423
John McCalld5532b62009-11-23 01:53:49 +00005424 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005425 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005426 TransArgs.setLAngleLoc(E->getLAngleLoc());
5427 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005428 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5429 E->getNumTemplateArgs(),
5430 TransArgs))
5431 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005432 }
Sean Huntc3021132010-05-05 15:23:54 +00005433
Douglas Gregorb98b1992009-08-11 05:31:07 +00005434 // FIXME: Bogus source location for the operator
5435 SourceLocation FakeOperatorLoc
5436 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5437
John McCallc2233c52010-01-15 08:34:02 +00005438 // FIXME: to do this check properly, we will need to preserve the
5439 // first-qualifier-in-scope here, just in case we had a dependent
5440 // base (and therefore couldn't do the check) and a
5441 // nested-name-qualifier (and therefore could do the lookup).
5442 NamedDecl *FirstQualifierInScope = 0;
5443
John McCall9ae2f072010-08-23 23:25:46 +00005444 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005446 Qualifier,
5447 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005448 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005449 Member,
John McCall6bb80172010-03-30 21:47:33 +00005450 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005451 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005452 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005453 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005454}
Mike Stump1eb44332009-09-09 15:08:12 +00005455
Douglas Gregorb98b1992009-08-11 05:31:07 +00005456template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005457ExprResult
John McCall454feb92009-12-08 09:21:05 +00005458TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005459 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005460 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005462
John McCall60d7b3a2010-08-24 06:29:42 +00005463 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005464 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005465 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregorb98b1992009-08-11 05:31:07 +00005467 if (!getDerived().AlwaysRebuild() &&
5468 LHS.get() == E->getLHS() &&
5469 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005470 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005471
Douglas Gregorb98b1992009-08-11 05:31:07 +00005472 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005473 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005474}
5475
Mike Stump1eb44332009-09-09 15:08:12 +00005476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005478TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005479 CompoundAssignOperator *E) {
5480 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005481}
Mike Stump1eb44332009-09-09 15:08:12 +00005482
Douglas Gregorb98b1992009-08-11 05:31:07 +00005483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005484ExprResult
John McCall454feb92009-12-08 09:21:05 +00005485TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005486 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005487 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005489
John McCall60d7b3a2010-08-24 06:29:42 +00005490 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005491 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005492 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005493
John McCall60d7b3a2010-08-24 06:29:42 +00005494 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005495 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005496 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregorb98b1992009-08-11 05:31:07 +00005498 if (!getDerived().AlwaysRebuild() &&
5499 Cond.get() == E->getCond() &&
5500 LHS.get() == E->getLHS() &&
5501 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005502 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005503
John McCall9ae2f072010-08-23 23:25:46 +00005504 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005505 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005506 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005507 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005508 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509}
Mike Stump1eb44332009-09-09 15:08:12 +00005510
5511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512ExprResult
John McCall454feb92009-12-08 09:21:05 +00005513TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005514 // Implicit casts are eliminated during transformation, since they
5515 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005516 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517}
Mike Stump1eb44332009-09-09 15:08:12 +00005518
Douglas Gregorb98b1992009-08-11 05:31:07 +00005519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005520ExprResult
John McCall454feb92009-12-08 09:21:05 +00005521TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005522 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5523 if (!Type)
5524 return ExprError();
5525
John McCall60d7b3a2010-08-24 06:29:42 +00005526 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005527 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005530
Douglas Gregorb98b1992009-08-11 05:31:07 +00005531 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005532 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005533 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005534 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005535
John McCall9d125032010-01-15 18:39:57 +00005536 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005537 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005538 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005539 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005540}
Mike Stump1eb44332009-09-09 15:08:12 +00005541
Douglas Gregorb98b1992009-08-11 05:31:07 +00005542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005543ExprResult
John McCall454feb92009-12-08 09:21:05 +00005544TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005545 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5546 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5547 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005548 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005549
John McCall60d7b3a2010-08-24 06:29:42 +00005550 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005552 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregorb98b1992009-08-11 05:31:07 +00005554 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005555 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005557 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005558
John McCall1d7d8d62010-01-19 22:33:45 +00005559 // Note: the expression type doesn't necessarily match the
5560 // type-as-written, but that's okay, because it should always be
5561 // derivable from the initializer.
5562
John McCall42f56b52010-01-18 19:35:47 +00005563 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005565 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005566}
Mike Stump1eb44332009-09-09 15:08:12 +00005567
Douglas Gregorb98b1992009-08-11 05:31:07 +00005568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005569ExprResult
John McCall454feb92009-12-08 09:21:05 +00005570TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005571 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005572 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005573 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005574
Douglas Gregorb98b1992009-08-11 05:31:07 +00005575 if (!getDerived().AlwaysRebuild() &&
5576 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005577 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005578
Douglas Gregorb98b1992009-08-11 05:31:07 +00005579 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005580 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005582 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583 E->getAccessorLoc(),
5584 E->getAccessor());
5585}
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005588ExprResult
John McCall454feb92009-12-08 09:21:05 +00005589TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005590 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005591
John McCallca0408f2010-08-23 06:44:23 +00005592 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005593 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5594 Inits, &InitChanged))
5595 return ExprError();
5596
Douglas Gregorb98b1992009-08-11 05:31:07 +00005597 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005598 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005599
Douglas Gregorb98b1992009-08-11 05:31:07 +00005600 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005601 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005602}
Mike Stump1eb44332009-09-09 15:08:12 +00005603
Douglas Gregorb98b1992009-08-11 05:31:07 +00005604template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005605ExprResult
John McCall454feb92009-12-08 09:21:05 +00005606TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005607 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005608
Douglas Gregor43959a92009-08-20 07:17:43 +00005609 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005610 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005611 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005613
Douglas Gregor43959a92009-08-20 07:17:43 +00005614 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005615 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005616 bool ExprChanged = false;
5617 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5618 DEnd = E->designators_end();
5619 D != DEnd; ++D) {
5620 if (D->isFieldDesignator()) {
5621 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5622 D->getDotLoc(),
5623 D->getFieldLoc()));
5624 continue;
5625 }
Mike Stump1eb44332009-09-09 15:08:12 +00005626
Douglas Gregorb98b1992009-08-11 05:31:07 +00005627 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005628 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005630 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005631
5632 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005633 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005634
Douglas Gregorb98b1992009-08-11 05:31:07 +00005635 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5636 ArrayExprs.push_back(Index.release());
5637 continue;
5638 }
Mike Stump1eb44332009-09-09 15:08:12 +00005639
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005641 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005642 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5643 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005644 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005645
John McCall60d7b3a2010-08-24 06:29:42 +00005646 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005647 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005648 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005649
5650 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005651 End.get(),
5652 D->getLBracketLoc(),
5653 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005654
Douglas Gregorb98b1992009-08-11 05:31:07 +00005655 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5656 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658 ArrayExprs.push_back(Start.release());
5659 ArrayExprs.push_back(End.release());
5660 }
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Douglas Gregorb98b1992009-08-11 05:31:07 +00005662 if (!getDerived().AlwaysRebuild() &&
5663 Init.get() == E->getInit() &&
5664 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005665 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregorb98b1992009-08-11 05:31:07 +00005667 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5668 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005669 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005670}
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005673ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005674TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005675 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005676 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005677
Douglas Gregor5557b252009-10-28 00:29:27 +00005678 // FIXME: Will we ever have proper type location here? Will we actually
5679 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 QualType T = getDerived().TransformType(E->getType());
5681 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005682 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005683
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684 if (!getDerived().AlwaysRebuild() &&
5685 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005686 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 return getDerived().RebuildImplicitValueInitExpr(T);
5689}
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692ExprResult
John McCall454feb92009-12-08 09:21:05 +00005693TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005694 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5695 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005696 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005697
John McCall60d7b3a2010-08-24 06:29:42 +00005698 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005699 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005701
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005703 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005705 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005706
John McCall9ae2f072010-08-23 23:25:46 +00005707 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005708 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005709}
5710
5711template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005712ExprResult
John McCall454feb92009-12-08 09:21:05 +00005713TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005715 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005716 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5717 &ArgumentChanged))
5718 return ExprError();
5719
Douglas Gregorb98b1992009-08-11 05:31:07 +00005720 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5721 move_arg(Inits),
5722 E->getRParenLoc());
5723}
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregorb98b1992009-08-11 05:31:07 +00005725/// \brief Transform an address-of-label expression.
5726///
5727/// By default, the transformation of an address-of-label expression always
5728/// rebuilds the expression, so that the label identifier can be resolved to
5729/// the corresponding label statement by semantic analysis.
5730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005731ExprResult
John McCall454feb92009-12-08 09:21:05 +00005732TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005733 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5734 E->getLabel());
5735}
Mike Stump1eb44332009-09-09 15:08:12 +00005736
5737template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005738ExprResult
John McCall454feb92009-12-08 09:21:05 +00005739TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005740 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005741 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5742 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005744
Douglas Gregorb98b1992009-08-11 05:31:07 +00005745 if (!getDerived().AlwaysRebuild() &&
5746 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005747 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005748
5749 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005750 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005751 E->getRParenLoc());
5752}
Mike Stump1eb44332009-09-09 15:08:12 +00005753
Douglas Gregorb98b1992009-08-11 05:31:07 +00005754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005755ExprResult
John McCall454feb92009-12-08 09:21:05 +00005756TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005757 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005759 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005760
John McCall60d7b3a2010-08-24 06:29:42 +00005761 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005762 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005763 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005764
John McCall60d7b3a2010-08-24 06:29:42 +00005765 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005766 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005767 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005768
Douglas Gregorb98b1992009-08-11 05:31:07 +00005769 if (!getDerived().AlwaysRebuild() &&
5770 Cond.get() == E->getCond() &&
5771 LHS.get() == E->getLHS() &&
5772 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005773 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005774
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005776 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 E->getRParenLoc());
5778}
Mike Stump1eb44332009-09-09 15:08:12 +00005779
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005781ExprResult
John McCall454feb92009-12-08 09:21:05 +00005782TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005783 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005784}
5785
5786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005787ExprResult
John McCall454feb92009-12-08 09:21:05 +00005788TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005789 switch (E->getOperator()) {
5790 case OO_New:
5791 case OO_Delete:
5792 case OO_Array_New:
5793 case OO_Array_Delete:
5794 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005795 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005796
Douglas Gregor668d6d92009-12-13 20:44:55 +00005797 case OO_Call: {
5798 // This is a call to an object's operator().
5799 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5800
5801 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005802 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005803 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005804 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005805
5806 // FIXME: Poor location information
5807 SourceLocation FakeLParenLoc
5808 = SemaRef.PP.getLocForEndOfToken(
5809 static_cast<Expr *>(Object.get())->getLocEnd());
5810
5811 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005812 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005813 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5814 Args))
5815 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005816
John McCall9ae2f072010-08-23 23:25:46 +00005817 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005818 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005819 E->getLocEnd());
5820 }
5821
5822#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5823 case OO_##Name:
5824#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5825#include "clang/Basic/OperatorKinds.def"
5826 case OO_Subscript:
5827 // Handled below.
5828 break;
5829
5830 case OO_Conditional:
5831 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005832 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005833
5834 case OO_None:
5835 case NUM_OVERLOADED_OPERATORS:
5836 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005837 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005838 }
5839
John McCall60d7b3a2010-08-24 06:29:42 +00005840 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005841 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005842 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005843
John McCall60d7b3a2010-08-24 06:29:42 +00005844 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005845 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005846 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005847
John McCall60d7b3a2010-08-24 06:29:42 +00005848 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005849 if (E->getNumArgs() == 2) {
5850 Second = getDerived().TransformExpr(E->getArg(1));
5851 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005852 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005853 }
Mike Stump1eb44332009-09-09 15:08:12 +00005854
Douglas Gregorb98b1992009-08-11 05:31:07 +00005855 if (!getDerived().AlwaysRebuild() &&
5856 Callee.get() == E->getCallee() &&
5857 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005858 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005859 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005860
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5862 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005863 Callee.get(),
5864 First.get(),
5865 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005866}
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregorb98b1992009-08-11 05:31:07 +00005868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005869ExprResult
John McCall454feb92009-12-08 09:21:05 +00005870TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5871 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005872}
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregorb98b1992009-08-11 05:31:07 +00005874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005875ExprResult
John McCall454feb92009-12-08 09:21:05 +00005876TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005877 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5878 if (!Type)
5879 return ExprError();
5880
John McCall60d7b3a2010-08-24 06:29:42 +00005881 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005882 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005883 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005884 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005885
Douglas Gregorb98b1992009-08-11 05:31:07 +00005886 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005887 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005888 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005889 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005890
Douglas Gregorb98b1992009-08-11 05:31:07 +00005891 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005892 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005893 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5894 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5895 SourceLocation FakeRParenLoc
5896 = SemaRef.PP.getLocForEndOfToken(
5897 E->getSubExpr()->getSourceRange().getEnd());
5898 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005899 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005900 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005901 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005902 FakeRAngleLoc,
5903 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005904 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005905 FakeRParenLoc);
5906}
Mike Stump1eb44332009-09-09 15:08:12 +00005907
Douglas Gregorb98b1992009-08-11 05:31:07 +00005908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005909ExprResult
John McCall454feb92009-12-08 09:21:05 +00005910TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5911 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005912}
Mike Stump1eb44332009-09-09 15:08:12 +00005913
5914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005915ExprResult
John McCall454feb92009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5917 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005918}
5919
Douglas Gregorb98b1992009-08-11 05:31:07 +00005920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005921ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005922TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005923 CXXReinterpretCastExpr *E) {
5924 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005925}
Mike Stump1eb44332009-09-09 15:08:12 +00005926
Douglas Gregorb98b1992009-08-11 05:31:07 +00005927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005928ExprResult
John McCall454feb92009-12-08 09:21:05 +00005929TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5930 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005931}
Mike Stump1eb44332009-09-09 15:08:12 +00005932
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005934ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005935TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005936 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005937 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5938 if (!Type)
5939 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005940
John McCall60d7b3a2010-08-24 06:29:42 +00005941 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005942 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005943 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005944 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005945
Douglas Gregorb98b1992009-08-11 05:31:07 +00005946 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005947 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005948 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005949 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005950
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005951 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005952 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005953 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005954 E->getRParenLoc());
5955}
Mike Stump1eb44332009-09-09 15:08:12 +00005956
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005958ExprResult
John McCall454feb92009-12-08 09:21:05 +00005959TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005961 TypeSourceInfo *TInfo
5962 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5963 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005964 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005965
Douglas Gregorb98b1992009-08-11 05:31:07 +00005966 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005967 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005968 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005969
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005970 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5971 E->getLocStart(),
5972 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005973 E->getLocEnd());
5974 }
Mike Stump1eb44332009-09-09 15:08:12 +00005975
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 // We don't know whether the expression is potentially evaluated until
5977 // after we perform semantic analysis, so the expression is potentially
5978 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005979 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005980 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005981
John McCall60d7b3a2010-08-24 06:29:42 +00005982 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005984 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005985
Douglas Gregorb98b1992009-08-11 05:31:07 +00005986 if (!getDerived().AlwaysRebuild() &&
5987 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005988 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005989
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005990 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5991 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005992 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005993 E->getLocEnd());
5994}
5995
5996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005997ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005998TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5999 if (E->isTypeOperand()) {
6000 TypeSourceInfo *TInfo
6001 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6002 if (!TInfo)
6003 return ExprError();
6004
6005 if (!getDerived().AlwaysRebuild() &&
6006 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006007 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006008
6009 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6010 E->getLocStart(),
6011 TInfo,
6012 E->getLocEnd());
6013 }
6014
6015 // We don't know whether the expression is potentially evaluated until
6016 // after we perform semantic analysis, so the expression is potentially
6017 // potentially evaluated.
6018 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6019
6020 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6021 if (SubExpr.isInvalid())
6022 return ExprError();
6023
6024 if (!getDerived().AlwaysRebuild() &&
6025 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006026 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006027
6028 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6029 E->getLocStart(),
6030 SubExpr.get(),
6031 E->getLocEnd());
6032}
6033
6034template<typename Derived>
6035ExprResult
John McCall454feb92009-12-08 09:21:05 +00006036TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006037 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038}
Mike Stump1eb44332009-09-09 15:08:12 +00006039
Douglas Gregorb98b1992009-08-11 05:31:07 +00006040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006041ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006043 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006044 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045}
Mike Stump1eb44332009-09-09 15:08:12 +00006046
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006048ExprResult
John McCall454feb92009-12-08 09:21:05 +00006049TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006050 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6051 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6052 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006053
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006054 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006055 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006056
Douglas Gregor828a1972010-01-07 23:12:05 +00006057 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058}
Mike Stump1eb44332009-09-09 15:08:12 +00006059
Douglas Gregorb98b1992009-08-11 05:31:07 +00006060template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006061ExprResult
John McCall454feb92009-12-08 09:21:05 +00006062TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006063 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006065 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067 if (!getDerived().AlwaysRebuild() &&
6068 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006069 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070
John McCall9ae2f072010-08-23 23:25:46 +00006071 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072}
Mike Stump1eb44332009-09-09 15:08:12 +00006073
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006075ExprResult
John McCall454feb92009-12-08 09:21:05 +00006076TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006077 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006078 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6079 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006080 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006081 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006082
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006083 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006084 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006085 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006086
Douglas Gregor036aed12009-12-23 23:03:06 +00006087 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006088}
Mike Stump1eb44332009-09-09 15:08:12 +00006089
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006091ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006092TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6093 CXXScalarValueInitExpr *E) {
6094 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6095 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006096 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006097
Douglas Gregorb98b1992009-08-11 05:31:07 +00006098 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006099 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006101
Douglas Gregorab6677e2010-09-08 00:15:04 +00006102 return getDerived().RebuildCXXScalarValueInitExpr(T,
6103 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006104 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006105}
Mike Stump1eb44332009-09-09 15:08:12 +00006106
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006108ExprResult
John McCall454feb92009-12-08 09:21:05 +00006109TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006110 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006111 TypeSourceInfo *AllocTypeInfo
6112 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6113 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006114 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006115
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006117 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006118 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006119 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121 // Transform the placement arguments (if any).
6122 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006123 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006124 if (getDerived().TransformExprs(E->getPlacementArgs(),
6125 E->getNumPlacementArgs(), true,
6126 PlacementArgs, &ArgumentChanged))
6127 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregor43959a92009-08-20 07:17:43 +00006129 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006130 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006131 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6132 ConstructorArgs, &ArgumentChanged))
6133 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006134
Douglas Gregor1af74512010-02-26 00:38:10 +00006135 // Transform constructor, new operator, and delete operator.
6136 CXXConstructorDecl *Constructor = 0;
6137 if (E->getConstructor()) {
6138 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006139 getDerived().TransformDecl(E->getLocStart(),
6140 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006141 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006142 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006143 }
6144
6145 FunctionDecl *OperatorNew = 0;
6146 if (E->getOperatorNew()) {
6147 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006148 getDerived().TransformDecl(E->getLocStart(),
6149 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006150 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006151 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006152 }
6153
6154 FunctionDecl *OperatorDelete = 0;
6155 if (E->getOperatorDelete()) {
6156 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006157 getDerived().TransformDecl(E->getLocStart(),
6158 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006159 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006160 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006161 }
Sean Huntc3021132010-05-05 15:23:54 +00006162
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006164 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006166 Constructor == E->getConstructor() &&
6167 OperatorNew == E->getOperatorNew() &&
6168 OperatorDelete == E->getOperatorDelete() &&
6169 !ArgumentChanged) {
6170 // Mark any declarations we need as referenced.
6171 // FIXME: instantiation-specific.
6172 if (Constructor)
6173 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6174 if (OperatorNew)
6175 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6176 if (OperatorDelete)
6177 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006178 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006179 }
Mike Stump1eb44332009-09-09 15:08:12 +00006180
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006181 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006182 if (!ArraySize.get()) {
6183 // If no array size was specified, but the new expression was
6184 // instantiated with an array type (e.g., "new T" where T is
6185 // instantiated with "int[4]"), extract the outer bound from the
6186 // array type as our array size. We do this with constant and
6187 // dependently-sized array types.
6188 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6189 if (!ArrayT) {
6190 // Do nothing
6191 } else if (const ConstantArrayType *ConsArrayT
6192 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006193 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006194 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6195 ConsArrayT->getSize(),
6196 SemaRef.Context.getSizeType(),
6197 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006198 AllocType = ConsArrayT->getElementType();
6199 } else if (const DependentSizedArrayType *DepArrayT
6200 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6201 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006202 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006203 AllocType = DepArrayT->getElementType();
6204 }
6205 }
6206 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006207
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6209 E->isGlobalNew(),
6210 /*FIXME:*/E->getLocStart(),
6211 move_arg(PlacementArgs),
6212 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006213 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006215 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006216 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 /*FIXME:*/E->getLocStart(),
6218 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006219 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220}
Mike Stump1eb44332009-09-09 15:08:12 +00006221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006223ExprResult
John McCall454feb92009-12-08 09:21:05 +00006224TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006225 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006227 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006228
Douglas Gregor1af74512010-02-26 00:38:10 +00006229 // Transform the delete operator, if known.
6230 FunctionDecl *OperatorDelete = 0;
6231 if (E->getOperatorDelete()) {
6232 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006233 getDerived().TransformDecl(E->getLocStart(),
6234 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006235 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006236 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006237 }
Sean Huntc3021132010-05-05 15:23:54 +00006238
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006240 Operand.get() == E->getArgument() &&
6241 OperatorDelete == E->getOperatorDelete()) {
6242 // Mark any declarations we need as referenced.
6243 // FIXME: instantiation-specific.
6244 if (OperatorDelete)
6245 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006246
6247 if (!E->getArgument()->isTypeDependent()) {
6248 QualType Destroyed = SemaRef.Context.getBaseElementType(
6249 E->getDestroyedType());
6250 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6251 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6252 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6253 SemaRef.LookupDestructor(Record));
6254 }
6255 }
6256
John McCall3fa5cae2010-10-26 07:05:15 +00006257 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006258 }
Mike Stump1eb44332009-09-09 15:08:12 +00006259
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6261 E->isGlobalDelete(),
6262 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006263 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264}
Mike Stump1eb44332009-09-09 15:08:12 +00006265
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006267ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006268TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006269 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006270 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006271 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006272 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006273
John McCallb3d87482010-08-24 05:47:05 +00006274 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006275 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006276 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006277 E->getOperatorLoc(),
6278 E->isArrow()? tok::arrow : tok::period,
6279 ObjectTypePtr,
6280 MayBePseudoDestructor);
6281 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006282 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006283
John McCallb3d87482010-08-24 05:47:05 +00006284 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006285 NestedNameSpecifier *Qualifier = E->getQualifier();
6286 if (Qualifier) {
6287 Qualifier
6288 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6289 E->getQualifierRange(),
6290 ObjectType);
6291 if (!Qualifier)
6292 return ExprError();
6293 }
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006295 PseudoDestructorTypeStorage Destroyed;
6296 if (E->getDestroyedTypeInfo()) {
6297 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006298 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6299 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006300 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006301 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006302 Destroyed = DestroyedTypeInfo;
6303 } else if (ObjectType->isDependentType()) {
6304 // We aren't likely to be able to resolve the identifier down to a type
6305 // now anyway, so just retain the identifier.
6306 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6307 E->getDestroyedTypeLoc());
6308 } else {
6309 // Look for a destructor known with the given name.
6310 CXXScopeSpec SS;
6311 if (Qualifier) {
6312 SS.setScopeRep(Qualifier);
6313 SS.setRange(E->getQualifierRange());
6314 }
Sean Huntc3021132010-05-05 15:23:54 +00006315
John McCallb3d87482010-08-24 05:47:05 +00006316 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006317 *E->getDestroyedTypeIdentifier(),
6318 E->getDestroyedTypeLoc(),
6319 /*Scope=*/0,
6320 SS, ObjectTypePtr,
6321 false);
6322 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006323 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006324
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006325 Destroyed
6326 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6327 E->getDestroyedTypeLoc());
6328 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006329
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006330 TypeSourceInfo *ScopeTypeInfo = 0;
6331 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006332 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006333 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006334 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006335 }
Sean Huntc3021132010-05-05 15:23:54 +00006336
John McCall9ae2f072010-08-23 23:25:46 +00006337 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006338 E->getOperatorLoc(),
6339 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006340 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006341 E->getQualifierRange(),
6342 ScopeTypeInfo,
6343 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006344 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006345 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006346}
Mike Stump1eb44332009-09-09 15:08:12 +00006347
Douglas Gregora71d8192009-09-04 17:36:40 +00006348template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006349ExprResult
John McCallba135432009-11-21 08:51:07 +00006350TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006351 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006352 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6353
6354 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6355 Sema::LookupOrdinaryName);
6356
6357 // Transform all the decls.
6358 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6359 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006360 NamedDecl *InstD = static_cast<NamedDecl*>(
6361 getDerived().TransformDecl(Old->getNameLoc(),
6362 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006363 if (!InstD) {
6364 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6365 // This can happen because of dependent hiding.
6366 if (isa<UsingShadowDecl>(*I))
6367 continue;
6368 else
John McCallf312b1e2010-08-26 23:41:50 +00006369 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006370 }
John McCallf7a1a742009-11-24 19:00:30 +00006371
6372 // Expand using declarations.
6373 if (isa<UsingDecl>(InstD)) {
6374 UsingDecl *UD = cast<UsingDecl>(InstD);
6375 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6376 E = UD->shadow_end(); I != E; ++I)
6377 R.addDecl(*I);
6378 continue;
6379 }
6380
6381 R.addDecl(InstD);
6382 }
6383
6384 // Resolve a kind, but don't do any further analysis. If it's
6385 // ambiguous, the callee needs to deal with it.
6386 R.resolveKind();
6387
6388 // Rebuild the nested-name qualifier, if present.
6389 CXXScopeSpec SS;
6390 NestedNameSpecifier *Qualifier = 0;
6391 if (Old->getQualifier()) {
6392 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006393 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006394 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006395 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006396
John McCallf7a1a742009-11-24 19:00:30 +00006397 SS.setScopeRep(Qualifier);
6398 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006399 }
6400
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006401 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006402 CXXRecordDecl *NamingClass
6403 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6404 Old->getNameLoc(),
6405 Old->getNamingClass()));
6406 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006407 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006408
Douglas Gregor66c45152010-04-27 16:10:10 +00006409 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006410 }
6411
6412 // If we have no template arguments, it's a normal declaration name.
6413 if (!Old->hasExplicitTemplateArgs())
6414 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6415
6416 // If we have template arguments, rebuild them, then rebuild the
6417 // templateid expression.
6418 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006419 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6420 Old->getNumTemplateArgs(),
6421 TransArgs))
6422 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006423
6424 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6425 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426}
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006429ExprResult
John McCall454feb92009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006431 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6432 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006434
Douglas Gregorb98b1992009-08-11 05:31:07 +00006435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006436 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006437 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006438
Mike Stump1eb44332009-09-09 15:08:12 +00006439 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 T,
6442 E->getLocEnd());
6443}
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006446ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006447TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6448 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6449 if (!LhsT)
6450 return ExprError();
6451
6452 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6453 if (!RhsT)
6454 return ExprError();
6455
6456 if (!getDerived().AlwaysRebuild() &&
6457 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6458 return SemaRef.Owned(E);
6459
6460 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6461 E->getLocStart(),
6462 LhsT, RhsT,
6463 E->getLocEnd());
6464}
6465
6466template<typename Derived>
6467ExprResult
John McCall865d4472009-11-19 22:55:06 +00006468TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006469 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006471 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006472 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006475
John McCall43fed0d2010-11-12 08:19:04 +00006476 // TODO: If this is a conversion-function-id, verify that the
6477 // destination type name (if present) resolves the same way after
6478 // instantiation as it did in the local scope.
6479
Abramo Bagnara25777432010-08-11 22:01:17 +00006480 DeclarationNameInfo NameInfo
6481 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6482 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006484
John McCallf7a1a742009-11-24 19:00:30 +00006485 if (!E->hasExplicitTemplateArgs()) {
6486 if (!getDerived().AlwaysRebuild() &&
6487 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006488 // Note: it is sufficient to compare the Name component of NameInfo:
6489 // if name has not changed, DNLoc has not changed either.
6490 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006492
John McCallf7a1a742009-11-24 19:00:30 +00006493 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6494 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006495 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006496 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006497 }
John McCalld5532b62009-11-23 01:53:49 +00006498
6499 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006500 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6501 E->getNumTemplateArgs(),
6502 TransArgs))
6503 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504
John McCallf7a1a742009-11-24 19:00:30 +00006505 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6506 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006507 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006508 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509}
6510
6511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006512ExprResult
John McCall454feb92009-12-08 09:21:05 +00006513TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006514 // CXXConstructExprs are always implicit, so when we have a
6515 // 1-argument construction we just transform that argument.
6516 if (E->getNumArgs() == 1 ||
6517 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6518 return getDerived().TransformExpr(E->getArg(0));
6519
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6521
6522 QualType T = getDerived().TransformType(E->getType());
6523 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006524 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525
6526 CXXConstructorDecl *Constructor
6527 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006528 getDerived().TransformDecl(E->getLocStart(),
6529 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006534 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006535 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6536 &ArgumentChanged))
6537 return ExprError();
6538
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 if (!getDerived().AlwaysRebuild() &&
6540 T == E->getType() &&
6541 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006542 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006543 // Mark the constructor as referenced.
6544 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006545 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006546 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006547 }
Mike Stump1eb44332009-09-09 15:08:12 +00006548
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006549 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6550 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006551 move_arg(Args),
6552 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006553 E->getConstructionKind(),
6554 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555}
Mike Stump1eb44332009-09-09 15:08:12 +00006556
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557/// \brief Transform a C++ temporary-binding expression.
6558///
Douglas Gregor51326552009-12-24 18:51:59 +00006559/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6560/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006562ExprResult
John McCall454feb92009-12-08 09:21:05 +00006563TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006564 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565}
Mike Stump1eb44332009-09-09 15:08:12 +00006566
John McCall4765fa02010-12-06 08:20:24 +00006567/// \brief Transform a C++ expression that contains cleanups that should
6568/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569///
John McCall4765fa02010-12-06 08:20:24 +00006570/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006571/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006573ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006574TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006575 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576}
Mike Stump1eb44332009-09-09 15:08:12 +00006577
Douglas Gregorb98b1992009-08-11 05:31:07 +00006578template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006579ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006581 CXXTemporaryObjectExpr *E) {
6582 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6583 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006584 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 CXXConstructorDecl *Constructor
6587 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006588 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006589 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006591 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006594 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006596 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6597 &ArgumentChanged))
6598 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006599
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006601 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006603 !ArgumentChanged) {
6604 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006605 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006606 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006607 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006608
6609 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6610 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 E->getLocEnd());
6613}
Mike Stump1eb44332009-09-09 15:08:12 +00006614
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006616ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006617TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006618 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006619 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6620 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006622
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006624 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006625 Args.reserve(E->arg_size());
6626 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6627 &ArgumentChanged))
6628 return ExprError();
6629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006631 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006633 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006636 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 E->getLParenLoc(),
6638 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 E->getRParenLoc());
6640}
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006643ExprResult
John McCall865d4472009-11-19 22:55:06 +00006644TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006645 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006647 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006648 Expr *OldBase;
6649 QualType BaseType;
6650 QualType ObjectType;
6651 if (!E->isImplicitAccess()) {
6652 OldBase = E->getBase();
6653 Base = getDerived().TransformExpr(OldBase);
6654 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006655 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006656
John McCallaa81e162009-12-01 22:10:20 +00006657 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006658 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006659 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006660 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006661 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006662 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006663 ObjectTy,
6664 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006665 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006667
John McCallb3d87482010-08-24 05:47:05 +00006668 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006669 BaseType = ((Expr*) Base.get())->getType();
6670 } else {
6671 OldBase = 0;
6672 BaseType = getDerived().TransformType(E->getBaseType());
6673 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6674 }
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregor6cd21982009-10-20 05:58:46 +00006676 // Transform the first part of the nested-name-specifier that qualifies
6677 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006678 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006679 = getDerived().TransformFirstQualifierInScope(
6680 E->getFirstQualifierFoundInScope(),
6681 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregora38c6872009-09-03 16:14:30 +00006683 NestedNameSpecifier *Qualifier = 0;
6684 if (E->getQualifier()) {
6685 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6686 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006687 ObjectType,
6688 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006689 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006690 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006691 }
Mike Stump1eb44332009-09-09 15:08:12 +00006692
John McCall43fed0d2010-11-12 08:19:04 +00006693 // TODO: If this is a conversion-function-id, verify that the
6694 // destination type name (if present) resolves the same way after
6695 // instantiation as it did in the local scope.
6696
Abramo Bagnara25777432010-08-11 22:01:17 +00006697 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006698 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006699 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006700 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006701
John McCallaa81e162009-12-01 22:10:20 +00006702 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006703 // This is a reference to a member without an explicitly-specified
6704 // template argument list. Optimize for this common case.
6705 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006706 Base.get() == OldBase &&
6707 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006708 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006709 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006710 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006711 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006712
John McCall9ae2f072010-08-23 23:25:46 +00006713 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006714 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006715 E->isArrow(),
6716 E->getOperatorLoc(),
6717 Qualifier,
6718 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006719 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006720 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006721 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006722 }
6723
John McCalld5532b62009-11-23 01:53:49 +00006724 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006725 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6726 E->getNumTemplateArgs(),
6727 TransArgs))
6728 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006729
John McCall9ae2f072010-08-23 23:25:46 +00006730 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006731 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 E->isArrow(),
6733 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006734 Qualifier,
6735 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006736 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006737 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006738 &TransArgs);
6739}
6740
6741template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006742ExprResult
John McCall454feb92009-12-08 09:21:05 +00006743TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006744 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006745 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006746 QualType BaseType;
6747 if (!Old->isImplicitAccess()) {
6748 Base = getDerived().TransformExpr(Old->getBase());
6749 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006750 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006751 BaseType = ((Expr*) Base.get())->getType();
6752 } else {
6753 BaseType = getDerived().TransformType(Old->getBaseType());
6754 }
John McCall129e2df2009-11-30 22:42:35 +00006755
6756 NestedNameSpecifier *Qualifier = 0;
6757 if (Old->getQualifier()) {
6758 Qualifier
6759 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006760 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006761 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006762 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006763 }
6764
Abramo Bagnara25777432010-08-11 22:01:17 +00006765 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006766 Sema::LookupOrdinaryName);
6767
6768 // Transform all the decls.
6769 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6770 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006771 NamedDecl *InstD = static_cast<NamedDecl*>(
6772 getDerived().TransformDecl(Old->getMemberLoc(),
6773 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006774 if (!InstD) {
6775 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6776 // This can happen because of dependent hiding.
6777 if (isa<UsingShadowDecl>(*I))
6778 continue;
6779 else
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006781 }
John McCall129e2df2009-11-30 22:42:35 +00006782
6783 // Expand using declarations.
6784 if (isa<UsingDecl>(InstD)) {
6785 UsingDecl *UD = cast<UsingDecl>(InstD);
6786 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6787 E = UD->shadow_end(); I != E; ++I)
6788 R.addDecl(*I);
6789 continue;
6790 }
6791
6792 R.addDecl(InstD);
6793 }
6794
6795 R.resolveKind();
6796
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006797 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006798 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006799 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006800 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006801 Old->getMemberLoc(),
6802 Old->getNamingClass()));
6803 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006805
Douglas Gregor66c45152010-04-27 16:10:10 +00006806 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006807 }
Sean Huntc3021132010-05-05 15:23:54 +00006808
John McCall129e2df2009-11-30 22:42:35 +00006809 TemplateArgumentListInfo TransArgs;
6810 if (Old->hasExplicitTemplateArgs()) {
6811 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6812 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006813 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6814 Old->getNumTemplateArgs(),
6815 TransArgs))
6816 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006817 }
John McCallc2233c52010-01-15 08:34:02 +00006818
6819 // FIXME: to do this check properly, we will need to preserve the
6820 // first-qualifier-in-scope here, just in case we had a dependent
6821 // base (and therefore couldn't do the check) and a
6822 // nested-name-qualifier (and therefore could do the lookup).
6823 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006824
John McCall9ae2f072010-08-23 23:25:46 +00006825 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006826 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006827 Old->getOperatorLoc(),
6828 Old->isArrow(),
6829 Qualifier,
6830 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006831 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006832 R,
6833 (Old->hasExplicitTemplateArgs()
6834 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835}
6836
6837template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006838ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006839TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6840 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6841 if (SubExpr.isInvalid())
6842 return ExprError();
6843
6844 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006845 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006846
6847 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6848}
6849
6850template<typename Derived>
6851ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006852TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00006853 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6854 if (Pattern.isInvalid())
6855 return ExprError();
6856
6857 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6858 return SemaRef.Owned(E);
6859
Douglas Gregor67fd1252011-01-14 21:20:45 +00006860 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6861 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00006862}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006863
6864template<typename Derived>
6865ExprResult
6866TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6867 // If E is not value-dependent, then nothing will change when we transform it.
6868 // Note: This is an instantiation-centric view.
6869 if (!E->isValueDependent())
6870 return SemaRef.Owned(E);
6871
6872 // Note: None of the implementations of TryExpandParameterPacks can ever
6873 // produce a diagnostic when given only a single unexpanded parameter pack,
6874 // so
6875 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6876 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00006877 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00006878 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00006879 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6880 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00006881 ShouldExpand, RetainExpansion,
6882 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00006883 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006884
Douglas Gregord3731192011-01-10 07:32:04 +00006885 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00006886 return SemaRef.Owned(E);
6887
6888 // We now know the length of the parameter pack, so build a new expression
6889 // that stores that length.
6890 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6891 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00006892 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00006893}
6894
Douglas Gregorbe230c32011-01-03 17:17:50 +00006895template<typename Derived>
6896ExprResult
John McCall454feb92009-12-08 09:21:05 +00006897TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006898 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899}
6900
Mike Stump1eb44332009-09-09 15:08:12 +00006901template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006902ExprResult
John McCall454feb92009-12-08 09:21:05 +00006903TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006904 TypeSourceInfo *EncodedTypeInfo
6905 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6906 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006907 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006908
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006910 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006911 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006912
6913 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006914 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006915 E->getRParenLoc());
6916}
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregorb98b1992009-08-11 05:31:07 +00006918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006919ExprResult
John McCall454feb92009-12-08 09:21:05 +00006920TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006921 // Transform arguments.
6922 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006923 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006924 Args.reserve(E->getNumArgs());
6925 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6926 &ArgChanged))
6927 return ExprError();
6928
Douglas Gregor92e986e2010-04-22 16:44:27 +00006929 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6930 // Class message: transform the receiver type.
6931 TypeSourceInfo *ReceiverTypeInfo
6932 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6933 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006934 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006935
Douglas Gregor92e986e2010-04-22 16:44:27 +00006936 // If nothing changed, just retain the existing message send.
6937 if (!getDerived().AlwaysRebuild() &&
6938 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006939 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006940
6941 // Build a new class message send.
6942 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6943 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006944 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006945 E->getMethodDecl(),
6946 E->getLeftLoc(),
6947 move_arg(Args),
6948 E->getRightLoc());
6949 }
6950
6951 // Instance message: transform the receiver
6952 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6953 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006954 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006955 = getDerived().TransformExpr(E->getInstanceReceiver());
6956 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006958
6959 // If nothing changed, just retain the existing message send.
6960 if (!getDerived().AlwaysRebuild() &&
6961 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006962 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006963
Douglas Gregor92e986e2010-04-22 16:44:27 +00006964 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006965 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006966 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006967 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006968 E->getMethodDecl(),
6969 E->getLeftLoc(),
6970 move_arg(Args),
6971 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972}
6973
Mike Stump1eb44332009-09-09 15:08:12 +00006974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006975ExprResult
John McCall454feb92009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978}
6979
Mike Stump1eb44332009-09-09 15:08:12 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006983 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984}
6985
Mike Stump1eb44332009-09-09 15:08:12 +00006986template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006987ExprResult
John McCall454feb92009-12-08 09:21:05 +00006988TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006989 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006990 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006991 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006992 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006993
6994 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006995
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006996 // If nothing changed, just retain the existing expression.
6997 if (!getDerived().AlwaysRebuild() &&
6998 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006999 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007000
John McCall9ae2f072010-08-23 23:25:46 +00007001 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007002 E->getLocation(),
7003 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004}
7005
Mike Stump1eb44332009-09-09 15:08:12 +00007006template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007007ExprResult
John McCall454feb92009-12-08 09:21:05 +00007008TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007009 // 'super' and types never change. Property never changes. Just
7010 // retain the existing expression.
7011 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007012 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007013
Douglas Gregore3303542010-04-26 20:47:02 +00007014 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007015 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007016 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007017 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007018
Douglas Gregore3303542010-04-26 20:47:02 +00007019 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007020
Douglas Gregore3303542010-04-26 20:47:02 +00007021 // If nothing changed, just retain the existing expression.
7022 if (!getDerived().AlwaysRebuild() &&
7023 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007024 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025
John McCall12f78a62010-12-02 01:19:52 +00007026 if (E->isExplicitProperty())
7027 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7028 E->getExplicitProperty(),
7029 E->getLocation());
7030
7031 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7032 E->getType(),
7033 E->getImplicitPropertyGetter(),
7034 E->getImplicitPropertySetter(),
7035 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007036}
7037
Mike Stump1eb44332009-09-09 15:08:12 +00007038template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007039ExprResult
John McCall454feb92009-12-08 09:21:05 +00007040TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007041 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007042 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007043 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007044 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007045
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007046 // If nothing changed, just retain the existing expression.
7047 if (!getDerived().AlwaysRebuild() &&
7048 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007049 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007050
John McCall9ae2f072010-08-23 23:25:46 +00007051 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007052 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053}
7054
Mike Stump1eb44332009-09-09 15:08:12 +00007055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007056ExprResult
John McCall454feb92009-12-08 09:21:05 +00007057TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007059 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007060 SubExprs.reserve(E->getNumSubExprs());
7061 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7062 SubExprs, &ArgumentChanged))
7063 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 if (!getDerived().AlwaysRebuild() &&
7066 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007067 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7070 move_arg(SubExprs),
7071 E->getRParenLoc());
7072}
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>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007077 SourceLocation CaretLoc(E->getExprLoc());
7078
7079 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7080 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7081 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7082 llvm::SmallVector<ParmVarDecl*, 4> Params;
7083 llvm::SmallVector<QualType, 4> ParamTypes;
7084
7085 // Parameter substitution.
Douglas Gregor12c9c002011-01-07 16:43:16 +00007086 // FIXME: Variadic templates
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007087 const BlockDecl *BD = E->getBlockDecl();
7088 for (BlockDecl::param_const_iterator P = BD->param_begin(),
7089 EN = BD->param_end(); P != EN; ++P) {
7090 ParmVarDecl *OldParm = (*P);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00007091 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
7092 llvm::Optional<unsigned>());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007093 QualType NewType = NewParm->getType();
7094 Params.push_back(NewParm);
7095 ParamTypes.push_back(NewParm->getType());
7096 }
7097
7098 const FunctionType *BExprFunctionType = E->getFunctionType();
7099 QualType BExprResultType = BExprFunctionType->getResultType();
7100 if (!BExprResultType.isNull()) {
7101 if (!BExprResultType->isDependentType())
7102 CurBlock->ReturnType = BExprResultType;
7103 else if (BExprResultType != SemaRef.Context.DependentTy)
7104 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7105 }
John McCall711c52b2011-01-05 12:14:39 +00007106
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007107 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7108 CurBlock->ReturnType,
7109 ParamTypes.data(),
7110 ParamTypes.size(),
7111 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007112 0,
7113 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007114 CurBlock->FunctionType = FunctionType;
John McCall711c52b2011-01-05 12:14:39 +00007115
7116 // Set the parameters on the block decl.
7117 if (!Params.empty())
7118 CurBlock->TheDecl->setParams(Params.data(), Params.size());
7119
7120 // Transform the body
7121 StmtResult Body = getDerived().TransformStmt(E->getBody());
7122 if (Body.isInvalid())
7123 return ExprError();
7124
John McCall9ae2f072010-08-23 23:25:46 +00007125 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126}
7127
Mike Stump1eb44332009-09-09 15:08:12 +00007128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007129ExprResult
John McCall454feb92009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007131 NestedNameSpecifier *Qualifier = 0;
7132
7133 ValueDecl *ND
7134 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7135 E->getDecl()));
7136 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007137 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007138
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007139 if (!getDerived().AlwaysRebuild() &&
7140 ND == E->getDecl()) {
7141 // Mark it referenced in the new context regardless.
7142 // FIXME: this is a bit instantiation-specific.
7143 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7144
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007146 }
7147
Abramo Bagnara25777432010-08-11 22:01:17 +00007148 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007149 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007150 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151}
Mike Stump1eb44332009-09-09 15:08:12 +00007152
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007154// Type reconstruction
7155//===----------------------------------------------------------------------===//
7156
Mike Stump1eb44332009-09-09 15:08:12 +00007157template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007158QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7159 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007160 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007161 getDerived().getBaseEntity());
7162}
7163
Mike Stump1eb44332009-09-09 15:08:12 +00007164template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007165QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7166 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007167 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007168 getDerived().getBaseEntity());
7169}
7170
Mike Stump1eb44332009-09-09 15:08:12 +00007171template<typename Derived>
7172QualType
John McCall85737a72009-10-30 00:06:24 +00007173TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7174 bool WrittenAsLValue,
7175 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007176 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007177 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007178}
7179
7180template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007181QualType
John McCall85737a72009-10-30 00:06:24 +00007182TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7183 QualType ClassType,
7184 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007185 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007186 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007187}
7188
7189template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007190QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007191TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7192 ArrayType::ArraySizeModifier SizeMod,
7193 const llvm::APInt *Size,
7194 Expr *SizeExpr,
7195 unsigned IndexTypeQuals,
7196 SourceRange BracketsRange) {
7197 if (SizeExpr || !Size)
7198 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7199 IndexTypeQuals, BracketsRange,
7200 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007201
7202 QualType Types[] = {
7203 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7204 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7205 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007206 };
7207 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7208 QualType SizeType;
7209 for (unsigned I = 0; I != NumTypes; ++I)
7210 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7211 SizeType = Types[I];
7212 break;
7213 }
Mike Stump1eb44332009-09-09 15:08:12 +00007214
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007215 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7216 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007217 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007218 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007219 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007220}
Mike Stump1eb44332009-09-09 15:08:12 +00007221
Douglas Gregor577f75a2009-08-04 16:50:30 +00007222template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007223QualType
7224TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007225 ArrayType::ArraySizeModifier SizeMod,
7226 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007227 unsigned IndexTypeQuals,
7228 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007229 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007230 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007231}
7232
7233template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007234QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007235TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007236 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007237 unsigned IndexTypeQuals,
7238 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007239 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007240 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007241}
Mike Stump1eb44332009-09-09 15:08:12 +00007242
Douglas Gregor577f75a2009-08-04 16:50:30 +00007243template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007244QualType
7245TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007246 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007247 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007248 unsigned IndexTypeQuals,
7249 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007250 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007251 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007252 IndexTypeQuals, BracketsRange);
7253}
7254
7255template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007256QualType
7257TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007258 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007259 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007260 unsigned IndexTypeQuals,
7261 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007262 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007263 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007264 IndexTypeQuals, BracketsRange);
7265}
7266
7267template<typename Derived>
7268QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007269 unsigned NumElements,
7270 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007271 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007272 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007273}
Mike Stump1eb44332009-09-09 15:08:12 +00007274
Douglas Gregor577f75a2009-08-04 16:50:30 +00007275template<typename Derived>
7276QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7277 unsigned NumElements,
7278 SourceLocation AttributeLoc) {
7279 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7280 NumElements, true);
7281 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007282 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7283 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007284 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007285}
Mike Stump1eb44332009-09-09 15:08:12 +00007286
Douglas Gregor577f75a2009-08-04 16:50:30 +00007287template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007288QualType
7289TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007290 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007291 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007292 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007293}
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregor577f75a2009-08-04 16:50:30 +00007295template<typename Derived>
7296QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007297 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007298 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007299 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007300 unsigned Quals,
7301 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007302 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007303 Quals,
7304 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007305 getDerived().getBaseEntity(),
7306 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007307}
Mike Stump1eb44332009-09-09 15:08:12 +00007308
Douglas Gregor577f75a2009-08-04 16:50:30 +00007309template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007310QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7311 return SemaRef.Context.getFunctionNoProtoType(T);
7312}
7313
7314template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007315QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7316 assert(D && "no decl found");
7317 if (D->isInvalidDecl()) return QualType();
7318
Douglas Gregor92e986e2010-04-22 16:44:27 +00007319 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007320 TypeDecl *Ty;
7321 if (isa<UsingDecl>(D)) {
7322 UsingDecl *Using = cast<UsingDecl>(D);
7323 assert(Using->isTypeName() &&
7324 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7325
7326 // A valid resolved using typename decl points to exactly one type decl.
7327 assert(++Using->shadow_begin() == Using->shadow_end());
7328 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007329
John McCalled976492009-12-04 22:46:56 +00007330 } else {
7331 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7332 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7333 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7334 }
7335
7336 return SemaRef.Context.getTypeDeclType(Ty);
7337}
7338
7339template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007340QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7341 SourceLocation Loc) {
7342 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007343}
7344
7345template<typename Derived>
7346QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7347 return SemaRef.Context.getTypeOfType(Underlying);
7348}
7349
7350template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007351QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7352 SourceLocation Loc) {
7353 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007354}
7355
7356template<typename Derived>
7357QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007358 TemplateName Template,
7359 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007360 const TemplateArgumentListInfo &TemplateArgs) {
7361 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007362}
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregordcee1a12009-08-06 05:28:30 +00007364template<typename Derived>
7365NestedNameSpecifier *
7366TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7367 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007368 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007369 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007370 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007371 CXXScopeSpec SS;
7372 // FIXME: The source location information is all wrong.
7373 SS.setRange(Range);
7374 SS.setScopeRep(Prefix);
7375 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007376 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007377 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007378 ObjectType,
7379 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007380 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007381}
7382
7383template<typename Derived>
7384NestedNameSpecifier *
7385TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7386 SourceRange Range,
7387 NamespaceDecl *NS) {
7388 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7389}
7390
7391template<typename Derived>
7392NestedNameSpecifier *
7393TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7394 SourceRange Range,
7395 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007396 QualType T) {
7397 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007398 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007399 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007400 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7401 T.getTypePtr());
7402 }
Mike Stump1eb44332009-09-09 15:08:12 +00007403
Douglas Gregordcee1a12009-08-06 05:28:30 +00007404 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7405 return 0;
7406}
Mike Stump1eb44332009-09-09 15:08:12 +00007407
Douglas Gregord1067e52009-08-06 06:41:21 +00007408template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007409TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007410TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7411 bool TemplateKW,
7412 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007413 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007414 Template);
7415}
7416
7417template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007418TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007419TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007420 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007421 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007422 QualType ObjectType,
7423 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007424 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007425 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007426 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007427 UnqualifiedId Name;
7428 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007429 Sema::TemplateTy Template;
7430 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7431 /*FIXME:*/getDerived().getBaseLocation(),
7432 SS,
7433 Name,
John McCallb3d87482010-08-24 05:47:05 +00007434 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007435 /*EnteringContext=*/false,
7436 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007437 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007438}
Mike Stump1eb44332009-09-09 15:08:12 +00007439
Douglas Gregorb98b1992009-08-11 05:31:07 +00007440template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007441TemplateName
7442TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7443 OverloadedOperatorKind Operator,
7444 QualType ObjectType) {
7445 CXXScopeSpec SS;
7446 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7447 SS.setScopeRep(Qualifier);
7448 UnqualifiedId Name;
7449 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7450 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7451 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007452 Sema::TemplateTy Template;
7453 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007454 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007455 SS,
7456 Name,
John McCallb3d87482010-08-24 05:47:05 +00007457 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007458 /*EnteringContext=*/false,
7459 Template);
7460 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007461}
Sean Huntc3021132010-05-05 15:23:54 +00007462
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007463template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007464ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7466 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007467 Expr *OrigCallee,
7468 Expr *First,
7469 Expr *Second) {
7470 Expr *Callee = OrigCallee->IgnoreParenCasts();
7471 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007472
Douglas Gregorb98b1992009-08-11 05:31:07 +00007473 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007474 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007475 if (!First->getType()->isOverloadableType() &&
7476 !Second->getType()->isOverloadableType())
7477 return getSema().CreateBuiltinArraySubscriptExpr(First,
7478 Callee->getLocStart(),
7479 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007480 } else if (Op == OO_Arrow) {
7481 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007482 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7483 } else if (Second == 0 || isPostIncDec) {
7484 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485 // The argument is not of overloadable type, so try to create a
7486 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007487 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007489
John McCall9ae2f072010-08-23 23:25:46 +00007490 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007491 }
7492 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007493 if (!First->getType()->isOverloadableType() &&
7494 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007495 // Neither of the arguments is an overloadable type, so try to
7496 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007497 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007498 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007499 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503 return move(Result);
7504 }
7505 }
Mike Stump1eb44332009-09-09 15:08:12 +00007506
7507 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007509 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007510
John McCall9ae2f072010-08-23 23:25:46 +00007511 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007512 assert(ULE->requiresADL());
7513
7514 // FIXME: Do we have to check
7515 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007516 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007517 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007518 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007519 }
Mike Stump1eb44332009-09-09 15:08:12 +00007520
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007522 Expr *Args[2] = { First, Second };
7523 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007524
Douglas Gregorb98b1992009-08-11 05:31:07 +00007525 // Create the overloaded operator invocation for unary operators.
7526 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007527 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007528 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007529 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530 }
Mike Stump1eb44332009-09-09 15:08:12 +00007531
Sebastian Redlf322ed62009-10-29 20:17:01 +00007532 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007533 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007534 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007535 First,
7536 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007539 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007540 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007541 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7542 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007543 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007544
Mike Stump1eb44332009-09-09 15:08:12 +00007545 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007546}
Mike Stump1eb44332009-09-09 15:08:12 +00007547
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007549ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007550TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007551 SourceLocation OperatorLoc,
7552 bool isArrow,
7553 NestedNameSpecifier *Qualifier,
7554 SourceRange QualifierRange,
7555 TypeSourceInfo *ScopeType,
7556 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007557 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007558 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007559 CXXScopeSpec SS;
7560 if (Qualifier) {
7561 SS.setRange(QualifierRange);
7562 SS.setScopeRep(Qualifier);
7563 }
7564
John McCall9ae2f072010-08-23 23:25:46 +00007565 QualType BaseType = Base->getType();
7566 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007567 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007568 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007569 !BaseType->getAs<PointerType>()->getPointeeType()
7570 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007571 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007572 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007573 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007574 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007575 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007576 /*FIXME?*/true);
7577 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007578
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007579 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007580 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7581 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7582 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7583 NameInfo.setNamedTypeInfo(DestroyedType);
7584
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007585 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007586
John McCall9ae2f072010-08-23 23:25:46 +00007587 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007588 OperatorLoc, isArrow,
7589 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007590 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007591 /*TemplateArgs*/ 0);
7592}
7593
Douglas Gregor577f75a2009-08-04 16:50:30 +00007594} // end namespace clang
7595
7596#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H