blob: ca5d1c1ea0f3348b8302eac5118eb464cadfc359 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-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 McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000037using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000038
Douglas Gregord6ff3322009-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 Stump11289f42009-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 Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-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 Gregorebe10102009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-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 Gregord6ff3322009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
Douglas Gregora8bac7f2011-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 Gregord6ff3322009-08-04 16:50:30 +0000109protected:
110 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000111
Mike Stump11289f42009-09-09 15:08:12 +0000112public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000114 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000115
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000120 const Derived &getDerived() const {
121 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 }
123
John McCalldadc5752010-08-24 06:29:42 +0000124 static inline ExprResult Owned(Expr *E) { return E; }
125 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000126
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000130
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000137
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000141 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000142 /// provide an alternative implementation that provides better location
143 /// information.
144 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000145
Douglas Gregord6ff3322009-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 Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 public:
168 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000169 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 OldLocation = Self.getDerived().getBaseLocation();
171 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000172
173 if (Location.isValid())
174 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000175 }
Mike Stump11289f42009-09-09 15:08:12 +0000176
Douglas Gregora16548e2009-08-11 05:31:07 +0000177 ~TemporaryBase() {
178 Self.getDerived().setBase(OldLocation, OldEntity);
179 }
180 };
Mike Stump11289f42009-09-09 15:08:12 +0000181
182 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// transformed.
184 ///
185 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000186 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000187 /// not change. For example, template instantiation need not traverse
188 /// non-dependent types.
189 bool AlreadyTransformed(QualType T) {
190 return T.isNull();
191 }
192
Douglas Gregord196a582009-12-14 19:27:10 +0000193 /// \brief Determine whether the given call argument should be dropped, e.g.,
194 /// because it is a default argument.
195 ///
196 /// Subclasses can provide an alternative implementation of this routine to
197 /// determine which kinds of call arguments get dropped. By default,
198 /// CXXDefaultArgument nodes are dropped (prior to transformation).
199 bool DropCallArgument(Expr *E) {
200 return E->isDefaultArgument();
201 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000202
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000203 /// \brief Determine whether we should expand a pack expansion with the
204 /// given set of parameter packs into separate arguments by repeatedly
205 /// transforming the pattern.
206 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000207 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000208 /// Subclasses can override this routine to provide different behavior.
209 ///
210 /// \param EllipsisLoc The location of the ellipsis that identifies the
211 /// pack expansion.
212 ///
213 /// \param PatternRange The source range that covers the entire pattern of
214 /// the pack expansion.
215 ///
216 /// \param Unexpanded The set of unexpanded parameter packs within the
217 /// pattern.
218 ///
219 /// \param NumUnexpanded The number of unexpanded parameter packs in
220 /// \p Unexpanded.
221 ///
222 /// \param ShouldExpand Will be set to \c true if the transformer should
223 /// expand the corresponding pack expansions into separate arguments. When
224 /// set, \c NumExpansions must also be set.
225 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000226 /// \param RetainExpansion Whether the caller should add an unexpanded
227 /// pack expansion after all of the expanded arguments. This is used
228 /// when extending explicitly-specified template argument packs per
229 /// C++0x [temp.arg.explicit]p9.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000232 /// the expanded form of the corresponding pack expansion. This is both an
233 /// input and an output parameter, which can be set by the caller if the
234 /// number of expansions is known a priori (e.g., due to a prior substitution)
235 /// and will be set by the callee when the number of expansions is known.
236 /// The callee must set this value when \c ShouldExpand is \c true; it may
237 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000238 ///
239 /// \returns true if an error occurred (e.g., because the parameter packs
240 /// are to be instantiated with arguments of different lengths), false
241 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
242 /// must be set.
243 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
244 SourceRange PatternRange,
245 const UnexpandedParameterPack *Unexpanded,
246 unsigned NumUnexpanded,
247 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000248 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000249 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000250 ShouldExpand = false;
251 return false;
252 }
253
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000254 /// \brief "Forget" about the partially-substituted pack template argument,
255 /// when performing an instantiation that must preserve the parameter pack
256 /// use.
257 ///
258 /// This routine is meant to be overridden by the template instantiator.
259 TemplateArgument ForgetPartiallySubstitutedPack() {
260 return TemplateArgument();
261 }
262
263 /// \brief "Remember" the partially-substituted pack template argument
264 /// after performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
269
Douglas Gregorf3010112011-01-07 16:43:16 +0000270 /// \brief Note to the derived class when a function parameter pack is
271 /// being expanded.
272 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
273
Douglas Gregord6ff3322009-08-04 16:50:30 +0000274 /// \brief Transforms the given type into another type.
275 ///
John McCall550e0c22009-10-21 00:40:46 +0000276 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000277 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000278 /// function. This is expensive, but we don't mind, because
279 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000280 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 ///
282 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000283 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000284
John McCall550e0c22009-10-21 00:40:46 +0000285 /// \brief Transforms the given type-with-location into a new
286 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 ///
John McCall550e0c22009-10-21 00:40:46 +0000288 /// By default, this routine transforms a type by delegating to the
289 /// appropriate TransformXXXType to build a new type. Subclasses
290 /// may override this function (to take over all type
291 /// transformations) or some set of the TransformXXXType functions
292 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000293 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000294
295 /// \brief Transform the given type-with-location into a new
296 /// type, collecting location information in the given builder
297 /// as necessary.
298 ///
John McCall31f82722010-11-12 08:19:04 +0000299 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000300
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000301 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000302 ///
Mike Stump11289f42009-09-09 15:08:12 +0000303 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000304 /// appropriate TransformXXXStmt function to transform a specific kind of
305 /// statement or the TransformExpr() function to transform an expression.
306 /// Subclasses may override this function to transform statements using some
307 /// other mechanism.
308 ///
309 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000310 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000311
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000312 /// \brief Transform the given expression.
313 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000314 /// By default, this routine transforms an expression by delegating to the
315 /// appropriate TransformXXXExpr function to build a new expression.
316 /// Subclasses may override this function to transform expressions using some
317 /// other mechanism.
318 ///
319 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000320 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000321
Douglas Gregora3efea12011-01-03 19:04:46 +0000322 /// \brief Transform the given list of expressions.
323 ///
324 /// This routine transforms a list of expressions by invoking
325 /// \c TransformExpr() for each subexpression. However, it also provides
326 /// support for variadic templates by expanding any pack expansions (if the
327 /// derived class permits such expansion) along the way. When pack expansions
328 /// are present, the number of outputs may not equal the number of inputs.
329 ///
330 /// \param Inputs The set of expressions to be transformed.
331 ///
332 /// \param NumInputs The number of expressions in \c Inputs.
333 ///
334 /// \param IsCall If \c true, then this transform is being performed on
335 /// function-call arguments, and any arguments that should be dropped, will
336 /// be.
337 ///
338 /// \param Outputs The transformed input expressions will be added to this
339 /// vector.
340 ///
341 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
342 /// due to transformation.
343 ///
344 /// \returns true if an error occurred, false otherwise.
345 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
346 llvm::SmallVectorImpl<Expr *> &Outputs,
347 bool *ArgChanged = 0);
348
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 /// \brief Transform the given declaration, which is referenced from a type
350 /// or expression.
351 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000352 /// By default, acts as the identity function on declarations. Subclasses
353 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000354 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000355
356 /// \brief Transform the definition of the given declaration.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000359 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000360 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
361 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000362 }
Mike Stump11289f42009-09-09 15:08:12 +0000363
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000364 /// \brief Transform the given declaration, which was the first part of a
365 /// nested-name-specifier in a member access expression.
366 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000367 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000368 /// identifier in a nested-name-specifier of a member access expression, e.g.,
369 /// the \c T in \c x->T::member
370 ///
371 /// By default, invokes TransformDecl() to transform the declaration.
372 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000373 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
374 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000375 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given nested-name-specifier.
378 ///
Mike Stump11289f42009-09-09 15:08:12 +0000379 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000380 /// nested-name-specifier. Subclasses may override this function to provide
381 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000383 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000384 QualType ObjectType = QualType(),
385 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000386
Douglas Gregorf816bd72009-09-03 22:13:48 +0000387 /// \brief Transform the given declaration name.
388 ///
389 /// By default, transforms the types of conversion function, constructor,
390 /// and destructor names and then (if needed) rebuilds the declaration name.
391 /// Identifiers and selectors are returned unmodified. Sublcasses may
392 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000393 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000394 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000397 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000398 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000399 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000400 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000401 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000402 QualType ObjectType = QualType(),
403 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000404
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// \brief Transform the given template argument.
406 ///
Mike Stump11289f42009-09-09 15:08:12 +0000407 /// By default, this operation transforms the type, expression, or
408 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000409 /// new template argument from the transformed result. Subclasses may
410 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000411 ///
412 /// Returns true if there was an error.
413 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
414 TemplateArgumentLoc &Output);
415
Douglas Gregor62e06f22010-12-20 17:31:10 +0000416 /// \brief Transform the given set of template arguments.
417 ///
418 /// By default, this operation transforms all of the template arguments
419 /// in the input set using \c TransformTemplateArgument(), and appends
420 /// the transformed arguments to the output list.
421 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000422 /// Note that this overload of \c TransformTemplateArguments() is merely
423 /// a convenience function. Subclasses that wish to override this behavior
424 /// should override the iterator-based member template version.
425 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000426 /// \param Inputs The set of template arguments to be transformed.
427 ///
428 /// \param NumInputs The number of template arguments in \p Inputs.
429 ///
430 /// \param Outputs The set of transformed template arguments output by this
431 /// routine.
432 ///
433 /// Returns true if an error occurred.
434 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
435 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000436 TemplateArgumentListInfo &Outputs) {
437 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
438 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000439
440 /// \brief Transform the given set of template arguments.
441 ///
442 /// By default, this operation transforms all of the template arguments
443 /// in the input set using \c TransformTemplateArgument(), and appends
444 /// the transformed arguments to the output list.
445 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000446 /// \param First An iterator to the first template argument.
447 ///
448 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000454 template<typename InputIterator>
455 bool TransformTemplateArguments(InputIterator First,
456 InputIterator Last,
457 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000458
John McCall0ad16662009-10-29 08:12:44 +0000459 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
460 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
461 TemplateArgumentLoc &ArgLoc);
462
John McCallbcd03502009-12-07 02:54:59 +0000463 /// \brief Fakes up a TypeSourceInfo for a type.
464 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
465 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000466 getDerived().getBaseLocation());
467 }
Mike Stump11289f42009-09-09 15:08:12 +0000468
John McCall550e0c22009-10-21 00:40:46 +0000469#define ABSTRACT_TYPELOC(CLASS, PARENT)
470#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000471 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000472#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000473
John McCall31f82722010-11-12 08:19:04 +0000474 QualType
475 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
476 TemplateSpecializationTypeLoc TL,
477 TemplateName Template);
478
479 QualType
480 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
481 DependentTemplateSpecializationTypeLoc TL,
482 NestedNameSpecifier *Prefix);
483
John McCall58f10c32010-03-11 09:03:00 +0000484 /// \brief Transforms the parameters of a function type into the
485 /// given vectors.
486 ///
487 /// The result vectors should be kept in sync; null entries in the
488 /// variables vector are acceptable.
489 ///
490 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000491 bool TransformFunctionTypeParams(SourceLocation Loc,
492 ParmVarDecl **Params, unsigned NumParams,
493 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000494 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000495 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000496
497 /// \brief Transforms a single function-type parameter. Return null
498 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000499 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
500 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000501
John McCall31f82722010-11-12 08:19:04 +0000502 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000503
John McCalldadc5752010-08-24 06:29:42 +0000504 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
505 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000506
Douglas Gregorebe10102009-08-20 07:17:43 +0000507#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000508 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000509#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000510 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000511#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000512#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000513
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 /// \brief Build a new pointer type given its pointee type.
515 ///
516 /// By default, performs semantic analysis when building the pointer type.
517 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000518 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000519
520 /// \brief Build a new block pointer type given its pointee type.
521 ///
Mike Stump11289f42009-09-09 15:08:12 +0000522 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000524 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525
John McCall70dd5f62009-10-30 00:06:24 +0000526 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000527 ///
John McCall70dd5f62009-10-30 00:06:24 +0000528 /// By default, performs semantic analysis when building the
529 /// reference type. Subclasses may override this routine to provide
530 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 ///
John McCall70dd5f62009-10-30 00:06:24 +0000532 /// \param LValue whether the type was written with an lvalue sigil
533 /// or an rvalue sigil.
534 QualType RebuildReferenceType(QualType ReferentType,
535 bool LValue,
536 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000537
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538 /// \brief Build a new member pointer type given the pointee type and the
539 /// class type it refers into.
540 ///
541 /// By default, performs semantic analysis when building the member pointer
542 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000543 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
544 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000545
Douglas Gregord6ff3322009-08-04 16:50:30 +0000546 /// \brief Build a new array type given the element type, size
547 /// modifier, size of the array (if known), size expression, and index type
548 /// qualifiers.
549 ///
550 /// By default, performs semantic analysis when building the array type.
551 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000552 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 QualType RebuildArrayType(QualType ElementType,
554 ArrayType::ArraySizeModifier SizeMod,
555 const llvm::APInt *Size,
556 Expr *SizeExpr,
557 unsigned IndexTypeQuals,
558 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000559
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// \brief Build a new constant array type given the element type, size
561 /// modifier, (known) size of the array, and index type qualifiers.
562 ///
563 /// By default, performs semantic analysis when building the array type.
564 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000565 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000566 ArrayType::ArraySizeModifier SizeMod,
567 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000568 unsigned IndexTypeQuals,
569 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new incomplete array type given the element type, size
572 /// modifier, and index type qualifiers.
573 ///
574 /// By default, performs semantic analysis when building the array type.
575 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000576 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000577 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000578 unsigned IndexTypeQuals,
579 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000580
Mike Stump11289f42009-09-09 15:08:12 +0000581 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 /// size modifier, size expression, and index type qualifiers.
583 ///
584 /// By default, performs semantic analysis when building the array type.
585 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000586 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000588 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000589 unsigned IndexTypeQuals,
590 SourceRange BracketsRange);
591
Mike Stump11289f42009-09-09 15:08:12 +0000592 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// size modifier, size expression, and index type qualifiers.
594 ///
595 /// By default, performs semantic analysis when building the array type.
596 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000597 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000598 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000599 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000600 unsigned IndexTypeQuals,
601 SourceRange BracketsRange);
602
603 /// \brief Build a new vector type given the element type and
604 /// number of elements.
605 ///
606 /// By default, performs semantic analysis when building the vector type.
607 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000608 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000609 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000610
Douglas Gregord6ff3322009-08-04 16:50:30 +0000611 /// \brief Build a new extended vector type given the element type and
612 /// number of elements.
613 ///
614 /// By default, performs semantic analysis when building the vector type.
615 /// Subclasses may override this routine to provide different behavior.
616 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
617 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000618
619 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 /// given the element type and number of elements.
621 ///
622 /// By default, performs semantic analysis when building the vector type.
623 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000624 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000625 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new function type.
629 ///
630 /// By default, performs semantic analysis when building the function type.
631 /// Subclasses may override this routine to provide different behavior.
632 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000633 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000635 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000636 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000637 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000638
John McCall550e0c22009-10-21 00:40:46 +0000639 /// \brief Build a new unprototyped function type.
640 QualType RebuildFunctionNoProtoType(QualType ResultType);
641
John McCallb96ec562009-12-04 22:46:56 +0000642 /// \brief Rebuild an unresolved typename type, given the decl that
643 /// the UnresolvedUsingTypenameDecl was transformed to.
644 QualType RebuildUnresolvedUsingType(Decl *D);
645
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 /// \brief Build a new typedef type.
647 QualType RebuildTypedefType(TypedefDecl *Typedef) {
648 return SemaRef.Context.getTypeDeclType(Typedef);
649 }
650
651 /// \brief Build a new class/struct/union type.
652 QualType RebuildRecordType(RecordDecl *Record) {
653 return SemaRef.Context.getTypeDeclType(Record);
654 }
655
656 /// \brief Build a new Enum type.
657 QualType RebuildEnumType(EnumDecl *Enum) {
658 return SemaRef.Context.getTypeDeclType(Enum);
659 }
John McCallfcc33b02009-09-05 00:15:47 +0000660
Mike Stump11289f42009-09-09 15:08:12 +0000661 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000662 ///
663 /// By default, performs semantic analysis when building the typeof type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000665 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
Mike Stump11289f42009-09-09 15:08:12 +0000667 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000668 ///
669 /// By default, builds a new TypeOfType with the given underlying type.
670 QualType RebuildTypeOfType(QualType Underlying);
671
Mike Stump11289f42009-09-09 15:08:12 +0000672 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000673 ///
674 /// By default, performs semantic analysis when building the decltype type.
675 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000676 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000677
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 /// \brief Build a new template specialization type.
679 ///
680 /// By default, performs semantic analysis when building the template
681 /// specialization type. Subclasses may override this routine to provide
682 /// different behavior.
683 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000684 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000685 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000686
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000687 /// \brief Build a new parenthesized type.
688 ///
689 /// By default, builds a new ParenType type from the inner type.
690 /// Subclasses may override this routine to provide different behavior.
691 QualType RebuildParenType(QualType InnerType) {
692 return SemaRef.Context.getParenType(InnerType);
693 }
694
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 /// \brief Build a new qualified name type.
696 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000697 /// By default, builds a new ElaboratedType type from the keyword,
698 /// the nested-name-specifier and the named type.
699 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000700 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
701 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000702 NestedNameSpecifier *NNS, QualType Named) {
703 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000704 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000705
706 /// \brief Build a new typename type that refers to a template-id.
707 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000708 /// By default, builds a new DependentNameType type from the
709 /// nested-name-specifier and the given type. Subclasses may override
710 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000711 QualType RebuildDependentTemplateSpecializationType(
712 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000713 NestedNameSpecifier *Qualifier,
714 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000715 const IdentifierInfo *Name,
716 SourceLocation NameLoc,
717 const TemplateArgumentListInfo &Args) {
718 // Rebuild the template name.
719 // TODO: avoid TemplateName abstraction
720 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000721 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000722 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000723
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000724 if (InstName.isNull())
725 return QualType();
726
John McCallc392f372010-06-11 00:33:02 +0000727 // If it's still dependent, make a dependent specialization.
728 if (InstName.getAsDependentTemplateName())
729 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000730 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000731
732 // Otherwise, make an elaborated type wrapping a non-dependent
733 // specialization.
734 QualType T =
735 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
736 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000737
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000738 // NOTE: NNS is already recorded in template specialization type T.
739 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000740 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741
742 /// \brief Build a new typename type that refers to an identifier.
743 ///
744 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000745 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000747 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000748 NestedNameSpecifier *NNS,
749 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000750 SourceLocation KeywordLoc,
751 SourceRange NNSRange,
752 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000753 CXXScopeSpec SS;
754 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000755 SS.setRange(NNSRange);
756
Douglas Gregore677daf2010-03-31 22:19:08 +0000757 if (NNS->isDependent()) {
758 // If the name is still dependent, just build a new dependent name type.
759 if (!SemaRef.computeDeclContext(SS))
760 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
761 }
762
Abramo Bagnara6150c882010-05-11 21:36:43 +0000763 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000764 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
765 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000766
767 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
768
Abramo Bagnarad7548482010-05-19 21:37:53 +0000769 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000770 // into a non-dependent elaborated-type-specifier. Find the tag we're
771 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000772 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000773 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
774 if (!DC)
775 return QualType();
776
John McCallbf8c5192010-05-27 06:40:31 +0000777 if (SemaRef.RequireCompleteDeclContext(SS, DC))
778 return QualType();
779
Douglas Gregore677daf2010-03-31 22:19:08 +0000780 TagDecl *Tag = 0;
781 SemaRef.LookupQualifiedName(Result, DC);
782 switch (Result.getResultKind()) {
783 case LookupResult::NotFound:
784 case LookupResult::NotFoundInCurrentInstantiation:
785 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000786
Douglas Gregore677daf2010-03-31 22:19:08 +0000787 case LookupResult::Found:
788 Tag = Result.getAsSingle<TagDecl>();
789 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000790
Douglas Gregore677daf2010-03-31 22:19:08 +0000791 case LookupResult::FoundOverloaded:
792 case LookupResult::FoundUnresolvedValue:
793 llvm_unreachable("Tag lookup cannot find non-tags");
794 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000795
Douglas Gregore677daf2010-03-31 22:19:08 +0000796 case LookupResult::Ambiguous:
797 // Let the LookupResult structure handle ambiguities.
798 return QualType();
799 }
800
801 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000802 // Check where the name exists but isn't a tag type and use that to emit
803 // better diagnostics.
804 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
805 SemaRef.LookupQualifiedName(Result, DC);
806 switch (Result.getResultKind()) {
807 case LookupResult::Found:
808 case LookupResult::FoundOverloaded:
809 case LookupResult::FoundUnresolvedValue: {
810 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
811 unsigned Kind = 0;
812 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
813 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
814 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
815 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
816 break;
817 }
818 default:
819 // FIXME: Would be nice to highlight just the source range.
820 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
821 << Kind << Id << DC;
822 break;
823 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 return QualType();
825 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000826
Abramo Bagnarad7548482010-05-19 21:37:53 +0000827 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
828 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000829 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
830 return QualType();
831 }
832
833 // Build the elaborated-type-specifier type.
834 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000835 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000836 }
Mike Stump11289f42009-09-09 15:08:12 +0000837
Douglas Gregor822d0302011-01-12 17:07:58 +0000838 /// \brief Build a new pack expansion type.
839 ///
840 /// By default, builds a new PackExpansionType type from the given pattern.
841 /// Subclasses may override this routine to provide different behavior.
842 QualType RebuildPackExpansionType(QualType Pattern,
843 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000844 SourceLocation EllipsisLoc,
845 llvm::Optional<unsigned> NumExpansions) {
846 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
847 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000848 }
849
Douglas Gregor1135c352009-08-06 05:28:30 +0000850 /// \brief Build a new nested-name-specifier given the prefix and an
851 /// identifier that names the next step in the nested-name-specifier.
852 ///
853 /// By default, performs semantic analysis when building the new
854 /// nested-name-specifier. Subclasses may override this routine to provide
855 /// different behavior.
856 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
857 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000858 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000859 QualType ObjectType,
860 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000861
862 /// \brief Build a new nested-name-specifier given the prefix and the
863 /// namespace named in the next step in the nested-name-specifier.
864 ///
865 /// By default, performs semantic analysis when building the new
866 /// nested-name-specifier. Subclasses may override this routine to provide
867 /// different behavior.
868 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
869 SourceRange Range,
870 NamespaceDecl *NS);
871
872 /// \brief Build a new nested-name-specifier given the prefix and the
873 /// type named in the next step in the nested-name-specifier.
874 ///
875 /// By default, performs semantic analysis when building the new
876 /// nested-name-specifier. Subclasses may override this routine to provide
877 /// different behavior.
878 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
879 SourceRange Range,
880 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000881 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000882
883 /// \brief Build a new template name given a nested name specifier, a flag
884 /// indicating whether the "template" keyword was provided, and the template
885 /// that the template name refers to.
886 ///
887 /// By default, builds the new template name directly. Subclasses may override
888 /// this routine to provide different behavior.
889 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
890 bool TemplateKW,
891 TemplateDecl *Template);
892
Douglas Gregor71dc5092009-08-06 06:41:21 +0000893 /// \brief Build a new template name given a nested name specifier and the
894 /// name that is referred to as a template.
895 ///
896 /// By default, performs semantic analysis to determine whether the name can
897 /// be resolved to a specific template, then builds the appropriate kind of
898 /// template name. Subclasses may override this routine to provide different
899 /// behavior.
900 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000901 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000902 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000903 QualType ObjectType,
904 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000905
Douglas Gregor71395fa2009-11-04 00:56:37 +0000906 /// \brief Build a new template name given a nested name specifier and the
907 /// overloaded operator name that is referred to as a template.
908 ///
909 /// By default, performs semantic analysis to determine whether the name can
910 /// be resolved to a specific template, then builds the appropriate kind of
911 /// template name. Subclasses may override this routine to provide different
912 /// behavior.
913 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
914 OverloadedOperatorKind Operator,
915 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000916
917 /// \brief Build a new template name given a template template parameter pack
918 /// and the
919 ///
920 /// By default, performs semantic analysis to determine whether the name can
921 /// be resolved to a specific template, then builds the appropriate kind of
922 /// template name. Subclasses may override this routine to provide different
923 /// behavior.
924 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
925 const TemplateArgument &ArgPack) {
926 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
927 }
928
Douglas Gregorebe10102009-08-20 07:17:43 +0000929 /// \brief Build a new compound statement.
930 ///
931 /// By default, performs semantic analysis to build the new statement.
932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000933 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000934 MultiStmtArg Statements,
935 SourceLocation RBraceLoc,
936 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000937 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000938 IsStmtExpr);
939 }
940
941 /// \brief Build a new case statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000945 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000946 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000947 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000948 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000950 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000951 ColonLoc);
952 }
Mike Stump11289f42009-09-09 15:08:12 +0000953
Douglas Gregorebe10102009-08-20 07:17:43 +0000954 /// \brief Attach the body to a new case statement.
955 ///
956 /// By default, performs semantic analysis to build the new statement.
957 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000958 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000959 getSema().ActOnCaseStmtBody(S, Body);
960 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000961 }
Mike Stump11289f42009-09-09 15:08:12 +0000962
Douglas Gregorebe10102009-08-20 07:17:43 +0000963 /// \brief Build a new default statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000967 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000968 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000969 Stmt *SubStmt) {
970 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000971 /*CurScope=*/0);
972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Build a new label statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 IdentifierInfo *Id,
980 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000981 Stmt *SubStmt, bool HasUnusedAttr) {
982 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
983 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregorebe10102009-08-20 07:17:43 +0000986 /// \brief Build a new "if" statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000990 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000991 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000992 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000993 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 }
Mike Stump11289f42009-09-09 15:08:12 +0000995
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 /// \brief Start building a new switch statement.
997 ///
998 /// By default, performs semantic analysis to build the new statement.
999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001000 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +00001001 Expr *Cond, VarDecl *CondVar) {
1002 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001003 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Attach the body to the switch statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001010 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +00001011 Stmt *Switch, Stmt *Body) {
1012 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001013 }
1014
1015 /// \brief Build a new while statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001019 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00001020 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001021 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +00001022 Stmt *Body) {
1023 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001024 }
Mike Stump11289f42009-09-09 15:08:12 +00001025
Douglas Gregorebe10102009-08-20 07:17:43 +00001026 /// \brief Build a new do-while statement.
1027 ///
1028 /// By default, performs semantic analysis to build the new statement.
1029 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001030 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 SourceLocation WhileLoc,
1032 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001033 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +00001034 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001035 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1036 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001037 }
1038
1039 /// \brief Build a new for statement.
1040 ///
1041 /// By default, performs semantic analysis to build the new statement.
1042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001043 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001044 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001045 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001046 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +00001047 SourceLocation RParenLoc, Stmt *Body) {
1048 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +00001049 CondVar,
John McCallb268a282010-08-23 23:25:46 +00001050 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregorebe10102009-08-20 07:17:43 +00001053 /// \brief Build a new goto statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001057 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001058 SourceLocation LabelLoc,
1059 LabelStmt *Label) {
1060 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1061 }
1062
1063 /// \brief Build a new indirect goto statement.
1064 ///
1065 /// By default, performs semantic analysis to build the new statement.
1066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001067 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +00001069 Expr *Target) {
1070 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Douglas Gregorebe10102009-08-20 07:17:43 +00001073 /// \brief Build a new return statement.
1074 ///
1075 /// By default, performs semantic analysis to build the new statement.
1076 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001077 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +00001078 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +00001079
John McCallb268a282010-08-23 23:25:46 +00001080 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001081 }
Mike Stump11289f42009-09-09 15:08:12 +00001082
Douglas Gregorebe10102009-08-20 07:17:43 +00001083 /// \brief Build a new declaration statement.
1084 ///
1085 /// By default, performs semantic analysis to build the new statement.
1086 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001087 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001088 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 SourceLocation EndLoc) {
1090 return getSema().Owned(
1091 new (getSema().Context) DeclStmt(
1092 DeclGroupRef::Create(getSema().Context,
1093 Decls, NumDecls),
1094 StartLoc, EndLoc));
1095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Anders Carlssonaaeef072010-01-24 05:50:09 +00001097 /// \brief Build a new inline asm statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001102 bool IsSimple,
1103 bool IsVolatile,
1104 unsigned NumOutputs,
1105 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001106 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001107 MultiExprArg Constraints,
1108 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001109 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001110 MultiExprArg Clobbers,
1111 SourceLocation RParenLoc,
1112 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001113 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001114 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001115 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001116 RParenLoc, MSAsm);
1117 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001118
1119 /// \brief Build a new Objective-C @try statement.
1120 ///
1121 /// By default, performs semantic analysis to build the new statement.
1122 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001123 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001124 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001125 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001126 Stmt *Finally) {
1127 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1128 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001129 }
1130
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001131 /// \brief Rebuild an Objective-C exception declaration.
1132 ///
1133 /// By default, performs semantic analysis to build the new declaration.
1134 /// Subclasses may override this routine to provide different behavior.
1135 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1136 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001137 return getSema().BuildObjCExceptionDecl(TInfo, T,
1138 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001139 ExceptionDecl->getLocation());
1140 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001141
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001142 /// \brief Build a new Objective-C @catch statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001147 SourceLocation RParenLoc,
1148 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001149 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001150 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001151 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001153
Douglas Gregor306de2f2010-04-22 23:59:56 +00001154 /// \brief Build a new Objective-C @finally statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001159 Stmt *Body) {
1160 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001161 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001162
Douglas Gregor6148de72010-04-22 22:01:21 +00001163 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001164 ///
1165 /// By default, performs semantic analysis to build the new statement.
1166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001167 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001168 Expr *Operand) {
1169 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001170 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001171
Douglas Gregor6148de72010-04-22 22:01:21 +00001172 /// \brief Build a new Objective-C @synchronized statement.
1173 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001177 Expr *Object,
1178 Stmt *Body) {
1179 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1180 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001181 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001182
1183 /// \brief Build a new Objective-C fast enumeration statement.
1184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001187 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001188 SourceLocation LParenLoc,
1189 Stmt *Element,
1190 Expr *Collection,
1191 SourceLocation RParenLoc,
1192 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001193 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001194 Element,
1195 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001196 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001197 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001198 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new C++ exception declaration.
1201 ///
1202 /// By default, performs semantic analysis to build the new decaration.
1203 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001204 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001205 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001206 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001207 SourceLocation Loc) {
1208 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001209 }
1210
1211 /// \brief Build a new C++ catch statement.
1212 ///
1213 /// By default, performs semantic analysis to build the new statement.
1214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001215 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001216 VarDecl *ExceptionDecl,
1217 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001218 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1219 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 /// \brief Build a new C++ try statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001226 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001227 Stmt *TryBlock,
1228 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001229 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// \brief Build a new expression that references a declaration.
1233 ///
1234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001236 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001237 LookupResult &R,
1238 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001239 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1240 }
1241
1242
1243 /// \brief Build a new expression that references a declaration.
1244 ///
1245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001247 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001248 SourceRange QualifierRange,
1249 ValueDecl *VD,
1250 const DeclarationNameInfo &NameInfo,
1251 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001252 CXXScopeSpec SS;
1253 SS.setScopeRep(Qualifier);
1254 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001255
1256 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001257
1258 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001262 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001265 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001267 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 }
1269
Douglas Gregorad8a3362009-09-04 17:36:40 +00001270 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001271 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001272 /// By default, performs semantic analysis to build the new expression.
1273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001274 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001275 SourceLocation OperatorLoc,
1276 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001277 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001278 SourceRange QualifierRange,
1279 TypeSourceInfo *ScopeType,
1280 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001281 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001282 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001283
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001285 ///
Douglas Gregora16548e2009-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 McCalldadc5752010-08-24 06:29:42 +00001288 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001289 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001290 Expr *SubExpr) {
1291 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 }
Mike Stump11289f42009-09-09 15:08:12 +00001293
Douglas Gregor882211c2010-04-28 22:16:22 +00001294 /// \brief Build a new builtin offsetof expression.
1295 ///
1296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001298 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001299 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001300 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001301 unsigned NumComponents,
1302 SourceLocation RParenLoc) {
1303 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1304 NumComponents, RParenLoc);
1305 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001308 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001312 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001314 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 }
1316
Mike Stump11289f42009-09-09 15:08:12 +00001317 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001319 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001322 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001324 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001325 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001328
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 return move(Result);
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001336 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001338 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001340 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1341 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 RBracketLoc);
1343 }
1344
1345 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001346 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001349 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001351 SourceLocation RParenLoc,
1352 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001353 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001354 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 }
1356
1357 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001358 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001361 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001362 bool isArrow,
1363 NestedNameSpecifier *Qualifier,
1364 SourceRange QualifierRange,
1365 const DeclarationNameInfo &MemberNameInfo,
1366 ValueDecl *Member,
1367 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001368 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001369 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001370 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001371 // We have a reference to an unnamed field. This is always the
1372 // base of an anonymous struct/union member access, i.e. the
1373 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001374 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001375 assert(Member->getType()->isRecordType() &&
1376 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001377
John McCallb268a282010-08-23 23:25:46 +00001378 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001379 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001380 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001381
John McCall7decc9e2010-11-18 06:31:45 +00001382 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001383 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001384 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001385 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001386 cast<FieldDecl>(Member)->getType(),
1387 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001388 return getSema().Owned(ME);
1389 }
Mike Stump11289f42009-09-09 15:08:12 +00001390
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001391 CXXScopeSpec SS;
1392 if (Qualifier) {
1393 SS.setRange(QualifierRange);
1394 SS.setScopeRep(Qualifier);
1395 }
1396
John McCallb268a282010-08-23 23:25:46 +00001397 getSema().DefaultFunctionArrayConversion(Base);
1398 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001399
John McCall16df1e52010-03-30 21:47:33 +00001400 // FIXME: this involves duplicating earlier analysis in a lot of
1401 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001402 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001403 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001404 R.resolveKind();
1405
John McCallb268a282010-08-23 23:25:46 +00001406 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001407 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001408 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 }
Mike Stump11289f42009-09-09 15:08:12 +00001410
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001412 ///
Douglas Gregora16548e2009-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 McCalldadc5752010-08-24 06:29:42 +00001415 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001416 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001417 Expr *LHS, Expr *RHS) {
1418 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 }
1420
1421 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001422 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001425 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001427 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001429 Expr *RHS) {
1430 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1431 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 }
1433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001439 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001441 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001442 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001443 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 }
Mike Stump11289f42009-09-09 15:08:12 +00001445
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001447 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001450 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001451 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001453 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001454 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 }
Mike Stump11289f42009-09-09 15:08:12 +00001457
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001459 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001462 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 SourceLocation OpLoc,
1464 SourceLocation AccessorLoc,
1465 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001466
John McCall10eae182009-11-30 22:42:35 +00001467 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001468 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001469 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001470 OpLoc, /*IsArrow*/ false,
1471 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001472 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001473 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 }
Mike Stump11289f42009-09-09 15:08:12 +00001475
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001477 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 /// By default, performs semantic analysis to build the new expression.
1479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001480 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001482 SourceLocation RBraceLoc,
1483 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001484 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001485 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1486 if (Result.isInvalid() || ResultTy->isDependentType())
1487 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001488
Douglas Gregord3d93062009-11-09 17:16:50 +00001489 // Patch in the result type we were given, which may have been computed
1490 // when the initial InitListExpr was built.
1491 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1492 ILE->setType(ResultTy);
1493 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 }
Mike Stump11289f42009-09-09 15:08:12 +00001495
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001497 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001500 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 MultiExprArg ArrayExprs,
1502 SourceLocation EqualOrColonLoc,
1503 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001504 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001505 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001507 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 ArrayExprs.release();
1512 return move(Result);
1513 }
Mike Stump11289f42009-09-09 15:08:12 +00001514
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001516 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// By default, builds the implicit value initialization without performing
1518 /// any semantic analysis. Subclasses may override this routine to provide
1519 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001520 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001525 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001528 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001529 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001530 SourceLocation RParenLoc) {
1531 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001532 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001533 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
1535
1536 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001537 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001540 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 MultiExprArg SubExprs,
1542 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001543 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001544 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 }
Mike Stump11289f42009-09-09 15:08:12 +00001546
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001548 ///
1549 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// rather than attempting to map the label statement itself.
1551 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001552 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 SourceLocation LabelLoc,
1554 LabelStmt *Label) {
1555 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1556 }
Mike Stump11289f42009-09-09 15:08:12 +00001557
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001559 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001563 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001565 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new __builtin_choose_expr expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001572 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001573 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 SourceLocation RParenLoc) {
1575 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001576 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 RParenLoc);
1578 }
Mike Stump11289f42009-09-09 15:08:12 +00001579
Douglas Gregora16548e2009-08-11 05:31:07 +00001580 /// \brief Build a new overloaded operator call expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// The semantic analysis provides the behavior of template instantiation,
1584 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001585 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 /// argument-dependent lookup, etc. Subclasses may override this routine to
1587 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001590 Expr *Callee,
1591 Expr *First,
1592 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001593
1594 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// reinterpret_cast.
1596 ///
1597 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001598 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001600 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 Stmt::StmtClass Class,
1602 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001603 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 SourceLocation RAngleLoc,
1605 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001606 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 SourceLocation RParenLoc) {
1608 switch (Class) {
1609 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001610 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001611 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001612 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001613
1614 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001615 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001616 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001618
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001620 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001621 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001622 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001626 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001627 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001628 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001629
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 default:
1631 assert(false && "Invalid C++ named cast");
1632 break;
1633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
John McCallfaf5fb42010-08-26 23:41:50 +00001635 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new C++ static_cast expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001642 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001644 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 SourceLocation RAngleLoc,
1646 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001647 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001649 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001650 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001651 SourceRange(LAngleLoc, RAngleLoc),
1652 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 }
1654
1655 /// \brief Build a new C++ dynamic_cast expression.
1656 ///
1657 /// By default, performs semantic analysis to build the new expression.
1658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001659 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001661 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 SourceLocation RAngleLoc,
1663 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001664 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001666 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001667 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001668 SourceRange(LAngleLoc, RAngleLoc),
1669 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 }
1671
1672 /// \brief Build a new C++ reinterpret_cast expression.
1673 ///
1674 /// By default, performs semantic analysis to build the new expression.
1675 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001676 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001678 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 SourceLocation RAngleLoc,
1680 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001681 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001683 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001684 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001685 SourceRange(LAngleLoc, RAngleLoc),
1686 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 }
1688
1689 /// \brief Build a new C++ const_cast expression.
1690 ///
1691 /// By default, performs semantic analysis to build the new expression.
1692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001693 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001695 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 SourceLocation RAngleLoc,
1697 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001698 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001700 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001701 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001702 SourceRange(LAngleLoc, RAngleLoc),
1703 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 /// \brief Build a new C++ functional-style cast expression.
1707 ///
1708 /// By default, performs semantic analysis to build the new expression.
1709 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001710 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1711 SourceLocation LParenLoc,
1712 Expr *Sub,
1713 SourceLocation RParenLoc) {
1714 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001715 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 RParenLoc);
1717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 /// \brief Build a new C++ typeid(type) expression.
1720 ///
1721 /// By default, performs semantic analysis to build the new expression.
1722 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001723 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001724 SourceLocation TypeidLoc,
1725 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001727 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001728 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001729 }
Mike Stump11289f42009-09-09 15:08:12 +00001730
Francois Pichet9f4f2072010-09-08 12:20:18 +00001731
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 /// \brief Build a new C++ typeid(expr) expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001736 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001737 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001738 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001740 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001741 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001742 }
1743
Francois Pichet9f4f2072010-09-08 12:20:18 +00001744 /// \brief Build a new C++ __uuidof(type) expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
1748 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1749 SourceLocation TypeidLoc,
1750 TypeSourceInfo *Operand,
1751 SourceLocation RParenLoc) {
1752 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1753 RParenLoc);
1754 }
1755
1756 /// \brief Build a new C++ __uuidof(expr) expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
1760 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1761 SourceLocation TypeidLoc,
1762 Expr *Operand,
1763 SourceLocation RParenLoc) {
1764 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1765 RParenLoc);
1766 }
1767
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// \brief Build a new C++ "this" expression.
1769 ///
1770 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001771 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001774 QualType ThisType,
1775 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001777 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1778 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 }
1780
1781 /// \brief Build a new C++ throw expression.
1782 ///
1783 /// By default, performs semantic analysis to build the new expression.
1784 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001785 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001786 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ default-argument expression.
1790 ///
1791 /// By default, builds a new default-argument expression, which does not
1792 /// require any semantic analysis. Subclasses may override this routine to
1793 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001794 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001795 ParmVarDecl *Param) {
1796 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1797 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
1799
1800 /// \brief Build a new C++ zero-initialization expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001804 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1805 SourceLocation LParenLoc,
1806 SourceLocation RParenLoc) {
1807 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001808 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001809 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 }
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregora16548e2009-08-11 05:31:07 +00001812 /// \brief Build a new C++ "new" expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001816 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001817 bool UseGlobal,
1818 SourceLocation PlacementLParen,
1819 MultiExprArg PlacementArgs,
1820 SourceLocation PlacementRParen,
1821 SourceRange TypeIdParens,
1822 QualType AllocatedType,
1823 TypeSourceInfo *AllocatedTypeInfo,
1824 Expr *ArraySize,
1825 SourceLocation ConstructorLParen,
1826 MultiExprArg ConstructorArgs,
1827 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001828 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 PlacementLParen,
1830 move(PlacementArgs),
1831 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001832 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001833 AllocatedType,
1834 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001835 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 ConstructorLParen,
1837 move(ConstructorArgs),
1838 ConstructorRParen);
1839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// \brief Build a new C++ "delete" expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001845 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 bool IsGlobalDelete,
1847 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001848 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001850 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregora16548e2009-08-11 05:31:07 +00001853 /// \brief Build a new unary type trait expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001857 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001858 SourceLocation StartLoc,
1859 TypeSourceInfo *T,
1860 SourceLocation RParenLoc) {
1861 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 }
1863
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001864 /// \brief Build a new binary type trait expression.
1865 ///
1866 /// By default, performs semantic analysis to build the new expression.
1867 /// Subclasses may override this routine to provide different behavior.
1868 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1869 SourceLocation StartLoc,
1870 TypeSourceInfo *LhsT,
1871 TypeSourceInfo *RhsT,
1872 SourceLocation RParenLoc) {
1873 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1874 }
1875
Mike Stump11289f42009-09-09 15:08:12 +00001876 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 /// expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001881 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001883 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001884 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001885 CXXScopeSpec SS;
1886 SS.setRange(QualifierRange);
1887 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001888
1889 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001890 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001891 *TemplateArgs);
1892
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001893 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 }
1895
1896 /// \brief Build a new template-id expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001900 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001901 LookupResult &R,
1902 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001903 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001904 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 }
1906
1907 /// \brief Build a new object-construction expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001911 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001912 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 CXXConstructorDecl *Constructor,
1914 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001915 MultiExprArg Args,
1916 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001917 CXXConstructExpr::ConstructionKind ConstructKind,
1918 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001919 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001920 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001921 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001922 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001923
Douglas Gregordb121ba2009-12-14 16:27:04 +00001924 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001925 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001926 RequiresZeroInit, ConstructKind,
1927 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 }
1929
1930 /// \brief Build a new object-construction expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001934 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1935 SourceLocation LParenLoc,
1936 MultiExprArg Args,
1937 SourceLocation RParenLoc) {
1938 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 LParenLoc,
1940 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 RParenLoc);
1942 }
1943
1944 /// \brief Build a new object-construction expression.
1945 ///
1946 /// By default, performs semantic analysis to build the new expression.
1947 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001948 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1949 SourceLocation LParenLoc,
1950 MultiExprArg Args,
1951 SourceLocation RParenLoc) {
1952 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 LParenLoc,
1954 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001955 RParenLoc);
1956 }
Mike Stump11289f42009-09-09 15:08:12 +00001957
Douglas Gregora16548e2009-08-11 05:31:07 +00001958 /// \brief Build a new member reference expression.
1959 ///
1960 /// By default, performs semantic analysis to build the new expression.
1961 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001962 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001963 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 bool IsArrow,
1965 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001966 NestedNameSpecifier *Qualifier,
1967 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001968 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001969 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001970 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001971 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001972 SS.setRange(QualifierRange);
1973 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001974
John McCallb268a282010-08-23 23:25:46 +00001975 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001976 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001977 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001978 MemberNameInfo,
1979 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 }
1981
John McCall10eae182009-11-30 22:42:35 +00001982 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001986 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001987 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001988 SourceLocation OperatorLoc,
1989 bool IsArrow,
1990 NestedNameSpecifier *Qualifier,
1991 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001992 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001993 LookupResult &R,
1994 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001995 CXXScopeSpec SS;
1996 SS.setRange(QualifierRange);
1997 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001998
John McCallb268a282010-08-23 23:25:46 +00001999 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002000 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002001 SS, FirstQualifierInScope,
2002 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002003 }
Mike Stump11289f42009-09-09 15:08:12 +00002004
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002005 /// \brief Build a new noexcept expression.
2006 ///
2007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
2009 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2010 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2011 }
2012
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002013 /// \brief Build a new expression to compute the length of a parameter pack.
2014 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2015 SourceLocation PackLoc,
2016 SourceLocation RParenLoc,
2017 unsigned Length) {
2018 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2019 OperatorLoc, Pack, PackLoc,
2020 RParenLoc, Length);
2021 }
2022
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// \brief Build a new Objective-C @encode expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002028 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002030 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002032 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002033
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002034 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002035 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002036 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002037 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002038 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002039 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002040 MultiExprArg Args,
2041 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2043 ReceiverTypeInfo->getType(),
2044 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002045 Sel, Method, LBracLoc, SelectorLoc,
2046 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 }
2048
2049 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002050 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002051 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002052 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002053 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002054 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002055 MultiExprArg Args,
2056 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002057 return SemaRef.BuildInstanceMessage(Receiver,
2058 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002059 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002060 Sel, Method, LBracLoc, SelectorLoc,
2061 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002062 }
2063
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 /// \brief Build a new Objective-C ivar reference expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002069 SourceLocation IvarLoc,
2070 bool IsArrow, bool IsFreeIvar) {
2071 // FIXME: We lose track of the IsFreeIvar bit.
2072 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002073 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002074 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2075 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002076 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002077 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002078 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002079 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002080 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002081 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002082
Douglas Gregord51d90d2010-04-26 20:11:03 +00002083 if (Result.get())
2084 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002085
John McCallb268a282010-08-23 23:25:46 +00002086 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002087 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002088 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002089 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002090 /*TemplateArgs=*/0);
2091 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002092
2093 /// \brief Build a new Objective-C property reference expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002097 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002098 ObjCPropertyDecl *Property,
2099 SourceLocation PropertyLoc) {
2100 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002101 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002102 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2103 Sema::LookupMemberName);
2104 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002105 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002106 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002107 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002108 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002109 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002110
Douglas Gregor9faee212010-04-26 20:47:02 +00002111 if (Result.get())
2112 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113
John McCallb268a282010-08-23 23:25:46 +00002114 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002115 /*FIXME:*/PropertyLoc, IsArrow,
2116 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002117 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002118 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002119 /*TemplateArgs=*/0);
2120 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002121
John McCallb7bd14f2010-12-02 01:19:52 +00002122 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002123 ///
2124 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002125 /// Subclasses may override this routine to provide different behavior.
2126 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2127 ObjCMethodDecl *Getter,
2128 ObjCMethodDecl *Setter,
2129 SourceLocation PropertyLoc) {
2130 // Since these expressions can only be value-dependent, we do not
2131 // need to perform semantic analysis again.
2132 return Owned(
2133 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2134 VK_LValue, OK_ObjCProperty,
2135 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002136 }
2137
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 /// \brief Build a new Objective-C "isa" expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002143 bool IsArrow) {
2144 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002145 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002146 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2147 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002148 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002150 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002151 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002152 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002153
Douglas Gregord51d90d2010-04-26 20:11:03 +00002154 if (Result.get())
2155 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002156
John McCallb268a282010-08-23 23:25:46 +00002157 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002158 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002159 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002160 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002161 /*TemplateArgs=*/0);
2162 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002163
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// \brief Build a new shuffle vector expression.
2165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002168 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002169 MultiExprArg SubExprs,
2170 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002172 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2174 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2175 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2176 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 // Build a reference to the __builtin_shufflevector builtin
2179 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002180 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002182 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002184
2185 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 unsigned NumSubExprs = SubExprs.size();
2187 Expr **Subs = (Expr **)SubExprs.release();
2188 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2189 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002190 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002191 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002193 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002194
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002196 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002201 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 }
John McCall31f82722010-11-12 08:19:04 +00002203
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002204 /// \brief Build a new template argument pack expansion.
2205 ///
2206 /// By default, performs semantic analysis to build a new pack expansion
2207 /// for a template argument. Subclasses may override this routine to provide
2208 /// different behavior.
2209 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002210 SourceLocation EllipsisLoc,
2211 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002212 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002213 case TemplateArgument::Expression: {
2214 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002215 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2216 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002217 if (Result.isInvalid())
2218 return TemplateArgumentLoc();
2219
2220 return TemplateArgumentLoc(Result.get(), Result.get());
2221 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002222
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002223 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002224 return TemplateArgumentLoc(TemplateArgument(
2225 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002226 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002227 Pattern.getTemplateQualifierRange(),
2228 Pattern.getTemplateNameLoc(),
2229 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002230
2231 case TemplateArgument::Null:
2232 case TemplateArgument::Integral:
2233 case TemplateArgument::Declaration:
2234 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002235 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002236 llvm_unreachable("Pack expansion pattern has no parameter packs");
2237
2238 case TemplateArgument::Type:
2239 if (TypeSourceInfo *Expansion
2240 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002241 EllipsisLoc,
2242 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002243 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2244 Expansion);
2245 break;
2246 }
2247
2248 return TemplateArgumentLoc();
2249 }
2250
Douglas Gregor968f23a2011-01-03 19:31:53 +00002251 /// \brief Build a new expression pack expansion.
2252 ///
2253 /// By default, performs semantic analysis to build a new pack expansion
2254 /// for an expression. Subclasses may override this routine to provide
2255 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002256 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2257 llvm::Optional<unsigned> NumExpansions) {
2258 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002259 }
2260
John McCall31f82722010-11-12 08:19:04 +00002261private:
2262 QualType TransformTypeInObjectScope(QualType T,
2263 QualType ObjectType,
2264 NamedDecl *FirstQualifierInScope,
2265 NestedNameSpecifier *Prefix);
2266
2267 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2268 QualType ObjectType,
2269 NamedDecl *FirstQualifierInScope,
2270 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002271};
Douglas Gregora16548e2009-08-11 05:31:07 +00002272
Douglas Gregorebe10102009-08-20 07:17:43 +00002273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002274StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002275 if (!S)
2276 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002277
Douglas Gregorebe10102009-08-20 07:17:43 +00002278 switch (S->getStmtClass()) {
2279 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002280
Douglas Gregorebe10102009-08-20 07:17:43 +00002281 // Transform individual statement nodes
2282#define STMT(Node, Parent) \
2283 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002284#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002285#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002286#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002287
Douglas Gregorebe10102009-08-20 07:17:43 +00002288 // Transform expressions by calling TransformExpr.
2289#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002290#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002291#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002292#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002293 {
John McCalldadc5752010-08-24 06:29:42 +00002294 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002295 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002296 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002297
John McCallb268a282010-08-23 23:25:46 +00002298 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002299 }
Mike Stump11289f42009-09-09 15:08:12 +00002300 }
2301
John McCallc3007a22010-10-26 07:05:15 +00002302 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002303}
Mike Stump11289f42009-09-09 15:08:12 +00002304
2305
Douglas Gregore922c772009-08-04 22:27:00 +00002306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002307ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 if (!E)
2309 return SemaRef.Owned(E);
2310
2311 switch (E->getStmtClass()) {
2312 case Stmt::NoStmtClass: break;
2313#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002314#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002315#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002316 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002317#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002318 }
2319
John McCallc3007a22010-10-26 07:05:15 +00002320 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002321}
2322
2323template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002324bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2325 unsigned NumInputs,
2326 bool IsCall,
2327 llvm::SmallVectorImpl<Expr *> &Outputs,
2328 bool *ArgChanged) {
2329 for (unsigned I = 0; I != NumInputs; ++I) {
2330 // If requested, drop call arguments that need to be dropped.
2331 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2332 if (ArgChanged)
2333 *ArgChanged = true;
2334
2335 break;
2336 }
2337
Douglas Gregor968f23a2011-01-03 19:31:53 +00002338 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2339 Expr *Pattern = Expansion->getPattern();
2340
2341 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2342 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2343 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2344
2345 // Determine whether the set of unexpanded parameter packs can and should
2346 // be expanded.
2347 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002348 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002349 llvm::Optional<unsigned> OrigNumExpansions
2350 = Expansion->getNumExpansions();
2351 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002352 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2353 Pattern->getSourceRange(),
2354 Unexpanded.data(),
2355 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002356 Expand, RetainExpansion,
2357 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002358 return true;
2359
2360 if (!Expand) {
2361 // The transform has determined that we should perform a simple
2362 // transformation on the pack expansion, producing another pack
2363 // expansion.
2364 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2365 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2366 if (OutPattern.isInvalid())
2367 return true;
2368
2369 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002370 Expansion->getEllipsisLoc(),
2371 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002372 if (Out.isInvalid())
2373 return true;
2374
2375 if (ArgChanged)
2376 *ArgChanged = true;
2377 Outputs.push_back(Out.get());
2378 continue;
2379 }
2380
2381 // The transform has determined that we should perform an elementwise
2382 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002383 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002384 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2385 ExprResult Out = getDerived().TransformExpr(Pattern);
2386 if (Out.isInvalid())
2387 return true;
2388
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002389 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002390 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2391 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002392 if (Out.isInvalid())
2393 return true;
2394 }
2395
Douglas Gregor968f23a2011-01-03 19:31:53 +00002396 if (ArgChanged)
2397 *ArgChanged = true;
2398 Outputs.push_back(Out.get());
2399 }
2400
2401 continue;
2402 }
2403
Douglas Gregora3efea12011-01-03 19:04:46 +00002404 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2405 if (Result.isInvalid())
2406 return true;
2407
2408 if (Result.get() != Inputs[I] && ArgChanged)
2409 *ArgChanged = true;
2410
2411 Outputs.push_back(Result.get());
2412 }
2413
2414 return false;
2415}
2416
2417template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002418NestedNameSpecifier *
2419TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002420 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002421 QualType ObjectType,
2422 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002423 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002424
Douglas Gregorebe10102009-08-20 07:17:43 +00002425 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002426 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002427 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002428 ObjectType,
2429 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002430 if (!Prefix)
2431 return 0;
2432 }
Mike Stump11289f42009-09-09 15:08:12 +00002433
Douglas Gregor1135c352009-08-06 05:28:30 +00002434 switch (NNS->getKind()) {
2435 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002436 if (Prefix) {
2437 // The object type and qualifier-in-scope really apply to the
2438 // leftmost entity.
2439 ObjectType = QualType();
2440 FirstQualifierInScope = 0;
2441 }
2442
Mike Stump11289f42009-09-09 15:08:12 +00002443 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002444 "Identifier nested-name-specifier with no prefix or object type");
2445 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2446 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002447 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002448
2449 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002450 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002451 ObjectType,
2452 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002453
Douglas Gregor1135c352009-08-06 05:28:30 +00002454 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002455 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002456 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002457 getDerived().TransformDecl(Range.getBegin(),
2458 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002459 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002460 Prefix == NNS->getPrefix() &&
2461 NS == NNS->getAsNamespace())
2462 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregor1135c352009-08-06 05:28:30 +00002464 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2465 }
Mike Stump11289f42009-09-09 15:08:12 +00002466
Douglas Gregor1135c352009-08-06 05:28:30 +00002467 case NestedNameSpecifier::Global:
2468 // There is no meaningful transformation that one could perform on the
2469 // global scope.
2470 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002471
Douglas Gregor1135c352009-08-06 05:28:30 +00002472 case NestedNameSpecifier::TypeSpecWithTemplate:
2473 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002474 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002475 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2476 ObjectType,
2477 FirstQualifierInScope,
2478 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002479 if (T.isNull())
2480 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002481
Douglas Gregor1135c352009-08-06 05:28:30 +00002482 if (!getDerived().AlwaysRebuild() &&
2483 Prefix == NNS->getPrefix() &&
2484 T == QualType(NNS->getAsType(), 0))
2485 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002486
2487 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2488 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002489 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002490 }
2491 }
Mike Stump11289f42009-09-09 15:08:12 +00002492
Douglas Gregor1135c352009-08-06 05:28:30 +00002493 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002494 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002495}
2496
2497template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002498DeclarationNameInfo
2499TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002500::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002501 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002502 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002503 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002504
2505 switch (Name.getNameKind()) {
2506 case DeclarationName::Identifier:
2507 case DeclarationName::ObjCZeroArgSelector:
2508 case DeclarationName::ObjCOneArgSelector:
2509 case DeclarationName::ObjCMultiArgSelector:
2510 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002511 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002512 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002513 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002514
Douglas Gregorf816bd72009-09-03 22:13:48 +00002515 case DeclarationName::CXXConstructorName:
2516 case DeclarationName::CXXDestructorName:
2517 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002518 TypeSourceInfo *NewTInfo;
2519 CanQualType NewCanTy;
2520 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002521 NewTInfo = getDerived().TransformType(OldTInfo);
2522 if (!NewTInfo)
2523 return DeclarationNameInfo();
2524 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002525 }
2526 else {
2527 NewTInfo = 0;
2528 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002529 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002530 if (NewT.isNull())
2531 return DeclarationNameInfo();
2532 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2533 }
Mike Stump11289f42009-09-09 15:08:12 +00002534
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002535 DeclarationName NewName
2536 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2537 NewCanTy);
2538 DeclarationNameInfo NewNameInfo(NameInfo);
2539 NewNameInfo.setName(NewName);
2540 NewNameInfo.setNamedTypeInfo(NewTInfo);
2541 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002542 }
Mike Stump11289f42009-09-09 15:08:12 +00002543 }
2544
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002545 assert(0 && "Unknown name kind.");
2546 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002547}
2548
2549template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002550TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002551TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002552 QualType ObjectType,
2553 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002554 SourceLocation Loc = getDerived().getBaseLocation();
2555
Douglas Gregor71dc5092009-08-06 06:41:21 +00002556 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002557 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002558 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002559 /*FIXME*/ SourceRange(Loc),
2560 ObjectType,
2561 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002562 if (!NNS)
2563 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002564
Douglas Gregor71dc5092009-08-06 06:41:21 +00002565 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002566 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002567 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002568 if (!TransTemplate)
2569 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002570
Douglas Gregor71dc5092009-08-06 06:41:21 +00002571 if (!getDerived().AlwaysRebuild() &&
2572 NNS == QTN->getQualifier() &&
2573 TransTemplate == Template)
2574 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002575
Douglas Gregor71dc5092009-08-06 06:41:21 +00002576 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2577 TransTemplate);
2578 }
Mike Stump11289f42009-09-09 15:08:12 +00002579
John McCalle66edc12009-11-24 19:00:30 +00002580 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002581 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002582 }
Mike Stump11289f42009-09-09 15:08:12 +00002583
Douglas Gregor71dc5092009-08-06 06:41:21 +00002584 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002585 NestedNameSpecifier *NNS = DTN->getQualifier();
2586 if (NNS) {
2587 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2588 /*FIXME:*/SourceRange(Loc),
2589 ObjectType,
2590 FirstQualifierInScope);
2591 if (!NNS) return TemplateName();
2592
2593 // These apply to the scope specifier, not the template.
2594 ObjectType = QualType();
2595 FirstQualifierInScope = 0;
2596 }
Mike Stump11289f42009-09-09 15:08:12 +00002597
Douglas Gregor71dc5092009-08-06 06:41:21 +00002598 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002599 NNS == DTN->getQualifier() &&
2600 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002601 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002602
Douglas Gregora5614c52010-09-08 23:56:00 +00002603 if (DTN->isIdentifier()) {
2604 // FIXME: Bad range
2605 SourceRange QualifierRange(getDerived().getBaseLocation());
2606 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2607 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002608 ObjectType,
2609 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002610 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002611
2612 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002613 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002614 }
Mike Stump11289f42009-09-09 15:08:12 +00002615
Douglas Gregor71dc5092009-08-06 06:41:21 +00002616 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002617 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002618 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002619 if (!TransTemplate)
2620 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002621
Douglas Gregor71dc5092009-08-06 06:41:21 +00002622 if (!getDerived().AlwaysRebuild() &&
2623 TransTemplate == Template)
2624 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002625
Douglas Gregor71dc5092009-08-06 06:41:21 +00002626 return TemplateName(TransTemplate);
2627 }
Mike Stump11289f42009-09-09 15:08:12 +00002628
Douglas Gregor5590be02011-01-15 06:45:20 +00002629 if (SubstTemplateTemplateParmPackStorage *SubstPack
2630 = Name.getAsSubstTemplateTemplateParmPack()) {
2631 TemplateTemplateParmDecl *TransParam
2632 = cast_or_null<TemplateTemplateParmDecl>(
2633 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2634 if (!TransParam)
2635 return TemplateName();
2636
2637 if (!getDerived().AlwaysRebuild() &&
2638 TransParam == SubstPack->getParameterPack())
2639 return Name;
2640
2641 return getDerived().RebuildTemplateName(TransParam,
2642 SubstPack->getArgumentPack());
2643 }
2644
John McCalle66edc12009-11-24 19:00:30 +00002645 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002646 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002647 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002648}
2649
2650template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002651void TreeTransform<Derived>::InventTemplateArgumentLoc(
2652 const TemplateArgument &Arg,
2653 TemplateArgumentLoc &Output) {
2654 SourceLocation Loc = getDerived().getBaseLocation();
2655 switch (Arg.getKind()) {
2656 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002657 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002658 break;
2659
2660 case TemplateArgument::Type:
2661 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002662 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002663
John McCall0ad16662009-10-29 08:12:44 +00002664 break;
2665
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002666 case TemplateArgument::Template:
2667 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2668 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002669
2670 case TemplateArgument::TemplateExpansion:
2671 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2672 break;
2673
John McCall0ad16662009-10-29 08:12:44 +00002674 case TemplateArgument::Expression:
2675 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2676 break;
2677
2678 case TemplateArgument::Declaration:
2679 case TemplateArgument::Integral:
2680 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002681 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002682 break;
2683 }
2684}
2685
2686template<typename Derived>
2687bool TreeTransform<Derived>::TransformTemplateArgument(
2688 const TemplateArgumentLoc &Input,
2689 TemplateArgumentLoc &Output) {
2690 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002691 switch (Arg.getKind()) {
2692 case TemplateArgument::Null:
2693 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002694 Output = Input;
2695 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002696
Douglas Gregore922c772009-08-04 22:27:00 +00002697 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002698 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002699 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002700 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002701
2702 DI = getDerived().TransformType(DI);
2703 if (!DI) return true;
2704
2705 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2706 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002707 }
Mike Stump11289f42009-09-09 15:08:12 +00002708
Douglas Gregore922c772009-08-04 22:27:00 +00002709 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002710 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002711 DeclarationName Name;
2712 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2713 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002714 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002715 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002716 if (!D) return true;
2717
John McCall0d07eb32009-10-29 18:45:58 +00002718 Expr *SourceExpr = Input.getSourceDeclExpression();
2719 if (SourceExpr) {
2720 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002721 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002722 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002723 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002724 }
2725
2726 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002727 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002728 }
Mike Stump11289f42009-09-09 15:08:12 +00002729
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002730 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002731 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002732 TemplateName Template
2733 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2734 if (Template.isNull())
2735 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002736
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002737 Output = TemplateArgumentLoc(TemplateArgument(Template),
2738 Input.getTemplateQualifierRange(),
2739 Input.getTemplateNameLoc());
2740 return false;
2741 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002742
2743 case TemplateArgument::TemplateExpansion:
2744 llvm_unreachable("Caller should expand pack expansions");
2745
Douglas Gregore922c772009-08-04 22:27:00 +00002746 case TemplateArgument::Expression: {
2747 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002748 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002749 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002750
John McCall0ad16662009-10-29 08:12:44 +00002751 Expr *InputExpr = Input.getSourceExpression();
2752 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2753
John McCalldadc5752010-08-24 06:29:42 +00002754 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002755 = getDerived().TransformExpr(InputExpr);
2756 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002757 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002758 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregore922c772009-08-04 22:27:00 +00002761 case TemplateArgument::Pack: {
2762 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2763 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002764 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002765 AEnd = Arg.pack_end();
2766 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002767
John McCall0ad16662009-10-29 08:12:44 +00002768 // FIXME: preserve source information here when we start
2769 // caring about parameter packs.
2770
John McCall0d07eb32009-10-29 18:45:58 +00002771 TemplateArgumentLoc InputArg;
2772 TemplateArgumentLoc OutputArg;
2773 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2774 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002775 return true;
2776
John McCall0d07eb32009-10-29 18:45:58 +00002777 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002778 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002779
2780 TemplateArgument *TransformedArgsPtr
2781 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2782 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2783 TransformedArgsPtr);
2784 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2785 TransformedArgs.size()),
2786 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002787 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002788 }
2789 }
Mike Stump11289f42009-09-09 15:08:12 +00002790
Douglas Gregore922c772009-08-04 22:27:00 +00002791 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002792 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002793}
2794
Douglas Gregorfe921a72010-12-20 23:36:19 +00002795/// \brief Iterator adaptor that invents template argument location information
2796/// for each of the template arguments in its underlying iterator.
2797template<typename Derived, typename InputIterator>
2798class TemplateArgumentLocInventIterator {
2799 TreeTransform<Derived> &Self;
2800 InputIterator Iter;
2801
2802public:
2803 typedef TemplateArgumentLoc value_type;
2804 typedef TemplateArgumentLoc reference;
2805 typedef typename std::iterator_traits<InputIterator>::difference_type
2806 difference_type;
2807 typedef std::input_iterator_tag iterator_category;
2808
2809 class pointer {
2810 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002811
Douglas Gregorfe921a72010-12-20 23:36:19 +00002812 public:
2813 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2814
2815 const TemplateArgumentLoc *operator->() const { return &Arg; }
2816 };
2817
2818 TemplateArgumentLocInventIterator() { }
2819
2820 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2821 InputIterator Iter)
2822 : Self(Self), Iter(Iter) { }
2823
2824 TemplateArgumentLocInventIterator &operator++() {
2825 ++Iter;
2826 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002827 }
2828
Douglas Gregorfe921a72010-12-20 23:36:19 +00002829 TemplateArgumentLocInventIterator operator++(int) {
2830 TemplateArgumentLocInventIterator Old(*this);
2831 ++(*this);
2832 return Old;
2833 }
2834
2835 reference operator*() const {
2836 TemplateArgumentLoc Result;
2837 Self.InventTemplateArgumentLoc(*Iter, Result);
2838 return Result;
2839 }
2840
2841 pointer operator->() const { return pointer(**this); }
2842
2843 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2844 const TemplateArgumentLocInventIterator &Y) {
2845 return X.Iter == Y.Iter;
2846 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002847
Douglas Gregorfe921a72010-12-20 23:36:19 +00002848 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2849 const TemplateArgumentLocInventIterator &Y) {
2850 return X.Iter != Y.Iter;
2851 }
2852};
2853
Douglas Gregor42cafa82010-12-20 17:42:22 +00002854template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002855template<typename InputIterator>
2856bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2857 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002858 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002859 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002860 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002861 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002862
2863 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2864 // Unpack argument packs, which we translate them into separate
2865 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002866 // FIXME: We could do much better if we could guarantee that the
2867 // TemplateArgumentLocInfo for the pack expansion would be usable for
2868 // all of the template arguments in the argument pack.
2869 typedef TemplateArgumentLocInventIterator<Derived,
2870 TemplateArgument::pack_iterator>
2871 PackLocIterator;
2872 if (TransformTemplateArguments(PackLocIterator(*this,
2873 In.getArgument().pack_begin()),
2874 PackLocIterator(*this,
2875 In.getArgument().pack_end()),
2876 Outputs))
2877 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002878
2879 continue;
2880 }
2881
2882 if (In.getArgument().isPackExpansion()) {
2883 // We have a pack expansion, for which we will be substituting into
2884 // the pattern.
2885 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002886 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002887 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002888 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2889 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002890
2891 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2892 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2893 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2894
2895 // Determine whether the set of unexpanded parameter packs can and should
2896 // be expanded.
2897 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002898 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002899 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002900 if (getDerived().TryExpandParameterPacks(Ellipsis,
2901 Pattern.getSourceRange(),
2902 Unexpanded.data(),
2903 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002904 Expand,
2905 RetainExpansion,
2906 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002907 return true;
2908
2909 if (!Expand) {
2910 // The transform has determined that we should perform a simple
2911 // transformation on the pack expansion, producing another pack
2912 // expansion.
2913 TemplateArgumentLoc OutPattern;
2914 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2915 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2916 return true;
2917
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002918 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2919 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002920 if (Out.getArgument().isNull())
2921 return true;
2922
2923 Outputs.addArgument(Out);
2924 continue;
2925 }
2926
2927 // The transform has determined that we should perform an elementwise
2928 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002929 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002930 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2931
2932 if (getDerived().TransformTemplateArgument(Pattern, Out))
2933 return true;
2934
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002935 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002936 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2937 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002938 if (Out.getArgument().isNull())
2939 return true;
2940 }
2941
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002942 Outputs.addArgument(Out);
2943 }
2944
Douglas Gregor48d24112011-01-10 20:53:55 +00002945 // If we're supposed to retain a pack expansion, do so by temporarily
2946 // forgetting the partially-substituted parameter pack.
2947 if (RetainExpansion) {
2948 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2949
2950 if (getDerived().TransformTemplateArgument(Pattern, Out))
2951 return true;
2952
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002953 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2954 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002955 if (Out.getArgument().isNull())
2956 return true;
2957
2958 Outputs.addArgument(Out);
2959 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002960
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002961 continue;
2962 }
2963
2964 // The simple case:
2965 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002966 return true;
2967
2968 Outputs.addArgument(Out);
2969 }
2970
2971 return false;
2972
2973}
2974
Douglas Gregord6ff3322009-08-04 16:50:30 +00002975//===----------------------------------------------------------------------===//
2976// Type transformation
2977//===----------------------------------------------------------------------===//
2978
2979template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002980QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002981 if (getDerived().AlreadyTransformed(T))
2982 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002983
John McCall550e0c22009-10-21 00:40:46 +00002984 // Temporary workaround. All of these transformations should
2985 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002986 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2987 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002988
John McCall31f82722010-11-12 08:19:04 +00002989 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002990
John McCall550e0c22009-10-21 00:40:46 +00002991 if (!NewDI)
2992 return QualType();
2993
2994 return NewDI->getType();
2995}
2996
2997template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002998TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002999 if (getDerived().AlreadyTransformed(DI->getType()))
3000 return DI;
3001
3002 TypeLocBuilder TLB;
3003
3004 TypeLoc TL = DI->getTypeLoc();
3005 TLB.reserve(TL.getFullDataSize());
3006
John McCall31f82722010-11-12 08:19:04 +00003007 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003008 if (Result.isNull())
3009 return 0;
3010
John McCallbcd03502009-12-07 02:54:59 +00003011 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003012}
3013
3014template<typename Derived>
3015QualType
John McCall31f82722010-11-12 08:19:04 +00003016TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003017 switch (T.getTypeLocClass()) {
3018#define ABSTRACT_TYPELOC(CLASS, PARENT)
3019#define TYPELOC(CLASS, PARENT) \
3020 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003021 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003022#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003023 }
Mike Stump11289f42009-09-09 15:08:12 +00003024
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003025 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003026 return QualType();
3027}
3028
3029/// FIXME: By default, this routine adds type qualifiers only to types
3030/// that can have qualifiers, and silently suppresses those qualifiers
3031/// that are not permitted (e.g., qualifiers on reference or function
3032/// types). This is the right thing for template instantiation, but
3033/// probably not for other clients.
3034template<typename Derived>
3035QualType
3036TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003037 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003038 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003039
John McCall31f82722010-11-12 08:19:04 +00003040 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003041 if (Result.isNull())
3042 return QualType();
3043
3044 // Silently suppress qualifiers if the result type can't be qualified.
3045 // FIXME: this is the right thing for template instantiation, but
3046 // probably not for other clients.
3047 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003048 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003049
John McCallcb0f89a2010-06-05 06:41:15 +00003050 if (!Quals.empty()) {
3051 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3052 TLB.push<QualifiedTypeLoc>(Result);
3053 // No location information to preserve.
3054 }
John McCall550e0c22009-10-21 00:40:46 +00003055
3056 return Result;
3057}
3058
John McCall31f82722010-11-12 08:19:04 +00003059/// \brief Transforms a type that was written in a scope specifier,
3060/// given an object type, the results of unqualified lookup, and
3061/// an already-instantiated prefix.
3062///
3063/// The object type is provided iff the scope specifier qualifies the
3064/// member of a dependent member-access expression. The prefix is
3065/// provided iff the the scope specifier in which this appears has a
3066/// prefix.
3067///
3068/// This is private to TreeTransform.
3069template<typename Derived>
3070QualType
3071TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3072 QualType ObjectType,
3073 NamedDecl *UnqualLookup,
3074 NestedNameSpecifier *Prefix) {
3075 if (getDerived().AlreadyTransformed(T))
3076 return T;
3077
3078 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003079 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003080
3081 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3082 UnqualLookup, Prefix);
3083 if (!TSI) return QualType();
3084 return TSI->getType();
3085}
3086
3087template<typename Derived>
3088TypeSourceInfo *
3089TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3090 QualType ObjectType,
3091 NamedDecl *UnqualLookup,
3092 NestedNameSpecifier *Prefix) {
3093 // TODO: in some cases, we might be some verification to do here.
3094 if (ObjectType.isNull())
3095 return getDerived().TransformType(TSI);
3096
3097 QualType T = TSI->getType();
3098 if (getDerived().AlreadyTransformed(T))
3099 return TSI;
3100
3101 TypeLocBuilder TLB;
3102 QualType Result;
3103
3104 if (isa<TemplateSpecializationType>(T)) {
3105 TemplateSpecializationTypeLoc TL
3106 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3107
3108 TemplateName Template =
3109 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3110 ObjectType, UnqualLookup);
3111 if (Template.isNull()) return 0;
3112
3113 Result = getDerived()
3114 .TransformTemplateSpecializationType(TLB, TL, Template);
3115 } else if (isa<DependentTemplateSpecializationType>(T)) {
3116 DependentTemplateSpecializationTypeLoc TL
3117 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3118
3119 Result = getDerived()
3120 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3121 } else {
3122 // Nothing special needs to be done for these.
3123 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3124 }
3125
3126 if (Result.isNull()) return 0;
3127 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3128}
3129
John McCall550e0c22009-10-21 00:40:46 +00003130template <class TyLoc> static inline
3131QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3132 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3133 NewT.setNameLoc(T.getNameLoc());
3134 return T.getType();
3135}
3136
John McCall550e0c22009-10-21 00:40:46 +00003137template<typename Derived>
3138QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003139 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003140 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3141 NewT.setBuiltinLoc(T.getBuiltinLoc());
3142 if (T.needsExtraLocalData())
3143 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3144 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145}
Mike Stump11289f42009-09-09 15:08:12 +00003146
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003148QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003149 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003150 // FIXME: recurse?
3151 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003152}
Mike Stump11289f42009-09-09 15:08:12 +00003153
Douglas Gregord6ff3322009-08-04 16:50:30 +00003154template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003155QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003156 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003157 QualType PointeeType
3158 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003159 if (PointeeType.isNull())
3160 return QualType();
3161
3162 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003163 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003164 // A dependent pointer type 'T *' has is being transformed such
3165 // that an Objective-C class type is being replaced for 'T'. The
3166 // resulting pointer type is an ObjCObjectPointerType, not a
3167 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003168 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003169
John McCall8b07ec22010-05-15 11:32:37 +00003170 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3171 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003172 return Result;
3173 }
John McCall31f82722010-11-12 08:19:04 +00003174
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003175 if (getDerived().AlwaysRebuild() ||
3176 PointeeType != TL.getPointeeLoc().getType()) {
3177 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3178 if (Result.isNull())
3179 return QualType();
3180 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003181
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003182 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3183 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003184 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003185}
Mike Stump11289f42009-09-09 15:08:12 +00003186
3187template<typename Derived>
3188QualType
John McCall550e0c22009-10-21 00:40:46 +00003189TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003190 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003191 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003192 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3193 if (PointeeType.isNull())
3194 return QualType();
3195
3196 QualType Result = TL.getType();
3197 if (getDerived().AlwaysRebuild() ||
3198 PointeeType != TL.getPointeeLoc().getType()) {
3199 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003200 TL.getSigilLoc());
3201 if (Result.isNull())
3202 return QualType();
3203 }
3204
Douglas Gregor049211a2010-04-22 16:50:51 +00003205 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003206 NewT.setSigilLoc(TL.getSigilLoc());
3207 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003208}
3209
John McCall70dd5f62009-10-30 00:06:24 +00003210/// Transforms a reference type. Note that somewhat paradoxically we
3211/// don't care whether the type itself is an l-value type or an r-value
3212/// type; we only care if the type was *written* as an l-value type
3213/// or an r-value type.
3214template<typename Derived>
3215QualType
3216TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003217 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003218 const ReferenceType *T = TL.getTypePtr();
3219
3220 // Note that this works with the pointee-as-written.
3221 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3222 if (PointeeType.isNull())
3223 return QualType();
3224
3225 QualType Result = TL.getType();
3226 if (getDerived().AlwaysRebuild() ||
3227 PointeeType != T->getPointeeTypeAsWritten()) {
3228 Result = getDerived().RebuildReferenceType(PointeeType,
3229 T->isSpelledAsLValue(),
3230 TL.getSigilLoc());
3231 if (Result.isNull())
3232 return QualType();
3233 }
3234
3235 // r-value references can be rebuilt as l-value references.
3236 ReferenceTypeLoc NewTL;
3237 if (isa<LValueReferenceType>(Result))
3238 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3239 else
3240 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3241 NewTL.setSigilLoc(TL.getSigilLoc());
3242
3243 return Result;
3244}
3245
Mike Stump11289f42009-09-09 15:08:12 +00003246template<typename Derived>
3247QualType
John McCall550e0c22009-10-21 00:40:46 +00003248TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003249 LValueReferenceTypeLoc TL) {
3250 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251}
3252
Mike Stump11289f42009-09-09 15:08:12 +00003253template<typename Derived>
3254QualType
John McCall550e0c22009-10-21 00:40:46 +00003255TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003256 RValueReferenceTypeLoc TL) {
3257 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258}
Mike Stump11289f42009-09-09 15:08:12 +00003259
Douglas Gregord6ff3322009-08-04 16:50:30 +00003260template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003261QualType
John McCall550e0c22009-10-21 00:40:46 +00003262TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003263 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003264 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003265
3266 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003267 if (PointeeType.isNull())
3268 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003269
John McCall550e0c22009-10-21 00:40:46 +00003270 // TODO: preserve source information for this.
3271 QualType ClassType
3272 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003273 if (ClassType.isNull())
3274 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003275
John McCall550e0c22009-10-21 00:40:46 +00003276 QualType Result = TL.getType();
3277 if (getDerived().AlwaysRebuild() ||
3278 PointeeType != T->getPointeeType() ||
3279 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003280 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3281 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003282 if (Result.isNull())
3283 return QualType();
3284 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285
John McCall550e0c22009-10-21 00:40:46 +00003286 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3287 NewTL.setSigilLoc(TL.getSigilLoc());
3288
3289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290}
3291
Mike Stump11289f42009-09-09 15:08:12 +00003292template<typename Derived>
3293QualType
John McCall550e0c22009-10-21 00:40:46 +00003294TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003295 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003296 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003297 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298 if (ElementType.isNull())
3299 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003300
John McCall550e0c22009-10-21 00:40:46 +00003301 QualType Result = TL.getType();
3302 if (getDerived().AlwaysRebuild() ||
3303 ElementType != T->getElementType()) {
3304 Result = getDerived().RebuildConstantArrayType(ElementType,
3305 T->getSizeModifier(),
3306 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003307 T->getIndexTypeCVRQualifiers(),
3308 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003309 if (Result.isNull())
3310 return QualType();
3311 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003312
John McCall550e0c22009-10-21 00:40:46 +00003313 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3314 NewTL.setLBracketLoc(TL.getLBracketLoc());
3315 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003316
John McCall550e0c22009-10-21 00:40:46 +00003317 Expr *Size = TL.getSizeExpr();
3318 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003319 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003320 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3321 }
3322 NewTL.setSizeExpr(Size);
3323
3324 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325}
Mike Stump11289f42009-09-09 15:08:12 +00003326
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003329 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003330 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003331 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003332 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003333 if (ElementType.isNull())
3334 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003335
John McCall550e0c22009-10-21 00:40:46 +00003336 QualType Result = TL.getType();
3337 if (getDerived().AlwaysRebuild() ||
3338 ElementType != T->getElementType()) {
3339 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003340 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003341 T->getIndexTypeCVRQualifiers(),
3342 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003343 if (Result.isNull())
3344 return QualType();
3345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003346
John McCall550e0c22009-10-21 00:40:46 +00003347 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3348 NewTL.setLBracketLoc(TL.getLBracketLoc());
3349 NewTL.setRBracketLoc(TL.getRBracketLoc());
3350 NewTL.setSizeExpr(0);
3351
3352 return Result;
3353}
3354
3355template<typename Derived>
3356QualType
3357TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003358 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003359 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003360 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3361 if (ElementType.isNull())
3362 return QualType();
3363
3364 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003365 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003366
John McCalldadc5752010-08-24 06:29:42 +00003367 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003368 = getDerived().TransformExpr(T->getSizeExpr());
3369 if (SizeResult.isInvalid())
3370 return QualType();
3371
John McCallb268a282010-08-23 23:25:46 +00003372 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003373
3374 QualType Result = TL.getType();
3375 if (getDerived().AlwaysRebuild() ||
3376 ElementType != T->getElementType() ||
3377 Size != T->getSizeExpr()) {
3378 Result = getDerived().RebuildVariableArrayType(ElementType,
3379 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003380 Size,
John McCall550e0c22009-10-21 00:40:46 +00003381 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003382 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003383 if (Result.isNull())
3384 return QualType();
3385 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003386
John McCall550e0c22009-10-21 00:40:46 +00003387 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3388 NewTL.setLBracketLoc(TL.getLBracketLoc());
3389 NewTL.setRBracketLoc(TL.getRBracketLoc());
3390 NewTL.setSizeExpr(Size);
3391
3392 return Result;
3393}
3394
3395template<typename Derived>
3396QualType
3397TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003398 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003399 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003400 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3401 if (ElementType.isNull())
3402 return QualType();
3403
3404 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003405 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003406
John McCall33ddac02011-01-19 10:06:00 +00003407 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3408 Expr *origSize = TL.getSizeExpr();
3409 if (!origSize) origSize = T->getSizeExpr();
3410
3411 ExprResult sizeResult
3412 = getDerived().TransformExpr(origSize);
3413 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003414 return QualType();
3415
John McCall33ddac02011-01-19 10:06:00 +00003416 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003417
3418 QualType Result = TL.getType();
3419 if (getDerived().AlwaysRebuild() ||
3420 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003421 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003422 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3423 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003424 size,
John McCall550e0c22009-10-21 00:40:46 +00003425 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003426 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003427 if (Result.isNull())
3428 return QualType();
3429 }
John McCall550e0c22009-10-21 00:40:46 +00003430
3431 // We might have any sort of array type now, but fortunately they
3432 // all have the same location layout.
3433 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3434 NewTL.setLBracketLoc(TL.getLBracketLoc());
3435 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003436 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003437
3438 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003439}
Mike Stump11289f42009-09-09 15:08:12 +00003440
3441template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003442QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003443 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003444 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003445 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003446
3447 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003448 QualType ElementType = getDerived().TransformType(T->getElementType());
3449 if (ElementType.isNull())
3450 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003451
Douglas Gregore922c772009-08-04 22:27:00 +00003452 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003453 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003454
John McCalldadc5752010-08-24 06:29:42 +00003455 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003456 if (Size.isInvalid())
3457 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003458
John McCall550e0c22009-10-21 00:40:46 +00003459 QualType Result = TL.getType();
3460 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003461 ElementType != T->getElementType() ||
3462 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003463 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003464 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003465 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003466 if (Result.isNull())
3467 return QualType();
3468 }
John McCall550e0c22009-10-21 00:40:46 +00003469
3470 // Result might be dependent or not.
3471 if (isa<DependentSizedExtVectorType>(Result)) {
3472 DependentSizedExtVectorTypeLoc NewTL
3473 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3474 NewTL.setNameLoc(TL.getNameLoc());
3475 } else {
3476 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3477 NewTL.setNameLoc(TL.getNameLoc());
3478 }
3479
3480 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003481}
Mike Stump11289f42009-09-09 15:08:12 +00003482
3483template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003484QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003485 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003486 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003487 QualType ElementType = getDerived().TransformType(T->getElementType());
3488 if (ElementType.isNull())
3489 return QualType();
3490
John McCall550e0c22009-10-21 00:40:46 +00003491 QualType Result = TL.getType();
3492 if (getDerived().AlwaysRebuild() ||
3493 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003494 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003495 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003496 if (Result.isNull())
3497 return QualType();
3498 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003499
John McCall550e0c22009-10-21 00:40:46 +00003500 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3501 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003502
John McCall550e0c22009-10-21 00:40:46 +00003503 return Result;
3504}
3505
3506template<typename Derived>
3507QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003508 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003509 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003510 QualType ElementType = getDerived().TransformType(T->getElementType());
3511 if (ElementType.isNull())
3512 return QualType();
3513
3514 QualType Result = TL.getType();
3515 if (getDerived().AlwaysRebuild() ||
3516 ElementType != T->getElementType()) {
3517 Result = getDerived().RebuildExtVectorType(ElementType,
3518 T->getNumElements(),
3519 /*FIXME*/ SourceLocation());
3520 if (Result.isNull())
3521 return QualType();
3522 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003523
John McCall550e0c22009-10-21 00:40:46 +00003524 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3525 NewTL.setNameLoc(TL.getNameLoc());
3526
3527 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003528}
Mike Stump11289f42009-09-09 15:08:12 +00003529
3530template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003531ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003532TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3533 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003534 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003535 TypeSourceInfo *NewDI = 0;
3536
3537 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3538 // If we're substituting into a pack expansion type and we know the
3539 TypeLoc OldTL = OldDI->getTypeLoc();
3540 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3541
3542 TypeLocBuilder TLB;
3543 TypeLoc NewTL = OldDI->getTypeLoc();
3544 TLB.reserve(NewTL.getFullDataSize());
3545
3546 QualType Result = getDerived().TransformType(TLB,
3547 OldExpansionTL.getPatternLoc());
3548 if (Result.isNull())
3549 return 0;
3550
3551 Result = RebuildPackExpansionType(Result,
3552 OldExpansionTL.getPatternLoc().getSourceRange(),
3553 OldExpansionTL.getEllipsisLoc(),
3554 NumExpansions);
3555 if (Result.isNull())
3556 return 0;
3557
3558 PackExpansionTypeLoc NewExpansionTL
3559 = TLB.push<PackExpansionTypeLoc>(Result);
3560 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3561 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3562 } else
3563 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003564 if (!NewDI)
3565 return 0;
3566
3567 if (NewDI == OldDI)
3568 return OldParm;
3569 else
3570 return ParmVarDecl::Create(SemaRef.Context,
3571 OldParm->getDeclContext(),
3572 OldParm->getLocation(),
3573 OldParm->getIdentifier(),
3574 NewDI->getType(),
3575 NewDI,
3576 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003577 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003578 /* DefArg */ NULL);
3579}
3580
3581template<typename Derived>
3582bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003583 TransformFunctionTypeParams(SourceLocation Loc,
3584 ParmVarDecl **Params, unsigned NumParams,
3585 const QualType *ParamTypes,
3586 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3587 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3588 for (unsigned i = 0; i != NumParams; ++i) {
3589 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003590 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003591 if (OldParm->isParameterPack()) {
3592 // We have a function parameter pack that may need to be expanded.
3593 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003594
Douglas Gregor5499af42011-01-05 23:12:31 +00003595 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003596 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3597 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3598 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3599 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003600
3601 // Determine whether we should expand the parameter packs.
3602 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003603 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003604 llvm::Optional<unsigned> OrigNumExpansions
3605 = ExpansionTL.getTypePtr()->getNumExpansions();
3606 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003607 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3608 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003609 Unexpanded.data(),
3610 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003611 ShouldExpand,
3612 RetainExpansion,
3613 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003614 return true;
3615 }
3616
3617 if (ShouldExpand) {
3618 // Expand the function parameter pack into multiple, separate
3619 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003620 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003621 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003622 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3623 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003624 = getDerived().TransformFunctionTypeParam(OldParm,
3625 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003626 if (!NewParm)
3627 return true;
3628
Douglas Gregordd472162011-01-07 00:20:55 +00003629 OutParamTypes.push_back(NewParm->getType());
3630 if (PVars)
3631 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003632 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003633
3634 // If we're supposed to retain a pack expansion, do so by temporarily
3635 // forgetting the partially-substituted parameter pack.
3636 if (RetainExpansion) {
3637 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3638 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003639 = getDerived().TransformFunctionTypeParam(OldParm,
3640 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003641 if (!NewParm)
3642 return true;
3643
3644 OutParamTypes.push_back(NewParm->getType());
3645 if (PVars)
3646 PVars->push_back(NewParm);
3647 }
3648
Douglas Gregor5499af42011-01-05 23:12:31 +00003649 // We're done with the pack expansion.
3650 continue;
3651 }
3652
3653 // We'll substitute the parameter now without expanding the pack
3654 // expansion.
3655 }
3656
3657 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003658 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3659 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003660 if (!NewParm)
3661 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003662
Douglas Gregordd472162011-01-07 00:20:55 +00003663 OutParamTypes.push_back(NewParm->getType());
3664 if (PVars)
3665 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003666 continue;
3667 }
John McCall58f10c32010-03-11 09:03:00 +00003668
3669 // Deal with the possibility that we don't have a parameter
3670 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003671 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003672 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003673 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003674 if (const PackExpansionType *Expansion
3675 = dyn_cast<PackExpansionType>(OldType)) {
3676 // We have a function parameter pack that may need to be expanded.
3677 QualType Pattern = Expansion->getPattern();
3678 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3679 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3680
3681 // Determine whether we should expand the parameter packs.
3682 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003683 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003684 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003685 Unexpanded.data(),
3686 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003687 ShouldExpand,
3688 RetainExpansion,
3689 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003690 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003691 }
3692
3693 if (ShouldExpand) {
3694 // Expand the function parameter pack into multiple, separate
3695 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003696 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003697 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3698 QualType NewType = getDerived().TransformType(Pattern);
3699 if (NewType.isNull())
3700 return true;
John McCall58f10c32010-03-11 09:03:00 +00003701
Douglas Gregordd472162011-01-07 00:20:55 +00003702 OutParamTypes.push_back(NewType);
3703 if (PVars)
3704 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003705 }
3706
3707 // We're done with the pack expansion.
3708 continue;
3709 }
3710
Douglas Gregor48d24112011-01-10 20:53:55 +00003711 // If we're supposed to retain a pack expansion, do so by temporarily
3712 // forgetting the partially-substituted parameter pack.
3713 if (RetainExpansion) {
3714 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3715 QualType NewType = getDerived().TransformType(Pattern);
3716 if (NewType.isNull())
3717 return true;
3718
3719 OutParamTypes.push_back(NewType);
3720 if (PVars)
3721 PVars->push_back(0);
3722 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003723
Douglas Gregor5499af42011-01-05 23:12:31 +00003724 // We'll substitute the parameter now without expanding the pack
3725 // expansion.
3726 OldType = Expansion->getPattern();
3727 IsPackExpansion = true;
3728 }
3729
3730 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3731 QualType NewType = getDerived().TransformType(OldType);
3732 if (NewType.isNull())
3733 return true;
3734
3735 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003736 NewType = getSema().Context.getPackExpansionType(NewType,
3737 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003738
Douglas Gregordd472162011-01-07 00:20:55 +00003739 OutParamTypes.push_back(NewType);
3740 if (PVars)
3741 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003742 }
3743
3744 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003745 }
John McCall58f10c32010-03-11 09:03:00 +00003746
3747template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003748QualType
John McCall550e0c22009-10-21 00:40:46 +00003749TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003750 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003751 // Transform the parameters and return type.
3752 //
3753 // We instantiate in source order, with the return type first followed by
3754 // the parameters, because users tend to expect this (even if they shouldn't
3755 // rely on it!).
3756 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003757 // When the function has a trailing return type, we instantiate the
3758 // parameters before the return type, since the return type can then refer
3759 // to the parameters themselves (via decltype, sizeof, etc.).
3760 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003761 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003762 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003763 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003764
Douglas Gregor7fb25412010-10-01 18:44:50 +00003765 QualType ResultType;
3766
3767 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003768 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3769 TL.getParmArray(),
3770 TL.getNumArgs(),
3771 TL.getTypePtr()->arg_type_begin(),
3772 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003773 return QualType();
3774
3775 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3776 if (ResultType.isNull())
3777 return QualType();
3778 }
3779 else {
3780 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3781 if (ResultType.isNull())
3782 return QualType();
3783
Douglas Gregordd472162011-01-07 00:20:55 +00003784 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3785 TL.getParmArray(),
3786 TL.getNumArgs(),
3787 TL.getTypePtr()->arg_type_begin(),
3788 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003789 return QualType();
3790 }
3791
John McCall550e0c22009-10-21 00:40:46 +00003792 QualType Result = TL.getType();
3793 if (getDerived().AlwaysRebuild() ||
3794 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003795 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003796 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3797 Result = getDerived().RebuildFunctionProtoType(ResultType,
3798 ParamTypes.data(),
3799 ParamTypes.size(),
3800 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003801 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003802 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003803 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003804 if (Result.isNull())
3805 return QualType();
3806 }
Mike Stump11289f42009-09-09 15:08:12 +00003807
John McCall550e0c22009-10-21 00:40:46 +00003808 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3809 NewTL.setLParenLoc(TL.getLParenLoc());
3810 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003811 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003812 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3813 NewTL.setArg(i, ParamDecls[i]);
3814
3815 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003816}
Mike Stump11289f42009-09-09 15:08:12 +00003817
Douglas Gregord6ff3322009-08-04 16:50:30 +00003818template<typename Derived>
3819QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003820 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003821 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003822 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003823 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3824 if (ResultType.isNull())
3825 return QualType();
3826
3827 QualType Result = TL.getType();
3828 if (getDerived().AlwaysRebuild() ||
3829 ResultType != T->getResultType())
3830 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3831
3832 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3833 NewTL.setLParenLoc(TL.getLParenLoc());
3834 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003835 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003836
3837 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003838}
Mike Stump11289f42009-09-09 15:08:12 +00003839
John McCallb96ec562009-12-04 22:46:56 +00003840template<typename Derived> QualType
3841TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003842 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003843 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003844 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003845 if (!D)
3846 return QualType();
3847
3848 QualType Result = TL.getType();
3849 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3850 Result = getDerived().RebuildUnresolvedUsingType(D);
3851 if (Result.isNull())
3852 return QualType();
3853 }
3854
3855 // We might get an arbitrary type spec type back. We should at
3856 // least always get a type spec type, though.
3857 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3858 NewTL.setNameLoc(TL.getNameLoc());
3859
3860 return Result;
3861}
3862
Douglas Gregord6ff3322009-08-04 16:50:30 +00003863template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003864QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003865 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003866 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003867 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003868 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3869 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003870 if (!Typedef)
3871 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003872
John McCall550e0c22009-10-21 00:40:46 +00003873 QualType Result = TL.getType();
3874 if (getDerived().AlwaysRebuild() ||
3875 Typedef != T->getDecl()) {
3876 Result = getDerived().RebuildTypedefType(Typedef);
3877 if (Result.isNull())
3878 return QualType();
3879 }
Mike Stump11289f42009-09-09 15:08:12 +00003880
John McCall550e0c22009-10-21 00:40:46 +00003881 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3882 NewTL.setNameLoc(TL.getNameLoc());
3883
3884 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003885}
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003888QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003889 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003890 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003891 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003892
John McCalldadc5752010-08-24 06:29:42 +00003893 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003894 if (E.isInvalid())
3895 return QualType();
3896
John McCall550e0c22009-10-21 00:40:46 +00003897 QualType Result = TL.getType();
3898 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003899 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003900 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003901 if (Result.isNull())
3902 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003903 }
John McCall550e0c22009-10-21 00:40:46 +00003904 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003905
John McCall550e0c22009-10-21 00:40:46 +00003906 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003907 NewTL.setTypeofLoc(TL.getTypeofLoc());
3908 NewTL.setLParenLoc(TL.getLParenLoc());
3909 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003910
3911 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
3914template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003915QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003916 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003917 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3918 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3919 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003920 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003921
John McCall550e0c22009-10-21 00:40:46 +00003922 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003923 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3924 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003925 if (Result.isNull())
3926 return QualType();
3927 }
Mike Stump11289f42009-09-09 15:08:12 +00003928
John McCall550e0c22009-10-21 00:40:46 +00003929 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003930 NewTL.setTypeofLoc(TL.getTypeofLoc());
3931 NewTL.setLParenLoc(TL.getLParenLoc());
3932 NewTL.setRParenLoc(TL.getRParenLoc());
3933 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003934
3935 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003936}
Mike Stump11289f42009-09-09 15:08:12 +00003937
3938template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003939QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003940 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003941 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003942
Douglas Gregore922c772009-08-04 22:27:00 +00003943 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003944 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003945
John McCalldadc5752010-08-24 06:29:42 +00003946 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003947 if (E.isInvalid())
3948 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003949
John McCall550e0c22009-10-21 00:40:46 +00003950 QualType Result = TL.getType();
3951 if (getDerived().AlwaysRebuild() ||
3952 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003953 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003954 if (Result.isNull())
3955 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003956 }
John McCall550e0c22009-10-21 00:40:46 +00003957 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003958
John McCall550e0c22009-10-21 00:40:46 +00003959 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3960 NewTL.setNameLoc(TL.getNameLoc());
3961
3962 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963}
3964
3965template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003966QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003967 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003968 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003969 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003970 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3971 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003972 if (!Record)
3973 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003974
John McCall550e0c22009-10-21 00:40:46 +00003975 QualType Result = TL.getType();
3976 if (getDerived().AlwaysRebuild() ||
3977 Record != T->getDecl()) {
3978 Result = getDerived().RebuildRecordType(Record);
3979 if (Result.isNull())
3980 return QualType();
3981 }
Mike Stump11289f42009-09-09 15:08:12 +00003982
John McCall550e0c22009-10-21 00:40:46 +00003983 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3984 NewTL.setNameLoc(TL.getNameLoc());
3985
3986 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003987}
Mike Stump11289f42009-09-09 15:08:12 +00003988
3989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003990QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003991 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003992 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003993 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003994 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3995 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003996 if (!Enum)
3997 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003998
John McCall550e0c22009-10-21 00:40:46 +00003999 QualType Result = TL.getType();
4000 if (getDerived().AlwaysRebuild() ||
4001 Enum != T->getDecl()) {
4002 Result = getDerived().RebuildEnumType(Enum);
4003 if (Result.isNull())
4004 return QualType();
4005 }
Mike Stump11289f42009-09-09 15:08:12 +00004006
John McCall550e0c22009-10-21 00:40:46 +00004007 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4008 NewTL.setNameLoc(TL.getNameLoc());
4009
4010 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011}
John McCallfcc33b02009-09-05 00:15:47 +00004012
John McCalle78aac42010-03-10 03:28:59 +00004013template<typename Derived>
4014QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4015 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004017 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4018 TL.getTypePtr()->getDecl());
4019 if (!D) return QualType();
4020
4021 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4022 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4023 return T;
4024}
4025
Douglas Gregord6ff3322009-08-04 16:50:30 +00004026template<typename Derived>
4027QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004028 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004029 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004030 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004031}
4032
Mike Stump11289f42009-09-09 15:08:12 +00004033template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004034QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004035 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004036 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004037 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004038}
4039
4040template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004041QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4042 TypeLocBuilder &TLB,
4043 SubstTemplateTypeParmPackTypeLoc TL) {
4044 return TransformTypeSpecType(TLB, TL);
4045}
4046
4047template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004048QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004049 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004050 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004051 const TemplateSpecializationType *T = TL.getTypePtr();
4052
Mike Stump11289f42009-09-09 15:08:12 +00004053 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004054 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004055 if (Template.isNull())
4056 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004057
John McCall31f82722010-11-12 08:19:04 +00004058 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4059}
4060
Douglas Gregorfe921a72010-12-20 23:36:19 +00004061namespace {
4062 /// \brief Simple iterator that traverses the template arguments in a
4063 /// container that provides a \c getArgLoc() member function.
4064 ///
4065 /// This iterator is intended to be used with the iterator form of
4066 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4067 template<typename ArgLocContainer>
4068 class TemplateArgumentLocContainerIterator {
4069 ArgLocContainer *Container;
4070 unsigned Index;
4071
4072 public:
4073 typedef TemplateArgumentLoc value_type;
4074 typedef TemplateArgumentLoc reference;
4075 typedef int difference_type;
4076 typedef std::input_iterator_tag iterator_category;
4077
4078 class pointer {
4079 TemplateArgumentLoc Arg;
4080
4081 public:
4082 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4083
4084 const TemplateArgumentLoc *operator->() const {
4085 return &Arg;
4086 }
4087 };
4088
4089
4090 TemplateArgumentLocContainerIterator() {}
4091
4092 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4093 unsigned Index)
4094 : Container(&Container), Index(Index) { }
4095
4096 TemplateArgumentLocContainerIterator &operator++() {
4097 ++Index;
4098 return *this;
4099 }
4100
4101 TemplateArgumentLocContainerIterator operator++(int) {
4102 TemplateArgumentLocContainerIterator Old(*this);
4103 ++(*this);
4104 return Old;
4105 }
4106
4107 TemplateArgumentLoc operator*() const {
4108 return Container->getArgLoc(Index);
4109 }
4110
4111 pointer operator->() const {
4112 return pointer(Container->getArgLoc(Index));
4113 }
4114
4115 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004116 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004117 return X.Container == Y.Container && X.Index == Y.Index;
4118 }
4119
4120 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004121 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004122 return !(X == Y);
4123 }
4124 };
4125}
4126
4127
John McCall31f82722010-11-12 08:19:04 +00004128template <typename Derived>
4129QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4130 TypeLocBuilder &TLB,
4131 TemplateSpecializationTypeLoc TL,
4132 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004133 TemplateArgumentListInfo NewTemplateArgs;
4134 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4135 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004136 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4137 ArgIterator;
4138 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4139 ArgIterator(TL, TL.getNumArgs()),
4140 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004141 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004142
John McCall0ad16662009-10-29 08:12:44 +00004143 // FIXME: maybe don't rebuild if all the template arguments are the same.
4144
4145 QualType Result =
4146 getDerived().RebuildTemplateSpecializationType(Template,
4147 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004148 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004149
4150 if (!Result.isNull()) {
4151 TemplateSpecializationTypeLoc NewTL
4152 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4153 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4154 NewTL.setLAngleLoc(TL.getLAngleLoc());
4155 NewTL.setRAngleLoc(TL.getRAngleLoc());
4156 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4157 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004158 }
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall0ad16662009-10-29 08:12:44 +00004160 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004161}
Mike Stump11289f42009-09-09 15:08:12 +00004162
4163template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004164QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004165TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004166 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004167 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004168
4169 NestedNameSpecifier *NNS = 0;
4170 // NOTE: the qualifier in an ElaboratedType is optional.
4171 if (T->getQualifier() != 0) {
4172 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004173 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004174 if (!NNS)
4175 return QualType();
4176 }
Mike Stump11289f42009-09-09 15:08:12 +00004177
John McCall31f82722010-11-12 08:19:04 +00004178 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4179 if (NamedT.isNull())
4180 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004181
John McCall550e0c22009-10-21 00:40:46 +00004182 QualType Result = TL.getType();
4183 if (getDerived().AlwaysRebuild() ||
4184 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004185 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004186 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4187 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004188 if (Result.isNull())
4189 return QualType();
4190 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191
Abramo Bagnara6150c882010-05-11 21:36:43 +00004192 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004193 NewTL.setKeywordLoc(TL.getKeywordLoc());
4194 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004195
4196 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004197}
Mike Stump11289f42009-09-09 15:08:12 +00004198
4199template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004200QualType TreeTransform<Derived>::TransformAttributedType(
4201 TypeLocBuilder &TLB,
4202 AttributedTypeLoc TL) {
4203 const AttributedType *oldType = TL.getTypePtr();
4204 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4205 if (modifiedType.isNull())
4206 return QualType();
4207
4208 QualType result = TL.getType();
4209
4210 // FIXME: dependent operand expressions?
4211 if (getDerived().AlwaysRebuild() ||
4212 modifiedType != oldType->getModifiedType()) {
4213 // TODO: this is really lame; we should really be rebuilding the
4214 // equivalent type from first principles.
4215 QualType equivalentType
4216 = getDerived().TransformType(oldType->getEquivalentType());
4217 if (equivalentType.isNull())
4218 return QualType();
4219 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4220 modifiedType,
4221 equivalentType);
4222 }
4223
4224 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4225 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4226 if (TL.hasAttrOperand())
4227 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4228 if (TL.hasAttrExprOperand())
4229 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4230 else if (TL.hasAttrEnumOperand())
4231 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4232
4233 return result;
4234}
4235
4236template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004237QualType
4238TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4239 ParenTypeLoc TL) {
4240 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4241 if (Inner.isNull())
4242 return QualType();
4243
4244 QualType Result = TL.getType();
4245 if (getDerived().AlwaysRebuild() ||
4246 Inner != TL.getInnerLoc().getType()) {
4247 Result = getDerived().RebuildParenType(Inner);
4248 if (Result.isNull())
4249 return QualType();
4250 }
4251
4252 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4253 NewTL.setLParenLoc(TL.getLParenLoc());
4254 NewTL.setRParenLoc(TL.getRParenLoc());
4255 return Result;
4256}
4257
4258template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004259QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004260 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004261 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004262
Douglas Gregord6ff3322009-08-04 16:50:30 +00004263 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004264 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004265 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004266 if (!NNS)
4267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004268
John McCallc392f372010-06-11 00:33:02 +00004269 QualType Result
4270 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4271 T->getIdentifier(),
4272 TL.getKeywordLoc(),
4273 TL.getQualifierRange(),
4274 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004275 if (Result.isNull())
4276 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004277
Abramo Bagnarad7548482010-05-19 21:37:53 +00004278 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4279 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004280 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4281
Abramo Bagnarad7548482010-05-19 21:37:53 +00004282 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4283 NewTL.setKeywordLoc(TL.getKeywordLoc());
4284 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004285 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004286 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4287 NewTL.setKeywordLoc(TL.getKeywordLoc());
4288 NewTL.setQualifierRange(TL.getQualifierRange());
4289 NewTL.setNameLoc(TL.getNameLoc());
4290 }
John McCall550e0c22009-10-21 00:40:46 +00004291 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004292}
Mike Stump11289f42009-09-09 15:08:12 +00004293
Douglas Gregord6ff3322009-08-04 16:50:30 +00004294template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004295QualType TreeTransform<Derived>::
4296 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004297 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004298 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004299
4300 NestedNameSpecifier *NNS
4301 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004302 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004303 if (!NNS)
4304 return QualType();
4305
John McCall31f82722010-11-12 08:19:04 +00004306 return getDerived()
4307 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4308}
4309
4310template<typename Derived>
4311QualType TreeTransform<Derived>::
4312 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4313 DependentTemplateSpecializationTypeLoc TL,
4314 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004315 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004316
John McCallc392f372010-06-11 00:33:02 +00004317 TemplateArgumentListInfo NewTemplateArgs;
4318 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4319 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004320
4321 typedef TemplateArgumentLocContainerIterator<
4322 DependentTemplateSpecializationTypeLoc> ArgIterator;
4323 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4324 ArgIterator(TL, TL.getNumArgs()),
4325 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004326 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004327
Douglas Gregora5614c52010-09-08 23:56:00 +00004328 QualType Result
4329 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4330 NNS,
4331 TL.getQualifierRange(),
4332 T->getIdentifier(),
4333 TL.getNameLoc(),
4334 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004335 if (Result.isNull())
4336 return QualType();
4337
4338 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4339 QualType NamedT = ElabT->getNamedType();
4340
4341 // Copy information relevant to the template specialization.
4342 TemplateSpecializationTypeLoc NamedTL
4343 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4344 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4345 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4346 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4347 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4348
4349 // Copy information relevant to the elaborated type.
4350 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4351 NewTL.setKeywordLoc(TL.getKeywordLoc());
4352 NewTL.setQualifierRange(TL.getQualifierRange());
4353 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004354 TypeLoc NewTL(Result, TL.getOpaqueData());
4355 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004356 }
4357 return Result;
4358}
4359
4360template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004361QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4362 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004363 QualType Pattern
4364 = getDerived().TransformType(TLB, TL.getPatternLoc());
4365 if (Pattern.isNull())
4366 return QualType();
4367
4368 QualType Result = TL.getType();
4369 if (getDerived().AlwaysRebuild() ||
4370 Pattern != TL.getPatternLoc().getType()) {
4371 Result = getDerived().RebuildPackExpansionType(Pattern,
4372 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004373 TL.getEllipsisLoc(),
4374 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004375 if (Result.isNull())
4376 return QualType();
4377 }
4378
4379 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4380 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4381 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004382}
4383
4384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004385QualType
4386TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004387 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004388 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004389 TLB.pushFullCopy(TL);
4390 return TL.getType();
4391}
4392
4393template<typename Derived>
4394QualType
4395TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004396 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004397 // ObjCObjectType is never dependent.
4398 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004399 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004400}
Mike Stump11289f42009-09-09 15:08:12 +00004401
4402template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004403QualType
4404TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004405 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004406 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004407 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004408 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004409}
4410
Douglas Gregord6ff3322009-08-04 16:50:30 +00004411//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004412// Statement transformation
4413//===----------------------------------------------------------------------===//
4414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004415StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004416TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004417 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004418}
4419
4420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004421StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004422TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4423 return getDerived().TransformCompoundStmt(S, false);
4424}
4425
4426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004427StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004428TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004429 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004430 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004431 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004432 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004433 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4434 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004435 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004436 if (Result.isInvalid()) {
4437 // Immediately fail if this was a DeclStmt, since it's very
4438 // likely that this will cause problems for future statements.
4439 if (isa<DeclStmt>(*B))
4440 return StmtError();
4441
4442 // Otherwise, just keep processing substatements and fail later.
4443 SubStmtInvalid = true;
4444 continue;
4445 }
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregorebe10102009-08-20 07:17:43 +00004447 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4448 Statements.push_back(Result.takeAs<Stmt>());
4449 }
Mike Stump11289f42009-09-09 15:08:12 +00004450
John McCall1ababa62010-08-27 19:56:05 +00004451 if (SubStmtInvalid)
4452 return StmtError();
4453
Douglas Gregorebe10102009-08-20 07:17:43 +00004454 if (!getDerived().AlwaysRebuild() &&
4455 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004456 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004457
4458 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4459 move_arg(Statements),
4460 S->getRBracLoc(),
4461 IsStmtExpr);
4462}
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregorebe10102009-08-20 07:17:43 +00004464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004465StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004466TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004467 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004468 {
4469 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004470 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004471
Eli Friedman06577382009-11-19 03:14:00 +00004472 // Transform the left-hand case value.
4473 LHS = getDerived().TransformExpr(S->getLHS());
4474 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004475 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004476
Eli Friedman06577382009-11-19 03:14:00 +00004477 // Transform the right-hand case value (for the GNU case-range extension).
4478 RHS = getDerived().TransformExpr(S->getRHS());
4479 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004480 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004481 }
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregorebe10102009-08-20 07:17:43 +00004483 // Build the case statement.
4484 // Case statements are always rebuilt so that they will attached to their
4485 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004486 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004487 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004488 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004489 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004490 S->getColonLoc());
4491 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004492 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregorebe10102009-08-20 07:17:43 +00004494 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004495 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004496 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004497 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregorebe10102009-08-20 07:17:43 +00004499 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004500 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004501}
4502
4503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004504StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004505TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004506 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004507 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004508 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004509 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregorebe10102009-08-20 07:17:43 +00004511 // Default statements are always rebuilt
4512 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004513 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004514}
Mike Stump11289f42009-09-09 15:08:12 +00004515
Douglas Gregorebe10102009-08-20 07:17:43 +00004516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004517StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004518TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004519 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004520 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004521 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004522
Douglas Gregorebe10102009-08-20 07:17:43 +00004523 // FIXME: Pass the real colon location in.
4524 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4525 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004526 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004527}
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregorebe10102009-08-20 07:17:43 +00004529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004530StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004531TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004532 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004533 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004534 VarDecl *ConditionVar = 0;
4535 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004536 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004537 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004538 getDerived().TransformDefinition(
4539 S->getConditionVariable()->getLocation(),
4540 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004541 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004542 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004543 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004544 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004545
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004546 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004547 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004548
4549 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004550 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004551 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4552 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004553 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004554 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004555
John McCallb268a282010-08-23 23:25:46 +00004556 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004557 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004558 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004559
John McCallb268a282010-08-23 23:25:46 +00004560 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4561 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004562 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004563
Douglas Gregorebe10102009-08-20 07:17:43 +00004564 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004565 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004566 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004567 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregorebe10102009-08-20 07:17:43 +00004569 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004570 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004571 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004572 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregorebe10102009-08-20 07:17:43 +00004574 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004575 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004576 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004577 Then.get() == S->getThen() &&
4578 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004579 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004580
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004581 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004582 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004583 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004584}
4585
4586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004587StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004588TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004589 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004590 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004591 VarDecl *ConditionVar = 0;
4592 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004593 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004594 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004595 getDerived().TransformDefinition(
4596 S->getConditionVariable()->getLocation(),
4597 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004598 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004599 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004600 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004601 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004602
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004603 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004604 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004605 }
Mike Stump11289f42009-09-09 15:08:12 +00004606
Douglas Gregorebe10102009-08-20 07:17:43 +00004607 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004608 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004609 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004610 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004611 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004612 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004613
Douglas Gregorebe10102009-08-20 07:17:43 +00004614 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004615 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004616 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004617 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregorebe10102009-08-20 07:17:43 +00004619 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004620 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4621 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004622}
Mike Stump11289f42009-09-09 15:08:12 +00004623
Douglas Gregorebe10102009-08-20 07:17:43 +00004624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004625StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004626TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004627 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004628 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004629 VarDecl *ConditionVar = 0;
4630 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004631 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004632 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004633 getDerived().TransformDefinition(
4634 S->getConditionVariable()->getLocation(),
4635 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004636 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004637 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004638 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004639 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004640
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004641 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004642 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004643
4644 if (S->getCond()) {
4645 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004646 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4647 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004648 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004649 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004650 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004651 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004652 }
Mike Stump11289f42009-09-09 15:08:12 +00004653
John McCallb268a282010-08-23 23:25:46 +00004654 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4655 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004656 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004657
Douglas Gregorebe10102009-08-20 07:17:43 +00004658 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004659 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004660 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004661 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregorebe10102009-08-20 07:17:43 +00004663 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004664 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004665 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004666 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004667 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004669 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004670 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004671}
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregorebe10102009-08-20 07:17:43 +00004673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004674StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004675TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004676 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004677 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004678 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004679 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004681 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004682 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004683 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004684 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004685
Douglas Gregorebe10102009-08-20 07:17:43 +00004686 if (!getDerived().AlwaysRebuild() &&
4687 Cond.get() == S->getCond() &&
4688 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004689 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004690
John McCallb268a282010-08-23 23:25:46 +00004691 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4692 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004693 S->getRParenLoc());
4694}
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregorebe10102009-08-20 07:17:43 +00004696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004697StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004698TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004700 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004701 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004702 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregorebe10102009-08-20 07:17:43 +00004704 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004705 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004706 VarDecl *ConditionVar = 0;
4707 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004708 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004709 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004710 getDerived().TransformDefinition(
4711 S->getConditionVariable()->getLocation(),
4712 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004713 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004714 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004715 } else {
4716 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004717
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004718 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004719 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004720
4721 if (S->getCond()) {
4722 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004723 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4724 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004725 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004726 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004727
John McCallb268a282010-08-23 23:25:46 +00004728 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004729 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004730 }
Mike Stump11289f42009-09-09 15:08:12 +00004731
John McCallb268a282010-08-23 23:25:46 +00004732 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4733 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004734 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004735
Douglas Gregorebe10102009-08-20 07:17:43 +00004736 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004737 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004738 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004739 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004740
John McCallb268a282010-08-23 23:25:46 +00004741 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4742 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004743 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004744
Douglas Gregorebe10102009-08-20 07:17:43 +00004745 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004746 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004747 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregorebe10102009-08-20 07:17:43 +00004750 if (!getDerived().AlwaysRebuild() &&
4751 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004752 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004753 Inc.get() == S->getInc() &&
4754 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004755 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004756
Douglas Gregorebe10102009-08-20 07:17:43 +00004757 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004758 Init.get(), FullCond, ConditionVar,
4759 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004760}
4761
4762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004763StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004764TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004765 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004766 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004767 S->getLabel());
4768}
4769
4770template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004771StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004772TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004773 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004774 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004775 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004776
Douglas Gregorebe10102009-08-20 07:17:43 +00004777 if (!getDerived().AlwaysRebuild() &&
4778 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004779 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004780
4781 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004782 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004783}
4784
4785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004786StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004787TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004788 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004789}
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregorebe10102009-08-20 07:17:43 +00004791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004792StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004793TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004794 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004795}
Mike Stump11289f42009-09-09 15:08:12 +00004796
Douglas Gregorebe10102009-08-20 07:17:43 +00004797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004798StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004799TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004800 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004801 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004802 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004803
Mike Stump11289f42009-09-09 15:08:12 +00004804 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004805 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004806 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004807}
Mike Stump11289f42009-09-09 15:08:12 +00004808
Douglas Gregorebe10102009-08-20 07:17:43 +00004809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004810StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004811TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004812 bool DeclChanged = false;
4813 llvm::SmallVector<Decl *, 4> Decls;
4814 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4815 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004816 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4817 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004818 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004819 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregorebe10102009-08-20 07:17:43 +00004821 if (Transformed != *D)
4822 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregorebe10102009-08-20 07:17:43 +00004824 Decls.push_back(Transformed);
4825 }
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregorebe10102009-08-20 07:17:43 +00004827 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004828 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004829
4830 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004831 S->getStartLoc(), S->getEndLoc());
4832}
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregorebe10102009-08-20 07:17:43 +00004834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004835StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004836TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004837
John McCall37ad5512010-08-23 06:44:23 +00004838 ASTOwningVector<Expr*> Constraints(getSema());
4839 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004840 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004841
John McCalldadc5752010-08-24 06:29:42 +00004842 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004843 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004844
4845 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004846
Anders Carlssonaaeef072010-01-24 05:50:09 +00004847 // Go through the outputs.
4848 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004849 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004850
Anders Carlssonaaeef072010-01-24 05:50:09 +00004851 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004852 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004853
Anders Carlssonaaeef072010-01-24 05:50:09 +00004854 // Transform the output expr.
4855 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004856 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004857 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004859
Anders Carlssonaaeef072010-01-24 05:50:09 +00004860 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004861
John McCallb268a282010-08-23 23:25:46 +00004862 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004863 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004864
Anders Carlssonaaeef072010-01-24 05:50:09 +00004865 // Go through the inputs.
4866 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004867 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004868
Anders Carlssonaaeef072010-01-24 05:50:09 +00004869 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004870 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004871
Anders Carlssonaaeef072010-01-24 05:50:09 +00004872 // Transform the input expr.
4873 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004874 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004875 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004876 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004877
Anders Carlssonaaeef072010-01-24 05:50:09 +00004878 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004879
John McCallb268a282010-08-23 23:25:46 +00004880 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004881 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004882
Anders Carlssonaaeef072010-01-24 05:50:09 +00004883 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004884 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004885
4886 // Go through the clobbers.
4887 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004888 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004889
4890 // No need to transform the asm string literal.
4891 AsmString = SemaRef.Owned(S->getAsmString());
4892
4893 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4894 S->isSimple(),
4895 S->isVolatile(),
4896 S->getNumOutputs(),
4897 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004898 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004899 move_arg(Constraints),
4900 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004901 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004902 move_arg(Clobbers),
4903 S->getRParenLoc(),
4904 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004905}
4906
4907
4908template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004909StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004910TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004911 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004912 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004913 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004915
Douglas Gregor96c79492010-04-23 22:50:49 +00004916 // Transform the @catch statements (if present).
4917 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004918 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004919 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004920 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004921 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004922 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004923 if (Catch.get() != S->getCatchStmt(I))
4924 AnyCatchChanged = true;
4925 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004926 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004927
Douglas Gregor306de2f2010-04-22 23:59:56 +00004928 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004929 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004930 if (S->getFinallyStmt()) {
4931 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4932 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004933 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004934 }
4935
4936 // If nothing changed, just retain this statement.
4937 if (!getDerived().AlwaysRebuild() &&
4938 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004939 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004940 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004941 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004942
Douglas Gregor306de2f2010-04-22 23:59:56 +00004943 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004944 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4945 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004946}
Mike Stump11289f42009-09-09 15:08:12 +00004947
Douglas Gregorebe10102009-08-20 07:17:43 +00004948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004949StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004950TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004951 // Transform the @catch parameter, if there is one.
4952 VarDecl *Var = 0;
4953 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4954 TypeSourceInfo *TSInfo = 0;
4955 if (FromVar->getTypeSourceInfo()) {
4956 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4957 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004958 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004959 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004960
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004961 QualType T;
4962 if (TSInfo)
4963 T = TSInfo->getType();
4964 else {
4965 T = getDerived().TransformType(FromVar->getType());
4966 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004967 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004968 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004969
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004970 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4971 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004972 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004973 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004974
John McCalldadc5752010-08-24 06:29:42 +00004975 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004976 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004977 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004978
4979 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004980 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004981 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004982}
Mike Stump11289f42009-09-09 15:08:12 +00004983
Douglas Gregorebe10102009-08-20 07:17:43 +00004984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004985StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004986TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004987 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004988 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004989 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004991
Douglas Gregor306de2f2010-04-22 23:59:56 +00004992 // If nothing changed, just retain this statement.
4993 if (!getDerived().AlwaysRebuild() &&
4994 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004995 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004996
4997 // Build a new statement.
4998 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004999 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005000}
Mike Stump11289f42009-09-09 15:08:12 +00005001
Douglas Gregorebe10102009-08-20 07:17:43 +00005002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005003StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005004TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005005 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005006 if (S->getThrowExpr()) {
5007 Operand = getDerived().TransformExpr(S->getThrowExpr());
5008 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005009 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005010 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005011
Douglas Gregor2900c162010-04-22 21:44:01 +00005012 if (!getDerived().AlwaysRebuild() &&
5013 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005014 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005015
John McCallb268a282010-08-23 23:25:46 +00005016 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017}
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregorebe10102009-08-20 07:17:43 +00005019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005020StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005021TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005022 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005023 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005024 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005025 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005026 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005027
Douglas Gregor6148de72010-04-22 22:01:21 +00005028 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005029 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005030 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005031 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005032
Douglas Gregor6148de72010-04-22 22:01:21 +00005033 // If nothing change, just retain the current statement.
5034 if (!getDerived().AlwaysRebuild() &&
5035 Object.get() == S->getSynchExpr() &&
5036 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005037 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005038
5039 // Build a new statement.
5040 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005041 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005042}
5043
5044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005045StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005046TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005047 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005048 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005049 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005050 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005051 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005052
Douglas Gregorf68a5082010-04-22 23:10:45 +00005053 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005054 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005055 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005056 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005057
Douglas Gregorf68a5082010-04-22 23:10:45 +00005058 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005059 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005060 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005061 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005062
Douglas Gregorf68a5082010-04-22 23:10:45 +00005063 // If nothing changed, just retain this statement.
5064 if (!getDerived().AlwaysRebuild() &&
5065 Element.get() == S->getElement() &&
5066 Collection.get() == S->getCollection() &&
5067 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005068 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005069
Douglas Gregorf68a5082010-04-22 23:10:45 +00005070 // Build a new statement.
5071 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5072 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005073 Element.get(),
5074 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005075 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005076 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005077}
5078
5079
5080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005081StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005082TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5083 // Transform the exception declaration, if any.
5084 VarDecl *Var = 0;
5085 if (S->getExceptionDecl()) {
5086 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005087 TypeSourceInfo *T = getDerived().TransformType(
5088 ExceptionDecl->getTypeSourceInfo());
5089 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005090 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005091
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005092 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005093 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005094 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005095 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005096 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005097 }
Mike Stump11289f42009-09-09 15:08:12 +00005098
Douglas Gregorebe10102009-08-20 07:17:43 +00005099 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005100 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005101 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005102 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005103
Douglas Gregorebe10102009-08-20 07:17:43 +00005104 if (!getDerived().AlwaysRebuild() &&
5105 !Var &&
5106 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005107 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005108
5109 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5110 Var,
John McCallb268a282010-08-23 23:25:46 +00005111 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005112}
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregorebe10102009-08-20 07:17:43 +00005114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005115StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005116TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5117 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005118 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005119 = getDerived().TransformCompoundStmt(S->getTryBlock());
5120 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregorebe10102009-08-20 07:17:43 +00005123 // Transform the handlers.
5124 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005125 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005126 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005127 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005128 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5129 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregorebe10102009-08-20 07:17:43 +00005132 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5133 Handlers.push_back(Handler.takeAs<Stmt>());
5134 }
Mike Stump11289f42009-09-09 15:08:12 +00005135
Douglas Gregorebe10102009-08-20 07:17:43 +00005136 if (!getDerived().AlwaysRebuild() &&
5137 TryBlock.get() == S->getTryBlock() &&
5138 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005139 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005140
John McCallb268a282010-08-23 23:25:46 +00005141 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005142 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005143}
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregorebe10102009-08-20 07:17:43 +00005145//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005146// Expression transformation
5147//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005149ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005150TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005151 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
5154template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005155ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005156TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005157 NestedNameSpecifier *Qualifier = 0;
5158 if (E->getQualifier()) {
5159 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005160 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005161 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005162 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005163 }
John McCallce546572009-12-08 09:08:17 +00005164
5165 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005166 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5167 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005170
John McCall815039a2010-08-17 21:27:17 +00005171 DeclarationNameInfo NameInfo = E->getNameInfo();
5172 if (NameInfo.getName()) {
5173 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5174 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005175 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005176 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005177
5178 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005179 Qualifier == E->getQualifier() &&
5180 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005181 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005182 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005183
5184 // Mark it referenced in the new context regardless.
5185 // FIXME: this is a bit instantiation-specific.
5186 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5187
John McCallc3007a22010-10-26 07:05:15 +00005188 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005189 }
John McCallce546572009-12-08 09:08:17 +00005190
5191 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005192 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005193 TemplateArgs = &TransArgs;
5194 TransArgs.setLAngleLoc(E->getLAngleLoc());
5195 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005196 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5197 E->getNumTemplateArgs(),
5198 TransArgs))
5199 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005200 }
5201
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005202 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005203 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
Mike Stump11289f42009-09-09 15:08:12 +00005205
Douglas Gregora16548e2009-08-11 05:31:07 +00005206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005208TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005209 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005210}
Mike Stump11289f42009-09-09 15:08:12 +00005211
Douglas Gregora16548e2009-08-11 05:31:07 +00005212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005214TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005215 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005216}
Mike Stump11289f42009-09-09 15:08:12 +00005217
Douglas Gregora16548e2009-08-11 05:31:07 +00005218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005220TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005221 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005222}
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregora16548e2009-08-11 05:31:07 +00005224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005226TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005227 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005228}
Mike Stump11289f42009-09-09 15:08:12 +00005229
Douglas Gregora16548e2009-08-11 05:31:07 +00005230template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005231ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005232TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005233 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005234}
5235
5236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005238TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005239 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005240 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005244 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005245
John McCallb268a282010-08-23 23:25:46 +00005246 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 E->getRParen());
5248}
5249
Mike Stump11289f42009-09-09 15:08:12 +00005250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005253 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005254 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5261 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005262 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005267TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5268 // Transform the type.
5269 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5270 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005271 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005272
Douglas Gregor882211c2010-04-28 22:16:22 +00005273 // Transform all of the components into components similar to what the
5274 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005275 // FIXME: It would be slightly more efficient in the non-dependent case to
5276 // just map FieldDecls, rather than requiring the rebuilder to look for
5277 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005278 // template code that we don't care.
5279 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005280 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005281 typedef OffsetOfExpr::OffsetOfNode Node;
5282 llvm::SmallVector<Component, 4> Components;
5283 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5284 const Node &ON = E->getComponent(I);
5285 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005286 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005287 Comp.LocStart = ON.getRange().getBegin();
5288 Comp.LocEnd = ON.getRange().getEnd();
5289 switch (ON.getKind()) {
5290 case Node::Array: {
5291 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005293 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005295
Douglas Gregor882211c2010-04-28 22:16:22 +00005296 ExprChanged = ExprChanged || Index.get() != FromIndex;
5297 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005298 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005299 break;
5300 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005301
Douglas Gregor882211c2010-04-28 22:16:22 +00005302 case Node::Field:
5303 case Node::Identifier:
5304 Comp.isBrackets = false;
5305 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005306 if (!Comp.U.IdentInfo)
5307 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005308
Douglas Gregor882211c2010-04-28 22:16:22 +00005309 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005310
Douglas Gregord1702062010-04-29 00:18:15 +00005311 case Node::Base:
5312 // Will be recomputed during the rebuild.
5313 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005314 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005315
Douglas Gregor882211c2010-04-28 22:16:22 +00005316 Components.push_back(Comp);
5317 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005318
Douglas Gregor882211c2010-04-28 22:16:22 +00005319 // If nothing changed, retain the existing expression.
5320 if (!getDerived().AlwaysRebuild() &&
5321 Type == E->getTypeSourceInfo() &&
5322 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005323 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324
Douglas Gregor882211c2010-04-28 22:16:22 +00005325 // Build a new offsetof expression.
5326 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5327 Components.data(), Components.size(),
5328 E->getRParenLoc());
5329}
5330
5331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005332ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005333TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5334 assert(getDerived().AlreadyTransformed(E->getType()) &&
5335 "opaque value expression requires transformation");
5336 return SemaRef.Owned(E);
5337}
5338
5339template<typename Derived>
5340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005341TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005342 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005343 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005344
John McCallbcd03502009-12-07 02:54:59 +00005345 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005346 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005348
John McCall4c98fd82009-11-04 07:28:41 +00005349 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005350 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005351
John McCall4c98fd82009-11-04 07:28:41 +00005352 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005353 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005354 E->getSourceRange());
5355 }
Mike Stump11289f42009-09-09 15:08:12 +00005356
John McCalldadc5752010-08-24 06:29:42 +00005357 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005358 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005359 // C++0x [expr.sizeof]p1:
5360 // The operand is either an expression, which is an unevaluated operand
5361 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005362 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005363
Douglas Gregora16548e2009-08-11 05:31:07 +00005364 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5365 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005367
Douglas Gregora16548e2009-08-11 05:31:07 +00005368 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005369 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005370 }
Mike Stump11289f42009-09-09 15:08:12 +00005371
John McCallb268a282010-08-23 23:25:46 +00005372 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005373 E->isSizeOf(),
5374 E->getSourceRange());
5375}
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregora16548e2009-08-11 05:31:07 +00005377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005378ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005379TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005380 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005381 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005382 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005383
John McCalldadc5752010-08-24 06:29:42 +00005384 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005386 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005387
5388
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 if (!getDerived().AlwaysRebuild() &&
5390 LHS.get() == E->getLHS() &&
5391 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005392 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005393
John McCallb268a282010-08-23 23:25:46 +00005394 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005395 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005396 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 E->getRBracketLoc());
5398}
Mike Stump11289f42009-09-09 15:08:12 +00005399
5400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005402TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005403 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005404 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005405 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005406 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005407
5408 // Transform arguments.
5409 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005410 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005411 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5412 &ArgChanged))
5413 return ExprError();
5414
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 if (!getDerived().AlwaysRebuild() &&
5416 Callee.get() == E->getCallee() &&
5417 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005418 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005421 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005422 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005423 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005425 E->getRParenLoc());
5426}
Mike Stump11289f42009-09-09 15:08:12 +00005427
5428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005430TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005431 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005432 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005435 NestedNameSpecifier *Qualifier = 0;
5436 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005437 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005438 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005439 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005440 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005441 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005442 }
Mike Stump11289f42009-09-09 15:08:12 +00005443
Eli Friedman2cfcef62009-12-04 06:40:45 +00005444 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005445 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5446 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005449
John McCall16df1e52010-03-30 21:47:33 +00005450 NamedDecl *FoundDecl = E->getFoundDecl();
5451 if (FoundDecl == E->getMemberDecl()) {
5452 FoundDecl = Member;
5453 } else {
5454 FoundDecl = cast_or_null<NamedDecl>(
5455 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5456 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005457 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005458 }
5459
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 if (!getDerived().AlwaysRebuild() &&
5461 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005462 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005463 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005464 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005465 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005466
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005467 // Mark it referenced in the new context regardless.
5468 // FIXME: this is a bit instantiation-specific.
5469 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005470 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005471 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005472
John McCall6b51f282009-11-23 01:53:49 +00005473 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005474 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005475 TransArgs.setLAngleLoc(E->getLAngleLoc());
5476 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005477 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5478 E->getNumTemplateArgs(),
5479 TransArgs))
5480 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005482
Douglas Gregora16548e2009-08-11 05:31:07 +00005483 // FIXME: Bogus source location for the operator
5484 SourceLocation FakeOperatorLoc
5485 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5486
John McCall38836f02010-01-15 08:34:02 +00005487 // FIXME: to do this check properly, we will need to preserve the
5488 // first-qualifier-in-scope here, just in case we had a dependent
5489 // base (and therefore couldn't do the check) and a
5490 // nested-name-qualifier (and therefore could do the lookup).
5491 NamedDecl *FirstQualifierInScope = 0;
5492
John McCallb268a282010-08-23 23:25:46 +00005493 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005494 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005495 Qualifier,
5496 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005497 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005498 Member,
John McCall16df1e52010-03-30 21:47:33 +00005499 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005500 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005501 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005502 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005503}
Mike Stump11289f42009-09-09 15:08:12 +00005504
Douglas Gregora16548e2009-08-11 05:31:07 +00005505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005506ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005507TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005508 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005509 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005511
John McCalldadc5752010-08-24 06:29:42 +00005512 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005513 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005514 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 if (!getDerived().AlwaysRebuild() &&
5517 LHS.get() == E->getLHS() &&
5518 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005519 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005520
Douglas Gregora16548e2009-08-11 05:31:07 +00005521 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005522 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005523}
5524
Mike Stump11289f42009-09-09 15:08:12 +00005525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005526ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005527TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005528 CompoundAssignOperator *E) {
5529 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005530}
Mike Stump11289f42009-09-09 15:08:12 +00005531
Douglas Gregora16548e2009-08-11 05:31:07 +00005532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005533ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005534TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005535 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005536 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005537 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005538
John McCalldadc5752010-08-24 06:29:42 +00005539 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005540 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005542
John McCalldadc5752010-08-24 06:29:42 +00005543 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregora16548e2009-08-11 05:31:07 +00005547 if (!getDerived().AlwaysRebuild() &&
5548 Cond.get() == E->getCond() &&
5549 LHS.get() == E->getLHS() &&
5550 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005551 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005552
John McCallb268a282010-08-23 23:25:46 +00005553 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005554 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005555 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005556 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005557 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
5560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005562TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005563 // Implicit casts are eliminated during transformation, since they
5564 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005565 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005566}
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005569ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005570TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005571 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5572 if (!Type)
5573 return ExprError();
5574
John McCalldadc5752010-08-24 06:29:42 +00005575 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005576 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005578 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregora16548e2009-08-11 05:31:07 +00005580 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005581 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005583 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005584
John McCall97513962010-01-15 18:39:57 +00005585 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005586 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005588 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005589}
Mike Stump11289f42009-09-09 15:08:12 +00005590
Douglas Gregora16548e2009-08-11 05:31:07 +00005591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005593TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005594 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5595 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5596 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005598
John McCalldadc5752010-08-24 06:29:42 +00005599 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005602
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005604 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005606 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005607
John McCall5d7aa7f2010-01-19 22:33:45 +00005608 // Note: the expression type doesn't necessarily match the
5609 // type-as-written, but that's okay, because it should always be
5610 // derivable from the initializer.
5611
John McCalle15bbff2010-01-18 19:35:47 +00005612 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005614 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005615}
Mike Stump11289f42009-09-09 15:08:12 +00005616
Douglas Gregora16548e2009-08-11 05:31:07 +00005617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005619TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005620 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005621 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 if (!getDerived().AlwaysRebuild() &&
5625 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005626 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005627
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005629 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005630 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005631 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 E->getAccessorLoc(),
5633 E->getAccessor());
5634}
Mike Stump11289f42009-09-09 15:08:12 +00005635
Douglas Gregora16548e2009-08-11 05:31:07 +00005636template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005637ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005638TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005640
John McCall37ad5512010-08-23 06:44:23 +00005641 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005642 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5643 Inits, &InitChanged))
5644 return ExprError();
5645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005647 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005650 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005651}
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregora16548e2009-08-11 05:31:07 +00005653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005655TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005656 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregorebe10102009-08-20 07:17:43 +00005658 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005659 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregorebe10102009-08-20 07:17:43 +00005663 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005664 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 bool ExprChanged = false;
5666 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5667 DEnd = E->designators_end();
5668 D != DEnd; ++D) {
5669 if (D->isFieldDesignator()) {
5670 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5671 D->getDotLoc(),
5672 D->getFieldLoc()));
5673 continue;
5674 }
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005677 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005680
5681 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5685 ArrayExprs.push_back(Index.release());
5686 continue;
5687 }
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005690 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5692 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005693 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005694
John McCalldadc5752010-08-24 06:29:42 +00005695 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005697 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005698
5699 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 End.get(),
5701 D->getLBracketLoc(),
5702 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5705 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 ArrayExprs.push_back(Start.release());
5708 ArrayExprs.push_back(End.release());
5709 }
Mike Stump11289f42009-09-09 15:08:12 +00005710
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 if (!getDerived().AlwaysRebuild() &&
5712 Init.get() == E->getInit() &&
5713 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005714 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005715
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5717 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005718 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005719}
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregora16548e2009-08-11 05:31:07 +00005721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005722ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005723TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005724 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005725 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005726
Douglas Gregor3da3c062009-10-28 00:29:27 +00005727 // FIXME: Will we ever have proper type location here? Will we actually
5728 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005729 QualType T = getDerived().TransformType(E->getType());
5730 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 if (!getDerived().AlwaysRebuild() &&
5734 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005735 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005736
Douglas Gregora16548e2009-08-11 05:31:07 +00005737 return getDerived().RebuildImplicitValueInitExpr(T);
5738}
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregora16548e2009-08-11 05:31:07 +00005740template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005741ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005742TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005743 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5744 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005746
John McCalldadc5752010-08-24 06:29:42 +00005747 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005750
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005752 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005754 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005755
John McCallb268a282010-08-23 23:25:46 +00005756 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005757 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005758}
5759
5760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005761ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005762TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005763 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005764 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005765 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5766 &ArgumentChanged))
5767 return ExprError();
5768
Douglas Gregora16548e2009-08-11 05:31:07 +00005769 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5770 move_arg(Inits),
5771 E->getRParenLoc());
5772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregora16548e2009-08-11 05:31:07 +00005774/// \brief Transform an address-of-label expression.
5775///
5776/// By default, the transformation of an address-of-label expression always
5777/// rebuilds the expression, so that the label identifier can be resolved to
5778/// the corresponding label statement by semantic analysis.
5779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005781TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005782 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5783 E->getLabel());
5784}
Mike Stump11289f42009-09-09 15:08:12 +00005785
5786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005788TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005789 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5791 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 if (!getDerived().AlwaysRebuild() &&
5795 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005796 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005797
5798 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005799 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005800 E->getRParenLoc());
5801}
Mike Stump11289f42009-09-09 15:08:12 +00005802
Douglas Gregora16548e2009-08-11 05:31:07 +00005803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005806 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005808 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005809
John McCalldadc5752010-08-24 06:29:42 +00005810 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005811 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005813
John McCalldadc5752010-08-24 06:29:42 +00005814 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005815 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005817
Douglas Gregora16548e2009-08-11 05:31:07 +00005818 if (!getDerived().AlwaysRebuild() &&
5819 Cond.get() == E->getCond() &&
5820 LHS.get() == E->getLHS() &&
5821 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005822 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005825 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 E->getRParenLoc());
5827}
Mike Stump11289f42009-09-09 15:08:12 +00005828
Douglas Gregora16548e2009-08-11 05:31:07 +00005829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005830ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005831TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005832 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005833}
5834
5835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005836ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005837TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005838 switch (E->getOperator()) {
5839 case OO_New:
5840 case OO_Delete:
5841 case OO_Array_New:
5842 case OO_Array_Delete:
5843 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005844 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005845
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005846 case OO_Call: {
5847 // This is a call to an object's operator().
5848 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5849
5850 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005851 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005852 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005853 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005854
5855 // FIXME: Poor location information
5856 SourceLocation FakeLParenLoc
5857 = SemaRef.PP.getLocForEndOfToken(
5858 static_cast<Expr *>(Object.get())->getLocEnd());
5859
5860 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005861 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005862 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5863 Args))
5864 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005865
John McCallb268a282010-08-23 23:25:46 +00005866 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005867 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005868 E->getLocEnd());
5869 }
5870
5871#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5872 case OO_##Name:
5873#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5874#include "clang/Basic/OperatorKinds.def"
5875 case OO_Subscript:
5876 // Handled below.
5877 break;
5878
5879 case OO_Conditional:
5880 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005881 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005882
5883 case OO_None:
5884 case NUM_OVERLOADED_OPERATORS:
5885 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005886 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005887 }
5888
John McCalldadc5752010-08-24 06:29:42 +00005889 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005890 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005892
John McCalldadc5752010-08-24 06:29:42 +00005893 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005894 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005895 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005896
John McCalldadc5752010-08-24 06:29:42 +00005897 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005898 if (E->getNumArgs() == 2) {
5899 Second = getDerived().TransformExpr(E->getArg(1));
5900 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005902 }
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregora16548e2009-08-11 05:31:07 +00005904 if (!getDerived().AlwaysRebuild() &&
5905 Callee.get() == E->getCallee() &&
5906 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005907 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005908 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5911 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005912 Callee.get(),
5913 First.get(),
5914 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005915}
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregora16548e2009-08-11 05:31:07 +00005917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005919TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5920 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005924ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00005925TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
5926 // Transform the callee.
5927 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5928 if (Callee.isInvalid())
5929 return ExprError();
5930
5931 // Transform exec config.
5932 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
5933 if (EC.isInvalid())
5934 return ExprError();
5935
5936 // Transform arguments.
5937 bool ArgChanged = false;
5938 ASTOwningVector<Expr*> Args(SemaRef);
5939 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5940 &ArgChanged))
5941 return ExprError();
5942
5943 if (!getDerived().AlwaysRebuild() &&
5944 Callee.get() == E->getCallee() &&
5945 !ArgChanged)
5946 return SemaRef.Owned(E);
5947
5948 // FIXME: Wrong source location information for the '('.
5949 SourceLocation FakeLParenLoc
5950 = ((Expr *)Callee.get())->getSourceRange().getBegin();
5951 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
5952 move_arg(Args),
5953 E->getRParenLoc(), EC.get());
5954}
5955
5956template<typename Derived>
5957ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005958TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005959 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5960 if (!Type)
5961 return ExprError();
5962
John McCalldadc5752010-08-24 06:29:42 +00005963 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005964 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005965 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005967
Douglas Gregora16548e2009-08-11 05:31:07 +00005968 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005969 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005971 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005974 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005975 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5976 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5977 SourceLocation FakeRParenLoc
5978 = SemaRef.PP.getLocForEndOfToken(
5979 E->getSubExpr()->getSourceRange().getEnd());
5980 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005981 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005982 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005983 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005984 FakeRAngleLoc,
5985 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005986 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005987 FakeRParenLoc);
5988}
Mike Stump11289f42009-09-09 15:08:12 +00005989
Douglas Gregora16548e2009-08-11 05:31:07 +00005990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005992TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5993 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005994}
Mike Stump11289f42009-09-09 15:08:12 +00005995
5996template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005997ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005998TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5999 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006000}
6001
Douglas Gregora16548e2009-08-11 05:31:07 +00006002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006003ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006004TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006005 CXXReinterpretCastExpr *E) {
6006 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006007}
Mike Stump11289f42009-09-09 15:08:12 +00006008
Douglas Gregora16548e2009-08-11 05:31:07 +00006009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6012 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006013}
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregora16548e2009-08-11 05:31:07 +00006015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006016ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006017TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006018 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006019 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6020 if (!Type)
6021 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006022
John McCalldadc5752010-08-24 06:29:42 +00006023 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006024 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006026 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006029 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006031 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006032
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006033 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006035 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006036 E->getRParenLoc());
6037}
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregora16548e2009-08-11 05:31:07 +00006039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006040ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006041TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006042 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006043 TypeSourceInfo *TInfo
6044 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6045 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006047
Douglas Gregora16548e2009-08-11 05:31:07 +00006048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006049 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006050 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006051
Douglas Gregor9da64192010-04-26 22:37:10 +00006052 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6053 E->getLocStart(),
6054 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 E->getLocEnd());
6056 }
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregora16548e2009-08-11 05:31:07 +00006058 // We don't know whether the expression is potentially evaluated until
6059 // after we perform semantic analysis, so the expression is potentially
6060 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006061 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006062 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006063
John McCalldadc5752010-08-24 06:29:42 +00006064 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006065 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006067
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 if (!getDerived().AlwaysRebuild() &&
6069 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregor9da64192010-04-26 22:37:10 +00006072 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6073 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006074 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006075 E->getLocEnd());
6076}
6077
6078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006080TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6081 if (E->isTypeOperand()) {
6082 TypeSourceInfo *TInfo
6083 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6084 if (!TInfo)
6085 return ExprError();
6086
6087 if (!getDerived().AlwaysRebuild() &&
6088 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006089 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006090
6091 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6092 E->getLocStart(),
6093 TInfo,
6094 E->getLocEnd());
6095 }
6096
6097 // We don't know whether the expression is potentially evaluated until
6098 // after we perform semantic analysis, so the expression is potentially
6099 // potentially evaluated.
6100 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6101
6102 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6103 if (SubExpr.isInvalid())
6104 return ExprError();
6105
6106 if (!getDerived().AlwaysRebuild() &&
6107 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006108 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006109
6110 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6111 E->getLocStart(),
6112 SubExpr.get(),
6113 E->getLocEnd());
6114}
6115
6116template<typename Derived>
6117ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006118TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006120}
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregora16548e2009-08-11 05:31:07 +00006122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006123ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006124TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006125 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006126 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006127}
Mike Stump11289f42009-09-09 15:08:12 +00006128
Douglas Gregora16548e2009-08-11 05:31:07 +00006129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006132 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6133 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6134 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006135
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006136 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006138
Douglas Gregorb15af892010-01-07 23:12:05 +00006139 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006140}
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregora16548e2009-08-11 05:31:07 +00006142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006144TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006145 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006148
Douglas Gregora16548e2009-08-11 05:31:07 +00006149 if (!getDerived().AlwaysRebuild() &&
6150 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006151 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006152
John McCallb268a282010-08-23 23:25:46 +00006153 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006154}
Mike Stump11289f42009-09-09 15:08:12 +00006155
Douglas Gregora16548e2009-08-11 05:31:07 +00006156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006157ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006158TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006159 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006160 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6161 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006162 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006164
Chandler Carruth794da4c2010-02-08 06:42:49 +00006165 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregor033f6752009-12-23 23:03:06 +00006169 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006170}
Mike Stump11289f42009-09-09 15:08:12 +00006171
Douglas Gregora16548e2009-08-11 05:31:07 +00006172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006173ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006174TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6175 CXXScalarValueInitExpr *E) {
6176 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6177 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006178 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006179
Douglas Gregora16548e2009-08-11 05:31:07 +00006180 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006181 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006182 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006183
Douglas Gregor2b88c112010-09-08 00:15:04 +00006184 return getDerived().RebuildCXXScalarValueInitExpr(T,
6185 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006186 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006187}
Mike Stump11289f42009-09-09 15:08:12 +00006188
Douglas Gregora16548e2009-08-11 05:31:07 +00006189template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006190ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006191TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006193 TypeSourceInfo *AllocTypeInfo
6194 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6195 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006199 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006200 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203 // Transform the placement arguments (if any).
6204 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006205 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006206 if (getDerived().TransformExprs(E->getPlacementArgs(),
6207 E->getNumPlacementArgs(), true,
6208 PlacementArgs, &ArgumentChanged))
6209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006210
Douglas Gregorebe10102009-08-20 07:17:43 +00006211 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006212 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006213 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6214 ConstructorArgs, &ArgumentChanged))
6215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006216
Douglas Gregord2d9da02010-02-26 00:38:10 +00006217 // Transform constructor, new operator, and delete operator.
6218 CXXConstructorDecl *Constructor = 0;
6219 if (E->getConstructor()) {
6220 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006221 getDerived().TransformDecl(E->getLocStart(),
6222 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006223 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006224 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006225 }
6226
6227 FunctionDecl *OperatorNew = 0;
6228 if (E->getOperatorNew()) {
6229 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006230 getDerived().TransformDecl(E->getLocStart(),
6231 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006232 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006233 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006234 }
6235
6236 FunctionDecl *OperatorDelete = 0;
6237 if (E->getOperatorDelete()) {
6238 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006239 getDerived().TransformDecl(E->getLocStart(),
6240 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006241 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006243 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006244
Douglas Gregora16548e2009-08-11 05:31:07 +00006245 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006246 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006247 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006248 Constructor == E->getConstructor() &&
6249 OperatorNew == E->getOperatorNew() &&
6250 OperatorDelete == E->getOperatorDelete() &&
6251 !ArgumentChanged) {
6252 // Mark any declarations we need as referenced.
6253 // FIXME: instantiation-specific.
6254 if (Constructor)
6255 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6256 if (OperatorNew)
6257 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6258 if (OperatorDelete)
6259 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006260 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006261 }
Mike Stump11289f42009-09-09 15:08:12 +00006262
Douglas Gregor0744ef62010-09-07 21:49:58 +00006263 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006264 if (!ArraySize.get()) {
6265 // If no array size was specified, but the new expression was
6266 // instantiated with an array type (e.g., "new T" where T is
6267 // instantiated with "int[4]"), extract the outer bound from the
6268 // array type as our array size. We do this with constant and
6269 // dependently-sized array types.
6270 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6271 if (!ArrayT) {
6272 // Do nothing
6273 } else if (const ConstantArrayType *ConsArrayT
6274 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006275 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006276 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6277 ConsArrayT->getSize(),
6278 SemaRef.Context.getSizeType(),
6279 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006280 AllocType = ConsArrayT->getElementType();
6281 } else if (const DependentSizedArrayType *DepArrayT
6282 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6283 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006284 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006285 AllocType = DepArrayT->getElementType();
6286 }
6287 }
6288 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006289
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6291 E->isGlobalNew(),
6292 /*FIXME:*/E->getLocStart(),
6293 move_arg(PlacementArgs),
6294 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006295 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006296 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006297 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006298 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006299 /*FIXME:*/E->getLocStart(),
6300 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006301 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006302}
Mike Stump11289f42009-09-09 15:08:12 +00006303
Douglas Gregora16548e2009-08-11 05:31:07 +00006304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006306TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006307 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006308 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006310
Douglas Gregord2d9da02010-02-26 00:38:10 +00006311 // Transform the delete operator, if known.
6312 FunctionDecl *OperatorDelete = 0;
6313 if (E->getOperatorDelete()) {
6314 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006315 getDerived().TransformDecl(E->getLocStart(),
6316 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006317 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006318 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006319 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006320
Douglas Gregora16548e2009-08-11 05:31:07 +00006321 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006322 Operand.get() == E->getArgument() &&
6323 OperatorDelete == E->getOperatorDelete()) {
6324 // Mark any declarations we need as referenced.
6325 // FIXME: instantiation-specific.
6326 if (OperatorDelete)
6327 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006328
6329 if (!E->getArgument()->isTypeDependent()) {
6330 QualType Destroyed = SemaRef.Context.getBaseElementType(
6331 E->getDestroyedType());
6332 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6333 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6334 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6335 SemaRef.LookupDestructor(Record));
6336 }
6337 }
6338
John McCallc3007a22010-10-26 07:05:15 +00006339 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006340 }
Mike Stump11289f42009-09-09 15:08:12 +00006341
Douglas Gregora16548e2009-08-11 05:31:07 +00006342 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6343 E->isGlobalDelete(),
6344 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006345 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006346}
Mike Stump11289f42009-09-09 15:08:12 +00006347
Douglas Gregora16548e2009-08-11 05:31:07 +00006348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006349ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006350TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006351 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006352 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006353 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006355
John McCallba7bf592010-08-24 05:47:05 +00006356 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006357 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006358 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006359 E->getOperatorLoc(),
6360 E->isArrow()? tok::arrow : tok::period,
6361 ObjectTypePtr,
6362 MayBePseudoDestructor);
6363 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006364 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006365
John McCallba7bf592010-08-24 05:47:05 +00006366 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006367 NestedNameSpecifier *Qualifier = E->getQualifier();
6368 if (Qualifier) {
6369 Qualifier
6370 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6371 E->getQualifierRange(),
6372 ObjectType);
6373 if (!Qualifier)
6374 return ExprError();
6375 }
Mike Stump11289f42009-09-09 15:08:12 +00006376
Douglas Gregor678f90d2010-02-25 01:56:36 +00006377 PseudoDestructorTypeStorage Destroyed;
6378 if (E->getDestroyedTypeInfo()) {
6379 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006380 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6381 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006382 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006383 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006384 Destroyed = DestroyedTypeInfo;
6385 } else if (ObjectType->isDependentType()) {
6386 // We aren't likely to be able to resolve the identifier down to a type
6387 // now anyway, so just retain the identifier.
6388 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6389 E->getDestroyedTypeLoc());
6390 } else {
6391 // Look for a destructor known with the given name.
6392 CXXScopeSpec SS;
6393 if (Qualifier) {
6394 SS.setScopeRep(Qualifier);
6395 SS.setRange(E->getQualifierRange());
6396 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006397
John McCallba7bf592010-08-24 05:47:05 +00006398 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006399 *E->getDestroyedTypeIdentifier(),
6400 E->getDestroyedTypeLoc(),
6401 /*Scope=*/0,
6402 SS, ObjectTypePtr,
6403 false);
6404 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006405 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006406
Douglas Gregor678f90d2010-02-25 01:56:36 +00006407 Destroyed
6408 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6409 E->getDestroyedTypeLoc());
6410 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006411
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006412 TypeSourceInfo *ScopeTypeInfo = 0;
6413 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006414 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006415 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006416 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006417 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006418
John McCallb268a282010-08-23 23:25:46 +00006419 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006420 E->getOperatorLoc(),
6421 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006422 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006423 E->getQualifierRange(),
6424 ScopeTypeInfo,
6425 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006426 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006427 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006428}
Mike Stump11289f42009-09-09 15:08:12 +00006429
Douglas Gregorad8a3362009-09-04 17:36:40 +00006430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006431ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006432TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006433 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006434 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6435
6436 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6437 Sema::LookupOrdinaryName);
6438
6439 // Transform all the decls.
6440 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6441 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006442 NamedDecl *InstD = static_cast<NamedDecl*>(
6443 getDerived().TransformDecl(Old->getNameLoc(),
6444 *I));
John McCall84d87672009-12-10 09:41:52 +00006445 if (!InstD) {
6446 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6447 // This can happen because of dependent hiding.
6448 if (isa<UsingShadowDecl>(*I))
6449 continue;
6450 else
John McCallfaf5fb42010-08-26 23:41:50 +00006451 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006452 }
John McCalle66edc12009-11-24 19:00:30 +00006453
6454 // Expand using declarations.
6455 if (isa<UsingDecl>(InstD)) {
6456 UsingDecl *UD = cast<UsingDecl>(InstD);
6457 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6458 E = UD->shadow_end(); I != E; ++I)
6459 R.addDecl(*I);
6460 continue;
6461 }
6462
6463 R.addDecl(InstD);
6464 }
6465
6466 // Resolve a kind, but don't do any further analysis. If it's
6467 // ambiguous, the callee needs to deal with it.
6468 R.resolveKind();
6469
6470 // Rebuild the nested-name qualifier, if present.
6471 CXXScopeSpec SS;
6472 NestedNameSpecifier *Qualifier = 0;
6473 if (Old->getQualifier()) {
6474 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006475 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006476 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006477 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006478
John McCalle66edc12009-11-24 19:00:30 +00006479 SS.setScopeRep(Qualifier);
6480 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006481 }
6482
Douglas Gregor9262f472010-04-27 18:19:34 +00006483 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006484 CXXRecordDecl *NamingClass
6485 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6486 Old->getNameLoc(),
6487 Old->getNamingClass()));
6488 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006489 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006490
Douglas Gregorda7be082010-04-27 16:10:10 +00006491 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006492 }
6493
6494 // If we have no template arguments, it's a normal declaration name.
6495 if (!Old->hasExplicitTemplateArgs())
6496 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6497
6498 // If we have template arguments, rebuild them, then rebuild the
6499 // templateid expression.
6500 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006501 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6502 Old->getNumTemplateArgs(),
6503 TransArgs))
6504 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006505
6506 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6507 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006508}
Mike Stump11289f42009-09-09 15:08:12 +00006509
Douglas Gregora16548e2009-08-11 05:31:07 +00006510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006512TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006513 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6514 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregora16548e2009-08-11 05:31:07 +00006517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006518 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006519 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006520
Mike Stump11289f42009-09-09 15:08:12 +00006521 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006522 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 T,
6524 E->getLocEnd());
6525}
Mike Stump11289f42009-09-09 15:08:12 +00006526
Douglas Gregora16548e2009-08-11 05:31:07 +00006527template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006528ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006529TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6530 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6531 if (!LhsT)
6532 return ExprError();
6533
6534 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6535 if (!RhsT)
6536 return ExprError();
6537
6538 if (!getDerived().AlwaysRebuild() &&
6539 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6540 return SemaRef.Owned(E);
6541
6542 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6543 E->getLocStart(),
6544 LhsT, RhsT,
6545 E->getLocEnd());
6546}
6547
6548template<typename Derived>
6549ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006550TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006551 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006553 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006554 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006555 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006556 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006557
John McCall31f82722010-11-12 08:19:04 +00006558 // TODO: If this is a conversion-function-id, verify that the
6559 // destination type name (if present) resolves the same way after
6560 // instantiation as it did in the local scope.
6561
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006562 DeclarationNameInfo NameInfo
6563 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6564 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006566
John McCalle66edc12009-11-24 19:00:30 +00006567 if (!E->hasExplicitTemplateArgs()) {
6568 if (!getDerived().AlwaysRebuild() &&
6569 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006570 // Note: it is sufficient to compare the Name component of NameInfo:
6571 // if name has not changed, DNLoc has not changed either.
6572 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006573 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006574
John McCalle66edc12009-11-24 19:00:30 +00006575 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6576 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006577 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006578 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006579 }
John McCall6b51f282009-11-23 01:53:49 +00006580
6581 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006582 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6583 E->getNumTemplateArgs(),
6584 TransArgs))
6585 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006586
John McCalle66edc12009-11-24 19:00:30 +00006587 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6588 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006589 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006590 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006591}
6592
6593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006595TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006596 // CXXConstructExprs are always implicit, so when we have a
6597 // 1-argument construction we just transform that argument.
6598 if (E->getNumArgs() == 1 ||
6599 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6600 return getDerived().TransformExpr(E->getArg(0));
6601
Douglas Gregora16548e2009-08-11 05:31:07 +00006602 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6603
6604 QualType T = getDerived().TransformType(E->getType());
6605 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006606 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006607
6608 CXXConstructorDecl *Constructor
6609 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006610 getDerived().TransformDecl(E->getLocStart(),
6611 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006612 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006614
Douglas Gregora16548e2009-08-11 05:31:07 +00006615 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006616 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006617 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6618 &ArgumentChanged))
6619 return ExprError();
6620
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 if (!getDerived().AlwaysRebuild() &&
6622 T == E->getType() &&
6623 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006624 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006625 // Mark the constructor as referenced.
6626 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006627 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006628 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006629 }
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregordb121ba2009-12-14 16:27:04 +00006631 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6632 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006633 move_arg(Args),
6634 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006635 E->getConstructionKind(),
6636 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006637}
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregora16548e2009-08-11 05:31:07 +00006639/// \brief Transform a C++ temporary-binding expression.
6640///
Douglas Gregor363b1512009-12-24 18:51:59 +00006641/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6642/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006645TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006646 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
John McCall5d413782010-12-06 08:20:24 +00006649/// \brief Transform a C++ expression that contains cleanups that should
6650/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006651///
John McCall5d413782010-12-06 08:20:24 +00006652/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006653/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006655ExprResult
John McCall5d413782010-12-06 08:20:24 +00006656TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006657 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006658}
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregora16548e2009-08-11 05:31:07 +00006660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006661ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006662TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006663 CXXTemporaryObjectExpr *E) {
6664 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6665 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006666 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregora16548e2009-08-11 05:31:07 +00006668 CXXConstructorDecl *Constructor
6669 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006670 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006671 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006672 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregora16548e2009-08-11 05:31:07 +00006675 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006676 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006678 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6679 &ArgumentChanged))
6680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006681
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006683 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006685 !ArgumentChanged) {
6686 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006687 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006688 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006689 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006690
6691 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6692 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006693 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 E->getLocEnd());
6695}
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregora16548e2009-08-11 05:31:07 +00006697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006698ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006699TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006700 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006701 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6702 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006706 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006707 Args.reserve(E->arg_size());
6708 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6709 &ArgumentChanged))
6710 return ExprError();
6711
Douglas Gregora16548e2009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006713 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006715 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006716
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006718 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006719 E->getLParenLoc(),
6720 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006721 E->getRParenLoc());
6722}
Mike Stump11289f42009-09-09 15:08:12 +00006723
Douglas Gregora16548e2009-08-11 05:31:07 +00006724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006725ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006726TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006727 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006728 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006729 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006730 Expr *OldBase;
6731 QualType BaseType;
6732 QualType ObjectType;
6733 if (!E->isImplicitAccess()) {
6734 OldBase = E->getBase();
6735 Base = getDerived().TransformExpr(OldBase);
6736 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006737 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006738
John McCall2d74de92009-12-01 22:10:20 +00006739 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006740 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006741 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006742 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006743 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006744 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006745 ObjectTy,
6746 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006747 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006748 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006749
John McCallba7bf592010-08-24 05:47:05 +00006750 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006751 BaseType = ((Expr*) Base.get())->getType();
6752 } else {
6753 OldBase = 0;
6754 BaseType = getDerived().TransformType(E->getBaseType());
6755 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6756 }
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006758 // Transform the first part of the nested-name-specifier that qualifies
6759 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006760 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006761 = getDerived().TransformFirstQualifierInScope(
6762 E->getFirstQualifierFoundInScope(),
6763 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006764
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006765 NestedNameSpecifier *Qualifier = 0;
6766 if (E->getQualifier()) {
6767 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6768 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006769 ObjectType,
6770 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006771 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006772 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006773 }
Mike Stump11289f42009-09-09 15:08:12 +00006774
John McCall31f82722010-11-12 08:19:04 +00006775 // TODO: If this is a conversion-function-id, verify that the
6776 // destination type name (if present) resolves the same way after
6777 // instantiation as it did in the local scope.
6778
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006779 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006780 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006781 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006783
John McCall2d74de92009-12-01 22:10:20 +00006784 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006785 // This is a reference to a member without an explicitly-specified
6786 // template argument list. Optimize for this common case.
6787 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006788 Base.get() == OldBase &&
6789 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006790 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006791 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006792 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006793 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006794
John McCallb268a282010-08-23 23:25:46 +00006795 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006796 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006797 E->isArrow(),
6798 E->getOperatorLoc(),
6799 Qualifier,
6800 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006801 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006802 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006803 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006804 }
6805
John McCall6b51f282009-11-23 01:53:49 +00006806 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006807 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6808 E->getNumTemplateArgs(),
6809 TransArgs))
6810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
John McCallb268a282010-08-23 23:25:46 +00006812 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006813 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006814 E->isArrow(),
6815 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006816 Qualifier,
6817 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006818 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006819 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006820 &TransArgs);
6821}
6822
6823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006824ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006825TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006826 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006827 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006828 QualType BaseType;
6829 if (!Old->isImplicitAccess()) {
6830 Base = getDerived().TransformExpr(Old->getBase());
6831 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006833 BaseType = ((Expr*) Base.get())->getType();
6834 } else {
6835 BaseType = getDerived().TransformType(Old->getBaseType());
6836 }
John McCall10eae182009-11-30 22:42:35 +00006837
6838 NestedNameSpecifier *Qualifier = 0;
6839 if (Old->getQualifier()) {
6840 Qualifier
6841 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006842 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006843 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006844 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006845 }
6846
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006847 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006848 Sema::LookupOrdinaryName);
6849
6850 // Transform all the decls.
6851 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6852 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006853 NamedDecl *InstD = static_cast<NamedDecl*>(
6854 getDerived().TransformDecl(Old->getMemberLoc(),
6855 *I));
John McCall84d87672009-12-10 09:41:52 +00006856 if (!InstD) {
6857 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6858 // This can happen because of dependent hiding.
6859 if (isa<UsingShadowDecl>(*I))
6860 continue;
6861 else
John McCallfaf5fb42010-08-26 23:41:50 +00006862 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006863 }
John McCall10eae182009-11-30 22:42:35 +00006864
6865 // Expand using declarations.
6866 if (isa<UsingDecl>(InstD)) {
6867 UsingDecl *UD = cast<UsingDecl>(InstD);
6868 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6869 E = UD->shadow_end(); I != E; ++I)
6870 R.addDecl(*I);
6871 continue;
6872 }
6873
6874 R.addDecl(InstD);
6875 }
6876
6877 R.resolveKind();
6878
Douglas Gregor9262f472010-04-27 18:19:34 +00006879 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006880 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006881 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006882 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006883 Old->getMemberLoc(),
6884 Old->getNamingClass()));
6885 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006886 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006887
Douglas Gregorda7be082010-04-27 16:10:10 +00006888 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006889 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006890
John McCall10eae182009-11-30 22:42:35 +00006891 TemplateArgumentListInfo TransArgs;
6892 if (Old->hasExplicitTemplateArgs()) {
6893 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6894 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006895 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6896 Old->getNumTemplateArgs(),
6897 TransArgs))
6898 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006899 }
John McCall38836f02010-01-15 08:34:02 +00006900
6901 // FIXME: to do this check properly, we will need to preserve the
6902 // first-qualifier-in-scope here, just in case we had a dependent
6903 // base (and therefore couldn't do the check) and a
6904 // nested-name-qualifier (and therefore could do the lookup).
6905 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006906
John McCallb268a282010-08-23 23:25:46 +00006907 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006908 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006909 Old->getOperatorLoc(),
6910 Old->isArrow(),
6911 Qualifier,
6912 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006913 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006914 R,
6915 (Old->hasExplicitTemplateArgs()
6916 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006917}
6918
6919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006920ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006921TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6922 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6923 if (SubExpr.isInvalid())
6924 return ExprError();
6925
6926 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006927 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006928
6929 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6930}
6931
6932template<typename Derived>
6933ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006934TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006935 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6936 if (Pattern.isInvalid())
6937 return ExprError();
6938
6939 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6940 return SemaRef.Owned(E);
6941
Douglas Gregorb8840002011-01-14 21:20:45 +00006942 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6943 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006944}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006945
6946template<typename Derived>
6947ExprResult
6948TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6949 // If E is not value-dependent, then nothing will change when we transform it.
6950 // Note: This is an instantiation-centric view.
6951 if (!E->isValueDependent())
6952 return SemaRef.Owned(E);
6953
6954 // Note: None of the implementations of TryExpandParameterPacks can ever
6955 // produce a diagnostic when given only a single unexpanded parameter pack,
6956 // so
6957 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6958 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006959 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006960 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006961 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6962 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006963 ShouldExpand, RetainExpansion,
6964 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006965 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006966
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006967 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006968 return SemaRef.Owned(E);
6969
6970 // We now know the length of the parameter pack, so build a new expression
6971 // that stores that length.
6972 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6973 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006974 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006975}
6976
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006977template<typename Derived>
6978ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00006979TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6980 SubstNonTypeTemplateParmPackExpr *E) {
6981 // Default behavior is to do nothing with this transformation.
6982 return SemaRef.Owned(E);
6983}
6984
6985template<typename Derived>
6986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006988 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006989}
6990
Mike Stump11289f42009-09-09 15:08:12 +00006991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006994 TypeSourceInfo *EncodedTypeInfo
6995 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6996 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006998
Douglas Gregora16548e2009-08-11 05:31:07 +00006999 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007000 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007001 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007002
7003 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007004 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 E->getRParenLoc());
7006}
Mike Stump11289f42009-09-09 15:08:12 +00007007
Douglas Gregora16548e2009-08-11 05:31:07 +00007008template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007009ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007010TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007011 // Transform arguments.
7012 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007013 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007014 Args.reserve(E->getNumArgs());
7015 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7016 &ArgChanged))
7017 return ExprError();
7018
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007019 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7020 // Class message: transform the receiver type.
7021 TypeSourceInfo *ReceiverTypeInfo
7022 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7023 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007024 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007025
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007026 // If nothing changed, just retain the existing message send.
7027 if (!getDerived().AlwaysRebuild() &&
7028 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007029 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007030
7031 // Build a new class message send.
7032 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7033 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007034 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007035 E->getMethodDecl(),
7036 E->getLeftLoc(),
7037 move_arg(Args),
7038 E->getRightLoc());
7039 }
7040
7041 // Instance message: transform the receiver
7042 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7043 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007044 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007045 = getDerived().TransformExpr(E->getInstanceReceiver());
7046 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007047 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007048
7049 // If nothing changed, just retain the existing message send.
7050 if (!getDerived().AlwaysRebuild() &&
7051 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007052 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007053
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007054 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007055 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007056 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007057 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007058 E->getMethodDecl(),
7059 E->getLeftLoc(),
7060 move_arg(Args),
7061 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007062}
7063
Mike Stump11289f42009-09-09 15:08:12 +00007064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007066TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007067 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007068}
7069
Mike Stump11289f42009-09-09 15:08:12 +00007070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007073 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007074}
7075
Mike Stump11289f42009-09-09 15:08:12 +00007076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007078TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007079 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007080 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007081 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007083
7084 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007085
Douglas Gregord51d90d2010-04-26 20:11:03 +00007086 // If nothing changed, just retain the existing expression.
7087 if (!getDerived().AlwaysRebuild() &&
7088 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007089 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007090
John McCallb268a282010-08-23 23:25:46 +00007091 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007092 E->getLocation(),
7093 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007094}
7095
Mike Stump11289f42009-09-09 15:08:12 +00007096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007098TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007099 // 'super' and types never change. Property never changes. Just
7100 // retain the existing expression.
7101 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007103
Douglas Gregor9faee212010-04-26 20:47:02 +00007104 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007105 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007106 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007107 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007108
Douglas Gregor9faee212010-04-26 20:47:02 +00007109 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007110
Douglas Gregor9faee212010-04-26 20:47:02 +00007111 // If nothing changed, just retain the existing expression.
7112 if (!getDerived().AlwaysRebuild() &&
7113 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007114 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007115
John McCallb7bd14f2010-12-02 01:19:52 +00007116 if (E->isExplicitProperty())
7117 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7118 E->getExplicitProperty(),
7119 E->getLocation());
7120
7121 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7122 E->getType(),
7123 E->getImplicitPropertyGetter(),
7124 E->getImplicitPropertySetter(),
7125 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007126}
7127
Mike Stump11289f42009-09-09 15:08:12 +00007128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007130TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007131 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007132 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007133 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007134 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007135
Douglas Gregord51d90d2010-04-26 20:11:03 +00007136 // If nothing changed, just retain the existing expression.
7137 if (!getDerived().AlwaysRebuild() &&
7138 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007139 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007140
John McCallb268a282010-08-23 23:25:46 +00007141 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007142 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007143}
7144
Mike Stump11289f42009-09-09 15:08:12 +00007145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007146ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007147TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007148 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007149 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007150 SubExprs.reserve(E->getNumSubExprs());
7151 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7152 SubExprs, &ArgumentChanged))
7153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007154
Douglas Gregora16548e2009-08-11 05:31:07 +00007155 if (!getDerived().AlwaysRebuild() &&
7156 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007157 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7160 move_arg(SubExprs),
7161 E->getRParenLoc());
7162}
7163
Mike Stump11289f42009-09-09 15:08:12 +00007164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007166TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007167 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007168
John McCall490112f2011-02-04 18:33:18 +00007169 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7170 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7171
7172 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7173 llvm::SmallVector<ParmVarDecl*, 4> params;
7174 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007175
7176 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007177 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7178 oldBlock->param_begin(),
7179 oldBlock->param_size(),
7180 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007181 return true;
John McCall490112f2011-02-04 18:33:18 +00007182
7183 const FunctionType *exprFunctionType = E->getFunctionType();
7184 QualType exprResultType = exprFunctionType->getResultType();
7185 if (!exprResultType.isNull()) {
7186 if (!exprResultType->isDependentType())
7187 blockScope->ReturnType = exprResultType;
7188 else if (exprResultType != getSema().Context.DependentTy)
7189 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007190 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007191
7192 // If the return type has not been determined yet, leave it as a dependent
7193 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007194 if (blockScope->ReturnType.isNull())
7195 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007196
7197 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007198 if (blockScope->ReturnType->isObjCObjectType()) {
7199 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007200 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007201 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007202 return ExprError();
7203 }
John McCall3882ace2011-01-05 12:14:39 +00007204
John McCall490112f2011-02-04 18:33:18 +00007205 QualType functionType = getDerived().RebuildFunctionProtoType(
7206 blockScope->ReturnType,
7207 paramTypes.data(),
7208 paramTypes.size(),
7209 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007210 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007211 exprFunctionType->getExtInfo());
7212 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007213
7214 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007215 if (!params.empty())
7216 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007217
7218 // If the return type wasn't explicitly set, it will have been marked as a
7219 // dependent type (DependentTy); clear out the return type setting so
7220 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007221 if (blockScope->ReturnType == getSema().Context.DependentTy)
7222 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007223
John McCall3882ace2011-01-05 12:14:39 +00007224 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007225 StmtResult body = getDerived().TransformStmt(E->getBody());
7226 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007227 return ExprError();
7228
John McCall490112f2011-02-04 18:33:18 +00007229#ifndef NDEBUG
7230 // In builds with assertions, make sure that we captured everything we
7231 // captured before.
7232
7233 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7234
7235 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7236 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007237 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007238
7239 // Ignore parameter packs.
7240 if (isa<ParmVarDecl>(oldCapture) &&
7241 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7242 continue;
7243
7244 VarDecl *newCapture =
7245 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7246 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007247 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007248 }
7249#endif
7250
7251 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7252 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007253}
7254
Mike Stump11289f42009-09-09 15:08:12 +00007255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007257TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007258 NestedNameSpecifier *Qualifier = 0;
7259
7260 ValueDecl *ND
7261 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7262 E->getDecl()));
7263 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007264 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007265
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007266 if (!getDerived().AlwaysRebuild() &&
7267 ND == E->getDecl()) {
7268 // Mark it referenced in the new context regardless.
7269 // FIXME: this is a bit instantiation-specific.
7270 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7271
John McCallc3007a22010-10-26 07:05:15 +00007272 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007273 }
7274
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007275 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007276 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007277 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007278}
Mike Stump11289f42009-09-09 15:08:12 +00007279
Douglas Gregora16548e2009-08-11 05:31:07 +00007280//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007281// Type reconstruction
7282//===----------------------------------------------------------------------===//
7283
Mike Stump11289f42009-09-09 15:08:12 +00007284template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007285QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7286 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007287 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007288 getDerived().getBaseEntity());
7289}
7290
Mike Stump11289f42009-09-09 15:08:12 +00007291template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007292QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7293 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007294 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007295 getDerived().getBaseEntity());
7296}
7297
Mike Stump11289f42009-09-09 15:08:12 +00007298template<typename Derived>
7299QualType
John McCall70dd5f62009-10-30 00:06:24 +00007300TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7301 bool WrittenAsLValue,
7302 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007303 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007304 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007305}
7306
7307template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007308QualType
John McCall70dd5f62009-10-30 00:06:24 +00007309TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7310 QualType ClassType,
7311 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007312 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007313 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007314}
7315
7316template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007317QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007318TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7319 ArrayType::ArraySizeModifier SizeMod,
7320 const llvm::APInt *Size,
7321 Expr *SizeExpr,
7322 unsigned IndexTypeQuals,
7323 SourceRange BracketsRange) {
7324 if (SizeExpr || !Size)
7325 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7326 IndexTypeQuals, BracketsRange,
7327 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007328
7329 QualType Types[] = {
7330 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7331 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7332 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007333 };
7334 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7335 QualType SizeType;
7336 for (unsigned I = 0; I != NumTypes; ++I)
7337 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7338 SizeType = Types[I];
7339 break;
7340 }
Mike Stump11289f42009-09-09 15:08:12 +00007341
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007342 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7343 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007344 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007345 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007346 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007347}
Mike Stump11289f42009-09-09 15:08:12 +00007348
Douglas Gregord6ff3322009-08-04 16:50:30 +00007349template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007350QualType
7351TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007352 ArrayType::ArraySizeModifier SizeMod,
7353 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007354 unsigned IndexTypeQuals,
7355 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007356 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007357 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007358}
7359
7360template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007361QualType
Mike Stump11289f42009-09-09 15:08:12 +00007362TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007363 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007364 unsigned IndexTypeQuals,
7365 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007366 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007367 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007368}
Mike Stump11289f42009-09-09 15:08:12 +00007369
Douglas Gregord6ff3322009-08-04 16:50:30 +00007370template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007371QualType
7372TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007373 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007374 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007375 unsigned IndexTypeQuals,
7376 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007377 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007378 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007379 IndexTypeQuals, BracketsRange);
7380}
7381
7382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007383QualType
7384TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007385 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007386 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007387 unsigned IndexTypeQuals,
7388 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007389 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007390 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007391 IndexTypeQuals, BracketsRange);
7392}
7393
7394template<typename Derived>
7395QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007396 unsigned NumElements,
7397 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007398 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007399 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007400}
Mike Stump11289f42009-09-09 15:08:12 +00007401
Douglas Gregord6ff3322009-08-04 16:50:30 +00007402template<typename Derived>
7403QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7404 unsigned NumElements,
7405 SourceLocation AttributeLoc) {
7406 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7407 NumElements, true);
7408 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007409 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7410 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007411 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007412}
Mike Stump11289f42009-09-09 15:08:12 +00007413
Douglas Gregord6ff3322009-08-04 16:50:30 +00007414template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007415QualType
7416TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007417 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007418 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007419 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007420}
Mike Stump11289f42009-09-09 15:08:12 +00007421
Douglas Gregord6ff3322009-08-04 16:50:30 +00007422template<typename Derived>
7423QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007424 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007425 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007426 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007427 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007428 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007429 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007430 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007431 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007432 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007433 getDerived().getBaseEntity(),
7434 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007435}
Mike Stump11289f42009-09-09 15:08:12 +00007436
Douglas Gregord6ff3322009-08-04 16:50:30 +00007437template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007438QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7439 return SemaRef.Context.getFunctionNoProtoType(T);
7440}
7441
7442template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007443QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7444 assert(D && "no decl found");
7445 if (D->isInvalidDecl()) return QualType();
7446
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007447 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007448 TypeDecl *Ty;
7449 if (isa<UsingDecl>(D)) {
7450 UsingDecl *Using = cast<UsingDecl>(D);
7451 assert(Using->isTypeName() &&
7452 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7453
7454 // A valid resolved using typename decl points to exactly one type decl.
7455 assert(++Using->shadow_begin() == Using->shadow_end());
7456 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007457
John McCallb96ec562009-12-04 22:46:56 +00007458 } else {
7459 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7460 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7461 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7462 }
7463
7464 return SemaRef.Context.getTypeDeclType(Ty);
7465}
7466
7467template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007468QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7469 SourceLocation Loc) {
7470 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007471}
7472
7473template<typename Derived>
7474QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7475 return SemaRef.Context.getTypeOfType(Underlying);
7476}
7477
7478template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007479QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7480 SourceLocation Loc) {
7481 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007482}
7483
7484template<typename Derived>
7485QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007486 TemplateName Template,
7487 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007488 const TemplateArgumentListInfo &TemplateArgs) {
7489 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007490}
Mike Stump11289f42009-09-09 15:08:12 +00007491
Douglas Gregor1135c352009-08-06 05:28:30 +00007492template<typename Derived>
7493NestedNameSpecifier *
7494TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7495 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007496 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007497 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007498 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007499 CXXScopeSpec SS;
7500 // FIXME: The source location information is all wrong.
7501 SS.setRange(Range);
7502 SS.setScopeRep(Prefix);
7503 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007504 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007505 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007506 ObjectType,
7507 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007508 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007509}
7510
7511template<typename Derived>
7512NestedNameSpecifier *
7513TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7514 SourceRange Range,
7515 NamespaceDecl *NS) {
7516 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7517}
7518
7519template<typename Derived>
7520NestedNameSpecifier *
7521TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7522 SourceRange Range,
7523 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007524 QualType T) {
7525 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007526 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007527 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007528 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7529 T.getTypePtr());
7530 }
Mike Stump11289f42009-09-09 15:08:12 +00007531
Douglas Gregor1135c352009-08-06 05:28:30 +00007532 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7533 return 0;
7534}
Mike Stump11289f42009-09-09 15:08:12 +00007535
Douglas Gregor71dc5092009-08-06 06:41:21 +00007536template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007537TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007538TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7539 bool TemplateKW,
7540 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007541 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007542 Template);
7543}
7544
7545template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007546TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007547TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007548 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007549 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007550 QualType ObjectType,
7551 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007552 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007553 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007554 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007555 UnqualifiedId Name;
7556 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007557 Sema::TemplateTy Template;
7558 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7559 /*FIXME:*/getDerived().getBaseLocation(),
7560 SS,
7561 Name,
John McCallba7bf592010-08-24 05:47:05 +00007562 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007563 /*EnteringContext=*/false,
7564 Template);
John McCall31f82722010-11-12 08:19:04 +00007565 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007566}
Mike Stump11289f42009-09-09 15:08:12 +00007567
Douglas Gregora16548e2009-08-11 05:31:07 +00007568template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007569TemplateName
7570TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7571 OverloadedOperatorKind Operator,
7572 QualType ObjectType) {
7573 CXXScopeSpec SS;
7574 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7575 SS.setScopeRep(Qualifier);
7576 UnqualifiedId Name;
7577 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7578 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7579 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007580 Sema::TemplateTy Template;
7581 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007582 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007583 SS,
7584 Name,
John McCallba7bf592010-08-24 05:47:05 +00007585 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007586 /*EnteringContext=*/false,
7587 Template);
7588 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007589}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007590
Douglas Gregor71395fa2009-11-04 00:56:37 +00007591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007592ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007593TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7594 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007595 Expr *OrigCallee,
7596 Expr *First,
7597 Expr *Second) {
7598 Expr *Callee = OrigCallee->IgnoreParenCasts();
7599 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007600
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007602 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007603 if (!First->getType()->isOverloadableType() &&
7604 !Second->getType()->isOverloadableType())
7605 return getSema().CreateBuiltinArraySubscriptExpr(First,
7606 Callee->getLocStart(),
7607 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007608 } else if (Op == OO_Arrow) {
7609 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007610 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7611 } else if (Second == 0 || isPostIncDec) {
7612 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007613 // The argument is not of overloadable type, so try to create a
7614 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007615 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007616 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007617
John McCallb268a282010-08-23 23:25:46 +00007618 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007619 }
7620 } else {
John McCallb268a282010-08-23 23:25:46 +00007621 if (!First->getType()->isOverloadableType() &&
7622 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007623 // Neither of the arguments is an overloadable type, so try to
7624 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007625 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007626 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007627 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007628 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 return move(Result);
7632 }
7633 }
Mike Stump11289f42009-09-09 15:08:12 +00007634
7635 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007636 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007637 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007638
John McCallb268a282010-08-23 23:25:46 +00007639 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007640 assert(ULE->requiresADL());
7641
7642 // FIXME: Do we have to check
7643 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007644 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007645 } else {
John McCallb268a282010-08-23 23:25:46 +00007646 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007647 }
Mike Stump11289f42009-09-09 15:08:12 +00007648
Douglas Gregora16548e2009-08-11 05:31:07 +00007649 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007650 Expr *Args[2] = { First, Second };
7651 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007652
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 // Create the overloaded operator invocation for unary operators.
7654 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007655 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007656 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007657 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 }
Mike Stump11289f42009-09-09 15:08:12 +00007659
Sebastian Redladba46e2009-10-29 20:17:01 +00007660 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007661 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007662 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007663 First,
7664 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007665
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007667 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007668 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007669 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7670 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007672
Mike Stump11289f42009-09-09 15:08:12 +00007673 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007674}
Mike Stump11289f42009-09-09 15:08:12 +00007675
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007677ExprResult
John McCallb268a282010-08-23 23:25:46 +00007678TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007679 SourceLocation OperatorLoc,
7680 bool isArrow,
7681 NestedNameSpecifier *Qualifier,
7682 SourceRange QualifierRange,
7683 TypeSourceInfo *ScopeType,
7684 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007685 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007686 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007687 CXXScopeSpec SS;
7688 if (Qualifier) {
7689 SS.setRange(QualifierRange);
7690 SS.setScopeRep(Qualifier);
7691 }
7692
John McCallb268a282010-08-23 23:25:46 +00007693 QualType BaseType = Base->getType();
7694 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007695 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007696 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007697 !BaseType->getAs<PointerType>()->getPointeeType()
7698 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007699 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007700 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007701 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007702 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007703 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007704 /*FIXME?*/true);
7705 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007706
Douglas Gregor678f90d2010-02-25 01:56:36 +00007707 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007708 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7709 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7710 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7711 NameInfo.setNamedTypeInfo(DestroyedType);
7712
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007713 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007714
John McCallb268a282010-08-23 23:25:46 +00007715 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007716 OperatorLoc, isArrow,
7717 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007718 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007719 /*TemplateArgs*/ 0);
7720}
7721
Douglas Gregord6ff3322009-08-04 16:50:30 +00007722} // end namespace clang
7723
7724#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H