blob: bd110bd1f6fac31ad5cb601a95f8666cb97bc04e [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,
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001352 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001353 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001354 }
1355
1356 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001360 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001361 bool isArrow,
1362 NestedNameSpecifier *Qualifier,
1363 SourceRange QualifierRange,
1364 const DeclarationNameInfo &MemberNameInfo,
1365 ValueDecl *Member,
1366 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001367 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001368 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001369 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001370 // We have a reference to an unnamed field. This is always the
1371 // base of an anonymous struct/union member access, i.e. the
1372 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001373 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001374 assert(Member->getType()->isRecordType() &&
1375 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001376
John McCallb268a282010-08-23 23:25:46 +00001377 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001378 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001379 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001380
John McCall7decc9e2010-11-18 06:31:45 +00001381 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001382 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001383 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001384 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001385 cast<FieldDecl>(Member)->getType(),
1386 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001387 return getSema().Owned(ME);
1388 }
Mike Stump11289f42009-09-09 15:08:12 +00001389
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001390 CXXScopeSpec SS;
1391 if (Qualifier) {
1392 SS.setRange(QualifierRange);
1393 SS.setScopeRep(Qualifier);
1394 }
1395
John McCallb268a282010-08-23 23:25:46 +00001396 getSema().DefaultFunctionArrayConversion(Base);
1397 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001398
John McCall16df1e52010-03-30 21:47:33 +00001399 // FIXME: this involves duplicating earlier analysis in a lot of
1400 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001401 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001402 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001403 R.resolveKind();
1404
John McCallb268a282010-08-23 23:25:46 +00001405 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001406 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001407 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 }
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001411 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001414 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001415 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001416 Expr *LHS, Expr *RHS) {
1417 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 }
1419
1420 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001421 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001424 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001426 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001428 Expr *RHS) {
1429 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1430 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 }
1432
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001434 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// By default, performs semantic analysis to build the new expression.
1436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001437 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001438 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001440 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001441 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001442 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 }
Mike Stump11289f42009-09-09 15:08:12 +00001444
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001446 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// By default, performs semantic analysis to build the new expression.
1448 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001449 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001450 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001452 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001453 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001454 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 }
Mike Stump11289f42009-09-09 15:08:12 +00001456
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001458 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 /// By default, performs semantic analysis to build the new expression.
1460 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation OpLoc,
1463 SourceLocation AccessorLoc,
1464 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001465
John McCall10eae182009-11-30 22:42:35 +00001466 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001467 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001468 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001469 OpLoc, /*IsArrow*/ false,
1470 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001471 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001472 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 }
Mike Stump11289f42009-09-09 15:08:12 +00001474
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001476 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001481 SourceLocation RBraceLoc,
1482 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001483 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001484 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1485 if (Result.isInvalid() || ResultTy->isDependentType())
1486 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001487
Douglas Gregord3d93062009-11-09 17:16:50 +00001488 // Patch in the result type we were given, which may have been computed
1489 // when the initial InitListExpr was built.
1490 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1491 ILE->setType(ResultTy);
1492 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 }
Mike Stump11289f42009-09-09 15:08:12 +00001494
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001496 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 /// By default, performs semantic analysis to build the new expression.
1498 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001499 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 MultiExprArg ArrayExprs,
1501 SourceLocation EqualOrColonLoc,
1502 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001503 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001504 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001506 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001508 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001509
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 ArrayExprs.release();
1511 return move(Result);
1512 }
Mike Stump11289f42009-09-09 15:08:12 +00001513
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001515 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// By default, builds the implicit value initialization without performing
1517 /// any semantic analysis. Subclasses may override this routine to provide
1518 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001519 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1521 }
Mike Stump11289f42009-09-09 15:08:12 +00001522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001524 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001527 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001529 SourceLocation RParenLoc) {
1530 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001531 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001532 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 }
1534
1535 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001536 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// By default, performs semantic analysis to build the new expression.
1538 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001539 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 MultiExprArg SubExprs,
1541 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001542 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001543 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 }
Mike Stump11289f42009-09-09 15:08:12 +00001545
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001547 ///
1548 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// rather than attempting to map the label statement itself.
1550 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001551 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 SourceLocation LabelLoc,
1553 LabelStmt *Label) {
1554 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1555 }
Mike Stump11289f42009-09-09 15:08:12 +00001556
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001558 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001561 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001562 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001564 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new __builtin_choose_expr expression.
1568 ///
1569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001572 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 SourceLocation RParenLoc) {
1574 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001575 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 RParenLoc);
1577 }
Mike Stump11289f42009-09-09 15:08:12 +00001578
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 /// \brief Build a new overloaded operator call expression.
1580 ///
1581 /// By default, performs semantic analysis to build the new expression.
1582 /// The semantic analysis provides the behavior of template instantiation,
1583 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001584 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// argument-dependent lookup, etc. Subclasses may override this routine to
1586 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001587 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001589 Expr *Callee,
1590 Expr *First,
1591 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001592
1593 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// reinterpret_cast.
1595 ///
1596 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001597 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001599 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 Stmt::StmtClass Class,
1601 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001602 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation RAngleLoc,
1604 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001605 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 SourceLocation RParenLoc) {
1607 switch (Class) {
1608 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001609 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001610 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001611 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001612
1613 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001614 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001615 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001616 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001617
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001619 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001620 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001621 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001625 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001626 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001627 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001628
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 default:
1630 assert(false && "Invalid C++ named cast");
1631 break;
1632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
John McCallfaf5fb42010-08-26 23:41:50 +00001634 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 }
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 /// \brief Build a new C++ static_cast expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001641 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001643 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 SourceLocation RAngleLoc,
1645 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001646 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001648 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001649 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001650 SourceRange(LAngleLoc, RAngleLoc),
1651 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 }
1653
1654 /// \brief Build a new C++ dynamic_cast expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001658 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001660 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 SourceLocation RAngleLoc,
1662 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001663 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001665 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001666 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001667 SourceRange(LAngleLoc, RAngleLoc),
1668 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new C++ reinterpret_cast expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001675 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001677 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceLocation RAngleLoc,
1679 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001680 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001682 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001683 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001684 SourceRange(LAngleLoc, RAngleLoc),
1685 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new C++ const_cast expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001692 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001694 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 SourceLocation RAngleLoc,
1696 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001697 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001699 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001700 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001701 SourceRange(LAngleLoc, RAngleLoc),
1702 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 }
Mike Stump11289f42009-09-09 15:08:12 +00001704
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 /// \brief Build a new C++ functional-style cast expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001709 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1710 SourceLocation LParenLoc,
1711 Expr *Sub,
1712 SourceLocation RParenLoc) {
1713 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001714 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 RParenLoc);
1716 }
Mike Stump11289f42009-09-09 15:08:12 +00001717
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 /// \brief Build a new C++ typeid(type) expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001722 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001723 SourceLocation TypeidLoc,
1724 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001726 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001727 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 }
Mike Stump11289f42009-09-09 15:08:12 +00001729
Francois Pichet9f4f2072010-09-08 12:20:18 +00001730
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 /// \brief Build a new C++ typeid(expr) expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001735 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001736 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001737 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001739 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001740 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001741 }
1742
Francois Pichet9f4f2072010-09-08 12:20:18 +00001743 /// \brief Build a new C++ __uuidof(type) expression.
1744 ///
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
1747 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1748 SourceLocation TypeidLoc,
1749 TypeSourceInfo *Operand,
1750 SourceLocation RParenLoc) {
1751 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1752 RParenLoc);
1753 }
1754
1755 /// \brief Build a new C++ __uuidof(expr) expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
1759 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1760 SourceLocation TypeidLoc,
1761 Expr *Operand,
1762 SourceLocation RParenLoc) {
1763 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1764 RParenLoc);
1765 }
1766
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// \brief Build a new C++ "this" expression.
1768 ///
1769 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001770 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001772 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001773 QualType ThisType,
1774 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001776 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1777 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 }
1779
1780 /// \brief Build a new C++ throw expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001784 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001785 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
1788 /// \brief Build a new C++ default-argument expression.
1789 ///
1790 /// By default, builds a new default-argument expression, which does not
1791 /// require any semantic analysis. Subclasses may override this routine to
1792 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001794 ParmVarDecl *Param) {
1795 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1796 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
1798
1799 /// \brief Build a new C++ zero-initialization expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001803 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1804 SourceLocation LParenLoc,
1805 SourceLocation RParenLoc) {
1806 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001807 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001808 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 }
Mike Stump11289f42009-09-09 15:08:12 +00001810
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 /// \brief Build a new C++ "new" expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001816 bool UseGlobal,
1817 SourceLocation PlacementLParen,
1818 MultiExprArg PlacementArgs,
1819 SourceLocation PlacementRParen,
1820 SourceRange TypeIdParens,
1821 QualType AllocatedType,
1822 TypeSourceInfo *AllocatedTypeInfo,
1823 Expr *ArraySize,
1824 SourceLocation ConstructorLParen,
1825 MultiExprArg ConstructorArgs,
1826 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001827 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 PlacementLParen,
1829 move(PlacementArgs),
1830 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001831 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001832 AllocatedType,
1833 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001834 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 ConstructorLParen,
1836 move(ConstructorArgs),
1837 ConstructorRParen);
1838 }
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// \brief Build a new C++ "delete" expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001844 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 bool IsGlobalDelete,
1846 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001847 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001849 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 }
Mike Stump11289f42009-09-09 15:08:12 +00001851
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 /// \brief Build a new unary type trait expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001856 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001857 SourceLocation StartLoc,
1858 TypeSourceInfo *T,
1859 SourceLocation RParenLoc) {
1860 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001861 }
1862
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001863 /// \brief Build a new binary type trait expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
1867 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1868 SourceLocation StartLoc,
1869 TypeSourceInfo *LhsT,
1870 TypeSourceInfo *RhsT,
1871 SourceLocation RParenLoc) {
1872 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1873 }
1874
Mike Stump11289f42009-09-09 15:08:12 +00001875 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// expression.
1877 ///
1878 /// By default, performs semantic analysis to build the new expression.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001882 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001883 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 CXXScopeSpec SS;
1885 SS.setRange(QualifierRange);
1886 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001887
1888 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001889 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001890 *TemplateArgs);
1891
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001892 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new template-id expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001900 LookupResult &R,
1901 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001902 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001903 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new object-construction expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001910 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001911 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 CXXConstructorDecl *Constructor,
1913 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001914 MultiExprArg Args,
1915 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001916 CXXConstructExpr::ConstructionKind ConstructKind,
1917 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001918 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001919 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001920 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001921 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001922
Douglas Gregordb121ba2009-12-14 16:27:04 +00001923 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001924 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001925 RequiresZeroInit, ConstructKind,
1926 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 }
1928
1929 /// \brief Build a new object-construction expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001933 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1934 SourceLocation LParenLoc,
1935 MultiExprArg Args,
1936 SourceLocation RParenLoc) {
1937 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 LParenLoc,
1939 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 RParenLoc);
1941 }
1942
1943 /// \brief Build a new object-construction expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001947 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1948 SourceLocation LParenLoc,
1949 MultiExprArg Args,
1950 SourceLocation RParenLoc) {
1951 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 LParenLoc,
1953 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 RParenLoc);
1955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 /// \brief Build a new member reference expression.
1958 ///
1959 /// By default, performs semantic analysis to build the new expression.
1960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001961 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001962 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 bool IsArrow,
1964 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001965 NestedNameSpecifier *Qualifier,
1966 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001967 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001968 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001969 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001970 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001971 SS.setRange(QualifierRange);
1972 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001973
John McCallb268a282010-08-23 23:25:46 +00001974 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001975 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001976 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001977 MemberNameInfo,
1978 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 }
1980
John McCall10eae182009-11-30 22:42:35 +00001981 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001985 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001986 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001987 SourceLocation OperatorLoc,
1988 bool IsArrow,
1989 NestedNameSpecifier *Qualifier,
1990 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001991 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001992 LookupResult &R,
1993 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001994 CXXScopeSpec SS;
1995 SS.setRange(QualifierRange);
1996 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001997
John McCallb268a282010-08-23 23:25:46 +00001998 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001999 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002000 SS, FirstQualifierInScope,
2001 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002002 }
Mike Stump11289f42009-09-09 15:08:12 +00002003
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002004 /// \brief Build a new noexcept expression.
2005 ///
2006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
2008 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2009 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2010 }
2011
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002012 /// \brief Build a new expression to compute the length of a parameter pack.
2013 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2014 SourceLocation PackLoc,
2015 SourceLocation RParenLoc,
2016 unsigned Length) {
2017 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2018 OperatorLoc, Pack, PackLoc,
2019 RParenLoc, Length);
2020 }
2021
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 /// \brief Build a new Objective-C @encode expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002026 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002027 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002029 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002031 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002032
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002033 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002035 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002036 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002037 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002038 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002039 MultiExprArg Args,
2040 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002041 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2042 ReceiverTypeInfo->getType(),
2043 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002044 Sel, Method, LBracLoc, SelectorLoc,
2045 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 }
2047
2048 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002049 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002050 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002051 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002052 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002053 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002054 MultiExprArg Args,
2055 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002056 return SemaRef.BuildInstanceMessage(Receiver,
2057 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002058 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002059 Sel, Method, LBracLoc, SelectorLoc,
2060 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002061 }
2062
Douglas Gregord51d90d2010-04-26 20:11:03 +00002063 /// \brief Build a new Objective-C ivar reference expression.
2064 ///
2065 /// By default, performs semantic analysis to build the new expression.
2066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002067 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002068 SourceLocation IvarLoc,
2069 bool IsArrow, bool IsFreeIvar) {
2070 // FIXME: We lose track of the IsFreeIvar bit.
2071 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002072 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002073 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2074 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002075 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002076 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002077 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002078 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002079 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002080 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002081
Douglas Gregord51d90d2010-04-26 20:11:03 +00002082 if (Result.get())
2083 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002084
John McCallb268a282010-08-23 23:25:46 +00002085 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002086 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002087 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002088 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002089 /*TemplateArgs=*/0);
2090 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002091
2092 /// \brief Build a new Objective-C property reference expression.
2093 ///
2094 /// By default, performs semantic analysis to build the new expression.
2095 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002096 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002097 ObjCPropertyDecl *Property,
2098 SourceLocation PropertyLoc) {
2099 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002100 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002101 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2102 Sema::LookupMemberName);
2103 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002104 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002105 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002106 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002107 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002108 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002109
Douglas Gregor9faee212010-04-26 20:47:02 +00002110 if (Result.get())
2111 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002112
John McCallb268a282010-08-23 23:25:46 +00002113 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002114 /*FIXME:*/PropertyLoc, IsArrow,
2115 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002116 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002117 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002118 /*TemplateArgs=*/0);
2119 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002120
John McCallb7bd14f2010-12-02 01:19:52 +00002121 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002122 ///
2123 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002124 /// Subclasses may override this routine to provide different behavior.
2125 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2126 ObjCMethodDecl *Getter,
2127 ObjCMethodDecl *Setter,
2128 SourceLocation PropertyLoc) {
2129 // Since these expressions can only be value-dependent, we do not
2130 // need to perform semantic analysis again.
2131 return Owned(
2132 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2133 VK_LValue, OK_ObjCProperty,
2134 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002135 }
2136
Douglas Gregord51d90d2010-04-26 20:11:03 +00002137 /// \brief Build a new Objective-C "isa" expression.
2138 ///
2139 /// By default, performs semantic analysis to build the new expression.
2140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002141 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002142 bool IsArrow) {
2143 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002144 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002145 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2146 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002147 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002148 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002149 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002150 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002151 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002152
Douglas Gregord51d90d2010-04-26 20:11:03 +00002153 if (Result.get())
2154 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155
John McCallb268a282010-08-23 23:25:46 +00002156 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002157 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002158 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002159 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002160 /*TemplateArgs=*/0);
2161 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new shuffle vector expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002167 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002168 MultiExprArg SubExprs,
2169 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002171 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2173 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2174 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2175 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 // Build a reference to the __builtin_shufflevector builtin
2178 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002179 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002181 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002183
2184 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 unsigned NumSubExprs = SubExprs.size();
2186 Expr **Subs = (Expr **)SubExprs.release();
2187 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2188 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002189 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002190 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002195 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002198
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002200 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 }
John McCall31f82722010-11-12 08:19:04 +00002202
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002203 /// \brief Build a new template argument pack expansion.
2204 ///
2205 /// By default, performs semantic analysis to build a new pack expansion
2206 /// for a template argument. Subclasses may override this routine to provide
2207 /// different behavior.
2208 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002209 SourceLocation EllipsisLoc,
2210 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002211 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002212 case TemplateArgument::Expression: {
2213 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002214 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2215 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002216 if (Result.isInvalid())
2217 return TemplateArgumentLoc();
2218
2219 return TemplateArgumentLoc(Result.get(), Result.get());
2220 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002221
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002222 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002223 return TemplateArgumentLoc(TemplateArgument(
2224 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002225 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002226 Pattern.getTemplateQualifierRange(),
2227 Pattern.getTemplateNameLoc(),
2228 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002229
2230 case TemplateArgument::Null:
2231 case TemplateArgument::Integral:
2232 case TemplateArgument::Declaration:
2233 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002234 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002235 llvm_unreachable("Pack expansion pattern has no parameter packs");
2236
2237 case TemplateArgument::Type:
2238 if (TypeSourceInfo *Expansion
2239 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002240 EllipsisLoc,
2241 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002242 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2243 Expansion);
2244 break;
2245 }
2246
2247 return TemplateArgumentLoc();
2248 }
2249
Douglas Gregor968f23a2011-01-03 19:31:53 +00002250 /// \brief Build a new expression pack expansion.
2251 ///
2252 /// By default, performs semantic analysis to build a new pack expansion
2253 /// for an expression. Subclasses may override this routine to provide
2254 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002255 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2256 llvm::Optional<unsigned> NumExpansions) {
2257 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002258 }
2259
John McCall31f82722010-11-12 08:19:04 +00002260private:
2261 QualType TransformTypeInObjectScope(QualType T,
2262 QualType ObjectType,
2263 NamedDecl *FirstQualifierInScope,
2264 NestedNameSpecifier *Prefix);
2265
2266 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2267 QualType ObjectType,
2268 NamedDecl *FirstQualifierInScope,
2269 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002270};
Douglas Gregora16548e2009-08-11 05:31:07 +00002271
Douglas Gregorebe10102009-08-20 07:17:43 +00002272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002273StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002274 if (!S)
2275 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002276
Douglas Gregorebe10102009-08-20 07:17:43 +00002277 switch (S->getStmtClass()) {
2278 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregorebe10102009-08-20 07:17:43 +00002280 // Transform individual statement nodes
2281#define STMT(Node, Parent) \
2282 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002283#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002284#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002285#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002286
Douglas Gregorebe10102009-08-20 07:17:43 +00002287 // Transform expressions by calling TransformExpr.
2288#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002289#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002290#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002291#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002292 {
John McCalldadc5752010-08-24 06:29:42 +00002293 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002294 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002295 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002296
John McCallb268a282010-08-23 23:25:46 +00002297 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002298 }
Mike Stump11289f42009-09-09 15:08:12 +00002299 }
2300
John McCallc3007a22010-10-26 07:05:15 +00002301 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002302}
Mike Stump11289f42009-09-09 15:08:12 +00002303
2304
Douglas Gregore922c772009-08-04 22:27:00 +00002305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002306ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 if (!E)
2308 return SemaRef.Owned(E);
2309
2310 switch (E->getStmtClass()) {
2311 case Stmt::NoStmtClass: break;
2312#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002313#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002314#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002315 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002316#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002317 }
2318
John McCallc3007a22010-10-26 07:05:15 +00002319 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002320}
2321
2322template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002323bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2324 unsigned NumInputs,
2325 bool IsCall,
2326 llvm::SmallVectorImpl<Expr *> &Outputs,
2327 bool *ArgChanged) {
2328 for (unsigned I = 0; I != NumInputs; ++I) {
2329 // If requested, drop call arguments that need to be dropped.
2330 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2331 if (ArgChanged)
2332 *ArgChanged = true;
2333
2334 break;
2335 }
2336
Douglas Gregor968f23a2011-01-03 19:31:53 +00002337 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2338 Expr *Pattern = Expansion->getPattern();
2339
2340 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2341 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2342 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2343
2344 // Determine whether the set of unexpanded parameter packs can and should
2345 // be expanded.
2346 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002347 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002348 llvm::Optional<unsigned> OrigNumExpansions
2349 = Expansion->getNumExpansions();
2350 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002351 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2352 Pattern->getSourceRange(),
2353 Unexpanded.data(),
2354 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002355 Expand, RetainExpansion,
2356 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002357 return true;
2358
2359 if (!Expand) {
2360 // The transform has determined that we should perform a simple
2361 // transformation on the pack expansion, producing another pack
2362 // expansion.
2363 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2364 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2365 if (OutPattern.isInvalid())
2366 return true;
2367
2368 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002369 Expansion->getEllipsisLoc(),
2370 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002371 if (Out.isInvalid())
2372 return true;
2373
2374 if (ArgChanged)
2375 *ArgChanged = true;
2376 Outputs.push_back(Out.get());
2377 continue;
2378 }
2379
2380 // The transform has determined that we should perform an elementwise
2381 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002382 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002383 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2384 ExprResult Out = getDerived().TransformExpr(Pattern);
2385 if (Out.isInvalid())
2386 return true;
2387
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002388 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002389 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2390 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002391 if (Out.isInvalid())
2392 return true;
2393 }
2394
Douglas Gregor968f23a2011-01-03 19:31:53 +00002395 if (ArgChanged)
2396 *ArgChanged = true;
2397 Outputs.push_back(Out.get());
2398 }
2399
2400 continue;
2401 }
2402
Douglas Gregora3efea12011-01-03 19:04:46 +00002403 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2404 if (Result.isInvalid())
2405 return true;
2406
2407 if (Result.get() != Inputs[I] && ArgChanged)
2408 *ArgChanged = true;
2409
2410 Outputs.push_back(Result.get());
2411 }
2412
2413 return false;
2414}
2415
2416template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002417NestedNameSpecifier *
2418TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002419 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002420 QualType ObjectType,
2421 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002422 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002423
Douglas Gregorebe10102009-08-20 07:17:43 +00002424 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002425 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002426 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002427 ObjectType,
2428 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002429 if (!Prefix)
2430 return 0;
2431 }
Mike Stump11289f42009-09-09 15:08:12 +00002432
Douglas Gregor1135c352009-08-06 05:28:30 +00002433 switch (NNS->getKind()) {
2434 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002435 if (Prefix) {
2436 // The object type and qualifier-in-scope really apply to the
2437 // leftmost entity.
2438 ObjectType = QualType();
2439 FirstQualifierInScope = 0;
2440 }
2441
Mike Stump11289f42009-09-09 15:08:12 +00002442 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002443 "Identifier nested-name-specifier with no prefix or object type");
2444 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2445 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002446 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002447
2448 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002449 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002450 ObjectType,
2451 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002452
Douglas Gregor1135c352009-08-06 05:28:30 +00002453 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002454 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002455 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002456 getDerived().TransformDecl(Range.getBegin(),
2457 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002458 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002459 Prefix == NNS->getPrefix() &&
2460 NS == NNS->getAsNamespace())
2461 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002462
Douglas Gregor1135c352009-08-06 05:28:30 +00002463 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2464 }
Mike Stump11289f42009-09-09 15:08:12 +00002465
Douglas Gregor1135c352009-08-06 05:28:30 +00002466 case NestedNameSpecifier::Global:
2467 // There is no meaningful transformation that one could perform on the
2468 // global scope.
2469 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002470
Douglas Gregor1135c352009-08-06 05:28:30 +00002471 case NestedNameSpecifier::TypeSpecWithTemplate:
2472 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002473 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002474 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2475 ObjectType,
2476 FirstQualifierInScope,
2477 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002478 if (T.isNull())
2479 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregor1135c352009-08-06 05:28:30 +00002481 if (!getDerived().AlwaysRebuild() &&
2482 Prefix == NNS->getPrefix() &&
2483 T == QualType(NNS->getAsType(), 0))
2484 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002485
2486 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2487 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002488 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002489 }
2490 }
Mike Stump11289f42009-09-09 15:08:12 +00002491
Douglas Gregor1135c352009-08-06 05:28:30 +00002492 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002493 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002494}
2495
2496template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002497DeclarationNameInfo
2498TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002499::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002500 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002501 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002502 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002503
2504 switch (Name.getNameKind()) {
2505 case DeclarationName::Identifier:
2506 case DeclarationName::ObjCZeroArgSelector:
2507 case DeclarationName::ObjCOneArgSelector:
2508 case DeclarationName::ObjCMultiArgSelector:
2509 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002510 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002511 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002512 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002513
Douglas Gregorf816bd72009-09-03 22:13:48 +00002514 case DeclarationName::CXXConstructorName:
2515 case DeclarationName::CXXDestructorName:
2516 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002517 TypeSourceInfo *NewTInfo;
2518 CanQualType NewCanTy;
2519 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002520 NewTInfo = getDerived().TransformType(OldTInfo);
2521 if (!NewTInfo)
2522 return DeclarationNameInfo();
2523 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002524 }
2525 else {
2526 NewTInfo = 0;
2527 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002528 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002529 if (NewT.isNull())
2530 return DeclarationNameInfo();
2531 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2532 }
Mike Stump11289f42009-09-09 15:08:12 +00002533
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002534 DeclarationName NewName
2535 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2536 NewCanTy);
2537 DeclarationNameInfo NewNameInfo(NameInfo);
2538 NewNameInfo.setName(NewName);
2539 NewNameInfo.setNamedTypeInfo(NewTInfo);
2540 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002541 }
Mike Stump11289f42009-09-09 15:08:12 +00002542 }
2543
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002544 assert(0 && "Unknown name kind.");
2545 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002546}
2547
2548template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002549TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002550TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002551 QualType ObjectType,
2552 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002553 SourceLocation Loc = getDerived().getBaseLocation();
2554
Douglas Gregor71dc5092009-08-06 06:41:21 +00002555 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002556 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002557 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002558 /*FIXME*/ SourceRange(Loc),
2559 ObjectType,
2560 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002561 if (!NNS)
2562 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregor71dc5092009-08-06 06:41:21 +00002564 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002565 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002566 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002567 if (!TransTemplate)
2568 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002569
Douglas Gregor71dc5092009-08-06 06:41:21 +00002570 if (!getDerived().AlwaysRebuild() &&
2571 NNS == QTN->getQualifier() &&
2572 TransTemplate == Template)
2573 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002574
Douglas Gregor71dc5092009-08-06 06:41:21 +00002575 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2576 TransTemplate);
2577 }
Mike Stump11289f42009-09-09 15:08:12 +00002578
John McCalle66edc12009-11-24 19:00:30 +00002579 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002580 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002581 }
Mike Stump11289f42009-09-09 15:08:12 +00002582
Douglas Gregor71dc5092009-08-06 06:41:21 +00002583 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002584 NestedNameSpecifier *NNS = DTN->getQualifier();
2585 if (NNS) {
2586 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2587 /*FIXME:*/SourceRange(Loc),
2588 ObjectType,
2589 FirstQualifierInScope);
2590 if (!NNS) return TemplateName();
2591
2592 // These apply to the scope specifier, not the template.
2593 ObjectType = QualType();
2594 FirstQualifierInScope = 0;
2595 }
Mike Stump11289f42009-09-09 15:08:12 +00002596
Douglas Gregor71dc5092009-08-06 06:41:21 +00002597 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002598 NNS == DTN->getQualifier() &&
2599 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002600 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002601
Douglas Gregora5614c52010-09-08 23:56:00 +00002602 if (DTN->isIdentifier()) {
2603 // FIXME: Bad range
2604 SourceRange QualifierRange(getDerived().getBaseLocation());
2605 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2606 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002607 ObjectType,
2608 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002609 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002610
2611 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002612 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002613 }
Mike Stump11289f42009-09-09 15:08:12 +00002614
Douglas Gregor71dc5092009-08-06 06:41:21 +00002615 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002616 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002617 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002618 if (!TransTemplate)
2619 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002620
Douglas Gregor71dc5092009-08-06 06:41:21 +00002621 if (!getDerived().AlwaysRebuild() &&
2622 TransTemplate == Template)
2623 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002624
Douglas Gregor71dc5092009-08-06 06:41:21 +00002625 return TemplateName(TransTemplate);
2626 }
Mike Stump11289f42009-09-09 15:08:12 +00002627
Douglas Gregor5590be02011-01-15 06:45:20 +00002628 if (SubstTemplateTemplateParmPackStorage *SubstPack
2629 = Name.getAsSubstTemplateTemplateParmPack()) {
2630 TemplateTemplateParmDecl *TransParam
2631 = cast_or_null<TemplateTemplateParmDecl>(
2632 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2633 if (!TransParam)
2634 return TemplateName();
2635
2636 if (!getDerived().AlwaysRebuild() &&
2637 TransParam == SubstPack->getParameterPack())
2638 return Name;
2639
2640 return getDerived().RebuildTemplateName(TransParam,
2641 SubstPack->getArgumentPack());
2642 }
2643
John McCalle66edc12009-11-24 19:00:30 +00002644 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002645 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002646 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002647}
2648
2649template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002650void TreeTransform<Derived>::InventTemplateArgumentLoc(
2651 const TemplateArgument &Arg,
2652 TemplateArgumentLoc &Output) {
2653 SourceLocation Loc = getDerived().getBaseLocation();
2654 switch (Arg.getKind()) {
2655 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002656 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002657 break;
2658
2659 case TemplateArgument::Type:
2660 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002661 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002662
John McCall0ad16662009-10-29 08:12:44 +00002663 break;
2664
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002665 case TemplateArgument::Template:
2666 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2667 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002668
2669 case TemplateArgument::TemplateExpansion:
2670 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2671 break;
2672
John McCall0ad16662009-10-29 08:12:44 +00002673 case TemplateArgument::Expression:
2674 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2675 break;
2676
2677 case TemplateArgument::Declaration:
2678 case TemplateArgument::Integral:
2679 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002680 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002681 break;
2682 }
2683}
2684
2685template<typename Derived>
2686bool TreeTransform<Derived>::TransformTemplateArgument(
2687 const TemplateArgumentLoc &Input,
2688 TemplateArgumentLoc &Output) {
2689 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002690 switch (Arg.getKind()) {
2691 case TemplateArgument::Null:
2692 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002693 Output = Input;
2694 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002695
Douglas Gregore922c772009-08-04 22:27:00 +00002696 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002697 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002698 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002699 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002700
2701 DI = getDerived().TransformType(DI);
2702 if (!DI) return true;
2703
2704 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2705 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707
Douglas Gregore922c772009-08-04 22:27:00 +00002708 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002709 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002710 DeclarationName Name;
2711 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2712 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002713 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002714 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002715 if (!D) return true;
2716
John McCall0d07eb32009-10-29 18:45:58 +00002717 Expr *SourceExpr = Input.getSourceDeclExpression();
2718 if (SourceExpr) {
2719 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002720 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002721 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002722 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002723 }
2724
2725 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002726 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002727 }
Mike Stump11289f42009-09-09 15:08:12 +00002728
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002729 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002730 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002731 TemplateName Template
2732 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2733 if (Template.isNull())
2734 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002735
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002736 Output = TemplateArgumentLoc(TemplateArgument(Template),
2737 Input.getTemplateQualifierRange(),
2738 Input.getTemplateNameLoc());
2739 return false;
2740 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002741
2742 case TemplateArgument::TemplateExpansion:
2743 llvm_unreachable("Caller should expand pack expansions");
2744
Douglas Gregore922c772009-08-04 22:27:00 +00002745 case TemplateArgument::Expression: {
2746 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002747 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002748 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002749
John McCall0ad16662009-10-29 08:12:44 +00002750 Expr *InputExpr = Input.getSourceExpression();
2751 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2752
John McCalldadc5752010-08-24 06:29:42 +00002753 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002754 = getDerived().TransformExpr(InputExpr);
2755 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002756 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002757 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002758 }
Mike Stump11289f42009-09-09 15:08:12 +00002759
Douglas Gregore922c772009-08-04 22:27:00 +00002760 case TemplateArgument::Pack: {
2761 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2762 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002763 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002764 AEnd = Arg.pack_end();
2765 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002766
John McCall0ad16662009-10-29 08:12:44 +00002767 // FIXME: preserve source information here when we start
2768 // caring about parameter packs.
2769
John McCall0d07eb32009-10-29 18:45:58 +00002770 TemplateArgumentLoc InputArg;
2771 TemplateArgumentLoc OutputArg;
2772 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2773 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002774 return true;
2775
John McCall0d07eb32009-10-29 18:45:58 +00002776 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002777 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002778
2779 TemplateArgument *TransformedArgsPtr
2780 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2781 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2782 TransformedArgsPtr);
2783 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2784 TransformedArgs.size()),
2785 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002786 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002787 }
2788 }
Mike Stump11289f42009-09-09 15:08:12 +00002789
Douglas Gregore922c772009-08-04 22:27:00 +00002790 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002791 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002792}
2793
Douglas Gregorfe921a72010-12-20 23:36:19 +00002794/// \brief Iterator adaptor that invents template argument location information
2795/// for each of the template arguments in its underlying iterator.
2796template<typename Derived, typename InputIterator>
2797class TemplateArgumentLocInventIterator {
2798 TreeTransform<Derived> &Self;
2799 InputIterator Iter;
2800
2801public:
2802 typedef TemplateArgumentLoc value_type;
2803 typedef TemplateArgumentLoc reference;
2804 typedef typename std::iterator_traits<InputIterator>::difference_type
2805 difference_type;
2806 typedef std::input_iterator_tag iterator_category;
2807
2808 class pointer {
2809 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002810
Douglas Gregorfe921a72010-12-20 23:36:19 +00002811 public:
2812 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2813
2814 const TemplateArgumentLoc *operator->() const { return &Arg; }
2815 };
2816
2817 TemplateArgumentLocInventIterator() { }
2818
2819 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2820 InputIterator Iter)
2821 : Self(Self), Iter(Iter) { }
2822
2823 TemplateArgumentLocInventIterator &operator++() {
2824 ++Iter;
2825 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002826 }
2827
Douglas Gregorfe921a72010-12-20 23:36:19 +00002828 TemplateArgumentLocInventIterator operator++(int) {
2829 TemplateArgumentLocInventIterator Old(*this);
2830 ++(*this);
2831 return Old;
2832 }
2833
2834 reference operator*() const {
2835 TemplateArgumentLoc Result;
2836 Self.InventTemplateArgumentLoc(*Iter, Result);
2837 return Result;
2838 }
2839
2840 pointer operator->() const { return pointer(**this); }
2841
2842 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2843 const TemplateArgumentLocInventIterator &Y) {
2844 return X.Iter == Y.Iter;
2845 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002846
Douglas Gregorfe921a72010-12-20 23:36:19 +00002847 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2848 const TemplateArgumentLocInventIterator &Y) {
2849 return X.Iter != Y.Iter;
2850 }
2851};
2852
Douglas Gregor42cafa82010-12-20 17:42:22 +00002853template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002854template<typename InputIterator>
2855bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2856 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002857 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002858 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002859 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002860 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002861
2862 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2863 // Unpack argument packs, which we translate them into separate
2864 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002865 // FIXME: We could do much better if we could guarantee that the
2866 // TemplateArgumentLocInfo for the pack expansion would be usable for
2867 // all of the template arguments in the argument pack.
2868 typedef TemplateArgumentLocInventIterator<Derived,
2869 TemplateArgument::pack_iterator>
2870 PackLocIterator;
2871 if (TransformTemplateArguments(PackLocIterator(*this,
2872 In.getArgument().pack_begin()),
2873 PackLocIterator(*this,
2874 In.getArgument().pack_end()),
2875 Outputs))
2876 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002877
2878 continue;
2879 }
2880
2881 if (In.getArgument().isPackExpansion()) {
2882 // We have a pack expansion, for which we will be substituting into
2883 // the pattern.
2884 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002885 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002886 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002887 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2888 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002889
2890 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2891 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2892 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2893
2894 // Determine whether the set of unexpanded parameter packs can and should
2895 // be expanded.
2896 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002897 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002898 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002899 if (getDerived().TryExpandParameterPacks(Ellipsis,
2900 Pattern.getSourceRange(),
2901 Unexpanded.data(),
2902 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002903 Expand,
2904 RetainExpansion,
2905 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002906 return true;
2907
2908 if (!Expand) {
2909 // The transform has determined that we should perform a simple
2910 // transformation on the pack expansion, producing another pack
2911 // expansion.
2912 TemplateArgumentLoc OutPattern;
2913 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2914 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2915 return true;
2916
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002917 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2918 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002919 if (Out.getArgument().isNull())
2920 return true;
2921
2922 Outputs.addArgument(Out);
2923 continue;
2924 }
2925
2926 // The transform has determined that we should perform an elementwise
2927 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002928 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002929 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2930
2931 if (getDerived().TransformTemplateArgument(Pattern, Out))
2932 return true;
2933
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002934 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002935 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2936 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002937 if (Out.getArgument().isNull())
2938 return true;
2939 }
2940
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002941 Outputs.addArgument(Out);
2942 }
2943
Douglas Gregor48d24112011-01-10 20:53:55 +00002944 // If we're supposed to retain a pack expansion, do so by temporarily
2945 // forgetting the partially-substituted parameter pack.
2946 if (RetainExpansion) {
2947 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2948
2949 if (getDerived().TransformTemplateArgument(Pattern, Out))
2950 return true;
2951
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002952 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2953 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002954 if (Out.getArgument().isNull())
2955 return true;
2956
2957 Outputs.addArgument(Out);
2958 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002959
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002960 continue;
2961 }
2962
2963 // The simple case:
2964 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002965 return true;
2966
2967 Outputs.addArgument(Out);
2968 }
2969
2970 return false;
2971
2972}
2973
Douglas Gregord6ff3322009-08-04 16:50:30 +00002974//===----------------------------------------------------------------------===//
2975// Type transformation
2976//===----------------------------------------------------------------------===//
2977
2978template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002979QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002980 if (getDerived().AlreadyTransformed(T))
2981 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002982
John McCall550e0c22009-10-21 00:40:46 +00002983 // Temporary workaround. All of these transformations should
2984 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002985 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2986 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002987
John McCall31f82722010-11-12 08:19:04 +00002988 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002989
John McCall550e0c22009-10-21 00:40:46 +00002990 if (!NewDI)
2991 return QualType();
2992
2993 return NewDI->getType();
2994}
2995
2996template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002997TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002998 if (getDerived().AlreadyTransformed(DI->getType()))
2999 return DI;
3000
3001 TypeLocBuilder TLB;
3002
3003 TypeLoc TL = DI->getTypeLoc();
3004 TLB.reserve(TL.getFullDataSize());
3005
John McCall31f82722010-11-12 08:19:04 +00003006 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003007 if (Result.isNull())
3008 return 0;
3009
John McCallbcd03502009-12-07 02:54:59 +00003010 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003011}
3012
3013template<typename Derived>
3014QualType
John McCall31f82722010-11-12 08:19:04 +00003015TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003016 switch (T.getTypeLocClass()) {
3017#define ABSTRACT_TYPELOC(CLASS, PARENT)
3018#define TYPELOC(CLASS, PARENT) \
3019 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003020 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003021#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 }
Mike Stump11289f42009-09-09 15:08:12 +00003023
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003024 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003025 return QualType();
3026}
3027
3028/// FIXME: By default, this routine adds type qualifiers only to types
3029/// that can have qualifiers, and silently suppresses those qualifiers
3030/// that are not permitted (e.g., qualifiers on reference or function
3031/// types). This is the right thing for template instantiation, but
3032/// probably not for other clients.
3033template<typename Derived>
3034QualType
3035TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003036 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003037 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003038
John McCall31f82722010-11-12 08:19:04 +00003039 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003040 if (Result.isNull())
3041 return QualType();
3042
3043 // Silently suppress qualifiers if the result type can't be qualified.
3044 // FIXME: this is the right thing for template instantiation, but
3045 // probably not for other clients.
3046 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003047 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003048
John McCallcb0f89a2010-06-05 06:41:15 +00003049 if (!Quals.empty()) {
3050 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3051 TLB.push<QualifiedTypeLoc>(Result);
3052 // No location information to preserve.
3053 }
John McCall550e0c22009-10-21 00:40:46 +00003054
3055 return Result;
3056}
3057
John McCall31f82722010-11-12 08:19:04 +00003058/// \brief Transforms a type that was written in a scope specifier,
3059/// given an object type, the results of unqualified lookup, and
3060/// an already-instantiated prefix.
3061///
3062/// The object type is provided iff the scope specifier qualifies the
3063/// member of a dependent member-access expression. The prefix is
3064/// provided iff the the scope specifier in which this appears has a
3065/// prefix.
3066///
3067/// This is private to TreeTransform.
3068template<typename Derived>
3069QualType
3070TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3071 QualType ObjectType,
3072 NamedDecl *UnqualLookup,
3073 NestedNameSpecifier *Prefix) {
3074 if (getDerived().AlreadyTransformed(T))
3075 return T;
3076
3077 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003078 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003079
3080 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3081 UnqualLookup, Prefix);
3082 if (!TSI) return QualType();
3083 return TSI->getType();
3084}
3085
3086template<typename Derived>
3087TypeSourceInfo *
3088TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3089 QualType ObjectType,
3090 NamedDecl *UnqualLookup,
3091 NestedNameSpecifier *Prefix) {
3092 // TODO: in some cases, we might be some verification to do here.
3093 if (ObjectType.isNull())
3094 return getDerived().TransformType(TSI);
3095
3096 QualType T = TSI->getType();
3097 if (getDerived().AlreadyTransformed(T))
3098 return TSI;
3099
3100 TypeLocBuilder TLB;
3101 QualType Result;
3102
3103 if (isa<TemplateSpecializationType>(T)) {
3104 TemplateSpecializationTypeLoc TL
3105 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3106
3107 TemplateName Template =
3108 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3109 ObjectType, UnqualLookup);
3110 if (Template.isNull()) return 0;
3111
3112 Result = getDerived()
3113 .TransformTemplateSpecializationType(TLB, TL, Template);
3114 } else if (isa<DependentTemplateSpecializationType>(T)) {
3115 DependentTemplateSpecializationTypeLoc TL
3116 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3117
3118 Result = getDerived()
3119 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3120 } else {
3121 // Nothing special needs to be done for these.
3122 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3123 }
3124
3125 if (Result.isNull()) return 0;
3126 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3127}
3128
John McCall550e0c22009-10-21 00:40:46 +00003129template <class TyLoc> static inline
3130QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3131 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3132 NewT.setNameLoc(T.getNameLoc());
3133 return T.getType();
3134}
3135
John McCall550e0c22009-10-21 00:40:46 +00003136template<typename Derived>
3137QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003138 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003139 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3140 NewT.setBuiltinLoc(T.getBuiltinLoc());
3141 if (T.needsExtraLocalData())
3142 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3143 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144}
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003147QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003148 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003149 // FIXME: recurse?
3150 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003151}
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregord6ff3322009-08-04 16:50:30 +00003153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003154QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003155 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003156 QualType PointeeType
3157 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003158 if (PointeeType.isNull())
3159 return QualType();
3160
3161 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003162 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003163 // A dependent pointer type 'T *' has is being transformed such
3164 // that an Objective-C class type is being replaced for 'T'. The
3165 // resulting pointer type is an ObjCObjectPointerType, not a
3166 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003167 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003168
John McCall8b07ec22010-05-15 11:32:37 +00003169 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3170 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003171 return Result;
3172 }
John McCall31f82722010-11-12 08:19:04 +00003173
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003174 if (getDerived().AlwaysRebuild() ||
3175 PointeeType != TL.getPointeeLoc().getType()) {
3176 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3177 if (Result.isNull())
3178 return QualType();
3179 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003180
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003181 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3182 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003183 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003184}
Mike Stump11289f42009-09-09 15:08:12 +00003185
3186template<typename Derived>
3187QualType
John McCall550e0c22009-10-21 00:40:46 +00003188TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003189 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003190 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003191 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3192 if (PointeeType.isNull())
3193 return QualType();
3194
3195 QualType Result = TL.getType();
3196 if (getDerived().AlwaysRebuild() ||
3197 PointeeType != TL.getPointeeLoc().getType()) {
3198 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003199 TL.getSigilLoc());
3200 if (Result.isNull())
3201 return QualType();
3202 }
3203
Douglas Gregor049211a2010-04-22 16:50:51 +00003204 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003205 NewT.setSigilLoc(TL.getSigilLoc());
3206 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003207}
3208
John McCall70dd5f62009-10-30 00:06:24 +00003209/// Transforms a reference type. Note that somewhat paradoxically we
3210/// don't care whether the type itself is an l-value type or an r-value
3211/// type; we only care if the type was *written* as an l-value type
3212/// or an r-value type.
3213template<typename Derived>
3214QualType
3215TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003216 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003217 const ReferenceType *T = TL.getTypePtr();
3218
3219 // Note that this works with the pointee-as-written.
3220 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3221 if (PointeeType.isNull())
3222 return QualType();
3223
3224 QualType Result = TL.getType();
3225 if (getDerived().AlwaysRebuild() ||
3226 PointeeType != T->getPointeeTypeAsWritten()) {
3227 Result = getDerived().RebuildReferenceType(PointeeType,
3228 T->isSpelledAsLValue(),
3229 TL.getSigilLoc());
3230 if (Result.isNull())
3231 return QualType();
3232 }
3233
3234 // r-value references can be rebuilt as l-value references.
3235 ReferenceTypeLoc NewTL;
3236 if (isa<LValueReferenceType>(Result))
3237 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3238 else
3239 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3240 NewTL.setSigilLoc(TL.getSigilLoc());
3241
3242 return Result;
3243}
3244
Mike Stump11289f42009-09-09 15:08:12 +00003245template<typename Derived>
3246QualType
John McCall550e0c22009-10-21 00:40:46 +00003247TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003248 LValueReferenceTypeLoc TL) {
3249 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003250}
3251
Mike Stump11289f42009-09-09 15:08:12 +00003252template<typename Derived>
3253QualType
John McCall550e0c22009-10-21 00:40:46 +00003254TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003255 RValueReferenceTypeLoc TL) {
3256 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003257}
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregord6ff3322009-08-04 16:50:30 +00003259template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003260QualType
John McCall550e0c22009-10-21 00:40:46 +00003261TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003262 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003263 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003264
3265 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266 if (PointeeType.isNull())
3267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003268
John McCall550e0c22009-10-21 00:40:46 +00003269 // TODO: preserve source information for this.
3270 QualType ClassType
3271 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003272 if (ClassType.isNull())
3273 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003274
John McCall550e0c22009-10-21 00:40:46 +00003275 QualType Result = TL.getType();
3276 if (getDerived().AlwaysRebuild() ||
3277 PointeeType != T->getPointeeType() ||
3278 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003279 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3280 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003281 if (Result.isNull())
3282 return QualType();
3283 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003284
John McCall550e0c22009-10-21 00:40:46 +00003285 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3286 NewTL.setSigilLoc(TL.getSigilLoc());
3287
3288 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003289}
3290
Mike Stump11289f42009-09-09 15:08:12 +00003291template<typename Derived>
3292QualType
John McCall550e0c22009-10-21 00:40:46 +00003293TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003294 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003295 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003296 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003297 if (ElementType.isNull())
3298 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003299
John McCall550e0c22009-10-21 00:40:46 +00003300 QualType Result = TL.getType();
3301 if (getDerived().AlwaysRebuild() ||
3302 ElementType != T->getElementType()) {
3303 Result = getDerived().RebuildConstantArrayType(ElementType,
3304 T->getSizeModifier(),
3305 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003306 T->getIndexTypeCVRQualifiers(),
3307 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003308 if (Result.isNull())
3309 return QualType();
3310 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3313 NewTL.setLBracketLoc(TL.getLBracketLoc());
3314 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003315
John McCall550e0c22009-10-21 00:40:46 +00003316 Expr *Size = TL.getSizeExpr();
3317 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003318 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003319 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3320 }
3321 NewTL.setSizeExpr(Size);
3322
3323 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324}
Mike Stump11289f42009-09-09 15:08:12 +00003325
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003327QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003328 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003329 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003330 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003331 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332 if (ElementType.isNull())
3333 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003334
John McCall550e0c22009-10-21 00:40:46 +00003335 QualType Result = TL.getType();
3336 if (getDerived().AlwaysRebuild() ||
3337 ElementType != T->getElementType()) {
3338 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003339 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003340 T->getIndexTypeCVRQualifiers(),
3341 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003342 if (Result.isNull())
3343 return QualType();
3344 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003345
John McCall550e0c22009-10-21 00:40:46 +00003346 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3347 NewTL.setLBracketLoc(TL.getLBracketLoc());
3348 NewTL.setRBracketLoc(TL.getRBracketLoc());
3349 NewTL.setSizeExpr(0);
3350
3351 return Result;
3352}
3353
3354template<typename Derived>
3355QualType
3356TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003357 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003358 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003359 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3360 if (ElementType.isNull())
3361 return QualType();
3362
3363 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003364 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003365
John McCalldadc5752010-08-24 06:29:42 +00003366 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003367 = getDerived().TransformExpr(T->getSizeExpr());
3368 if (SizeResult.isInvalid())
3369 return QualType();
3370
John McCallb268a282010-08-23 23:25:46 +00003371 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003372
3373 QualType Result = TL.getType();
3374 if (getDerived().AlwaysRebuild() ||
3375 ElementType != T->getElementType() ||
3376 Size != T->getSizeExpr()) {
3377 Result = getDerived().RebuildVariableArrayType(ElementType,
3378 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003379 Size,
John McCall550e0c22009-10-21 00:40:46 +00003380 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003381 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003382 if (Result.isNull())
3383 return QualType();
3384 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003385
John McCall550e0c22009-10-21 00:40:46 +00003386 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3387 NewTL.setLBracketLoc(TL.getLBracketLoc());
3388 NewTL.setRBracketLoc(TL.getRBracketLoc());
3389 NewTL.setSizeExpr(Size);
3390
3391 return Result;
3392}
3393
3394template<typename Derived>
3395QualType
3396TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003397 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003398 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003399 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3400 if (ElementType.isNull())
3401 return QualType();
3402
3403 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003404 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003405
John McCall33ddac02011-01-19 10:06:00 +00003406 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3407 Expr *origSize = TL.getSizeExpr();
3408 if (!origSize) origSize = T->getSizeExpr();
3409
3410 ExprResult sizeResult
3411 = getDerived().TransformExpr(origSize);
3412 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003413 return QualType();
3414
John McCall33ddac02011-01-19 10:06:00 +00003415 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003416
3417 QualType Result = TL.getType();
3418 if (getDerived().AlwaysRebuild() ||
3419 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003420 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003421 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3422 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003423 size,
John McCall550e0c22009-10-21 00:40:46 +00003424 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003425 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003426 if (Result.isNull())
3427 return QualType();
3428 }
John McCall550e0c22009-10-21 00:40:46 +00003429
3430 // We might have any sort of array type now, but fortunately they
3431 // all have the same location layout.
3432 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3433 NewTL.setLBracketLoc(TL.getLBracketLoc());
3434 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003435 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003436
3437 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003438}
Mike Stump11289f42009-09-09 15:08:12 +00003439
3440template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003441QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003442 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003443 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003444 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003445
3446 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003447 QualType ElementType = getDerived().TransformType(T->getElementType());
3448 if (ElementType.isNull())
3449 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003450
Douglas Gregore922c772009-08-04 22:27:00 +00003451 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003452 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003453
John McCalldadc5752010-08-24 06:29:42 +00003454 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003455 if (Size.isInvalid())
3456 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003457
John McCall550e0c22009-10-21 00:40:46 +00003458 QualType Result = TL.getType();
3459 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003460 ElementType != T->getElementType() ||
3461 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003462 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003463 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003464 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003465 if (Result.isNull())
3466 return QualType();
3467 }
John McCall550e0c22009-10-21 00:40:46 +00003468
3469 // Result might be dependent or not.
3470 if (isa<DependentSizedExtVectorType>(Result)) {
3471 DependentSizedExtVectorTypeLoc NewTL
3472 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3473 NewTL.setNameLoc(TL.getNameLoc());
3474 } else {
3475 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3476 NewTL.setNameLoc(TL.getNameLoc());
3477 }
3478
3479 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003480}
Mike Stump11289f42009-09-09 15:08:12 +00003481
3482template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003483QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003484 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003485 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486 QualType ElementType = getDerived().TransformType(T->getElementType());
3487 if (ElementType.isNull())
3488 return QualType();
3489
John McCall550e0c22009-10-21 00:40:46 +00003490 QualType Result = TL.getType();
3491 if (getDerived().AlwaysRebuild() ||
3492 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003493 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003494 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003495 if (Result.isNull())
3496 return QualType();
3497 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003498
John McCall550e0c22009-10-21 00:40:46 +00003499 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3500 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003501
John McCall550e0c22009-10-21 00:40:46 +00003502 return Result;
3503}
3504
3505template<typename Derived>
3506QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003507 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003508 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003509 QualType ElementType = getDerived().TransformType(T->getElementType());
3510 if (ElementType.isNull())
3511 return QualType();
3512
3513 QualType Result = TL.getType();
3514 if (getDerived().AlwaysRebuild() ||
3515 ElementType != T->getElementType()) {
3516 Result = getDerived().RebuildExtVectorType(ElementType,
3517 T->getNumElements(),
3518 /*FIXME*/ SourceLocation());
3519 if (Result.isNull())
3520 return QualType();
3521 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003522
John McCall550e0c22009-10-21 00:40:46 +00003523 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3524 NewTL.setNameLoc(TL.getNameLoc());
3525
3526 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003527}
Mike Stump11289f42009-09-09 15:08:12 +00003528
3529template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003530ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003531TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3532 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003533 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003534 TypeSourceInfo *NewDI = 0;
3535
3536 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3537 // If we're substituting into a pack expansion type and we know the
3538 TypeLoc OldTL = OldDI->getTypeLoc();
3539 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3540
3541 TypeLocBuilder TLB;
3542 TypeLoc NewTL = OldDI->getTypeLoc();
3543 TLB.reserve(NewTL.getFullDataSize());
3544
3545 QualType Result = getDerived().TransformType(TLB,
3546 OldExpansionTL.getPatternLoc());
3547 if (Result.isNull())
3548 return 0;
3549
3550 Result = RebuildPackExpansionType(Result,
3551 OldExpansionTL.getPatternLoc().getSourceRange(),
3552 OldExpansionTL.getEllipsisLoc(),
3553 NumExpansions);
3554 if (Result.isNull())
3555 return 0;
3556
3557 PackExpansionTypeLoc NewExpansionTL
3558 = TLB.push<PackExpansionTypeLoc>(Result);
3559 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3560 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3561 } else
3562 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003563 if (!NewDI)
3564 return 0;
3565
3566 if (NewDI == OldDI)
3567 return OldParm;
3568 else
3569 return ParmVarDecl::Create(SemaRef.Context,
3570 OldParm->getDeclContext(),
3571 OldParm->getLocation(),
3572 OldParm->getIdentifier(),
3573 NewDI->getType(),
3574 NewDI,
3575 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003576 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003577 /* DefArg */ NULL);
3578}
3579
3580template<typename Derived>
3581bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003582 TransformFunctionTypeParams(SourceLocation Loc,
3583 ParmVarDecl **Params, unsigned NumParams,
3584 const QualType *ParamTypes,
3585 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3586 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3587 for (unsigned i = 0; i != NumParams; ++i) {
3588 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003589 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003590 if (OldParm->isParameterPack()) {
3591 // We have a function parameter pack that may need to be expanded.
3592 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003593
Douglas Gregor5499af42011-01-05 23:12:31 +00003594 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003595 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3596 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3597 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3598 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003599
3600 // Determine whether we should expand the parameter packs.
3601 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003602 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003603 llvm::Optional<unsigned> OrigNumExpansions
3604 = ExpansionTL.getTypePtr()->getNumExpansions();
3605 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003606 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3607 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003608 Unexpanded.data(),
3609 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003610 ShouldExpand,
3611 RetainExpansion,
3612 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003613 return true;
3614 }
3615
3616 if (ShouldExpand) {
3617 // Expand the function parameter pack into multiple, separate
3618 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003619 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003620 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003621 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3622 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003623 = getDerived().TransformFunctionTypeParam(OldParm,
3624 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003625 if (!NewParm)
3626 return true;
3627
Douglas Gregordd472162011-01-07 00:20:55 +00003628 OutParamTypes.push_back(NewParm->getType());
3629 if (PVars)
3630 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003631 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003632
3633 // If we're supposed to retain a pack expansion, do so by temporarily
3634 // forgetting the partially-substituted parameter pack.
3635 if (RetainExpansion) {
3636 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3637 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003638 = getDerived().TransformFunctionTypeParam(OldParm,
3639 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003640 if (!NewParm)
3641 return true;
3642
3643 OutParamTypes.push_back(NewParm->getType());
3644 if (PVars)
3645 PVars->push_back(NewParm);
3646 }
3647
Douglas Gregor5499af42011-01-05 23:12:31 +00003648 // We're done with the pack expansion.
3649 continue;
3650 }
3651
3652 // We'll substitute the parameter now without expanding the pack
3653 // expansion.
3654 }
3655
3656 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003657 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3658 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003659 if (!NewParm)
3660 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003661
Douglas Gregordd472162011-01-07 00:20:55 +00003662 OutParamTypes.push_back(NewParm->getType());
3663 if (PVars)
3664 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003665 continue;
3666 }
John McCall58f10c32010-03-11 09:03:00 +00003667
3668 // Deal with the possibility that we don't have a parameter
3669 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003670 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003671 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003672 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003673 if (const PackExpansionType *Expansion
3674 = dyn_cast<PackExpansionType>(OldType)) {
3675 // We have a function parameter pack that may need to be expanded.
3676 QualType Pattern = Expansion->getPattern();
3677 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3678 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3679
3680 // Determine whether we should expand the parameter packs.
3681 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003682 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003683 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003684 Unexpanded.data(),
3685 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003686 ShouldExpand,
3687 RetainExpansion,
3688 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003689 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003690 }
3691
3692 if (ShouldExpand) {
3693 // Expand the function parameter pack into multiple, separate
3694 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003695 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003696 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3697 QualType NewType = getDerived().TransformType(Pattern);
3698 if (NewType.isNull())
3699 return true;
John McCall58f10c32010-03-11 09:03:00 +00003700
Douglas Gregordd472162011-01-07 00:20:55 +00003701 OutParamTypes.push_back(NewType);
3702 if (PVars)
3703 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003704 }
3705
3706 // We're done with the pack expansion.
3707 continue;
3708 }
3709
Douglas Gregor48d24112011-01-10 20:53:55 +00003710 // If we're supposed to retain a pack expansion, do so by temporarily
3711 // forgetting the partially-substituted parameter pack.
3712 if (RetainExpansion) {
3713 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3714 QualType NewType = getDerived().TransformType(Pattern);
3715 if (NewType.isNull())
3716 return true;
3717
3718 OutParamTypes.push_back(NewType);
3719 if (PVars)
3720 PVars->push_back(0);
3721 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003722
Douglas Gregor5499af42011-01-05 23:12:31 +00003723 // We'll substitute the parameter now without expanding the pack
3724 // expansion.
3725 OldType = Expansion->getPattern();
3726 IsPackExpansion = true;
3727 }
3728
3729 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3730 QualType NewType = getDerived().TransformType(OldType);
3731 if (NewType.isNull())
3732 return true;
3733
3734 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003735 NewType = getSema().Context.getPackExpansionType(NewType,
3736 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003737
Douglas Gregordd472162011-01-07 00:20:55 +00003738 OutParamTypes.push_back(NewType);
3739 if (PVars)
3740 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003741 }
3742
3743 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003744 }
John McCall58f10c32010-03-11 09:03:00 +00003745
3746template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003747QualType
John McCall550e0c22009-10-21 00:40:46 +00003748TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003749 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003750 // Transform the parameters and return type.
3751 //
3752 // We instantiate in source order, with the return type first followed by
3753 // the parameters, because users tend to expect this (even if they shouldn't
3754 // rely on it!).
3755 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003756 // When the function has a trailing return type, we instantiate the
3757 // parameters before the return type, since the return type can then refer
3758 // to the parameters themselves (via decltype, sizeof, etc.).
3759 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003760 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003761 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003762 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003763
Douglas Gregor7fb25412010-10-01 18:44:50 +00003764 QualType ResultType;
3765
3766 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003767 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3768 TL.getParmArray(),
3769 TL.getNumArgs(),
3770 TL.getTypePtr()->arg_type_begin(),
3771 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003772 return QualType();
3773
3774 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3775 if (ResultType.isNull())
3776 return QualType();
3777 }
3778 else {
3779 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3780 if (ResultType.isNull())
3781 return QualType();
3782
Douglas Gregordd472162011-01-07 00:20:55 +00003783 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3784 TL.getParmArray(),
3785 TL.getNumArgs(),
3786 TL.getTypePtr()->arg_type_begin(),
3787 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003788 return QualType();
3789 }
3790
John McCall550e0c22009-10-21 00:40:46 +00003791 QualType Result = TL.getType();
3792 if (getDerived().AlwaysRebuild() ||
3793 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003794 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003795 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3796 Result = getDerived().RebuildFunctionProtoType(ResultType,
3797 ParamTypes.data(),
3798 ParamTypes.size(),
3799 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003800 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003801 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003802 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003803 if (Result.isNull())
3804 return QualType();
3805 }
Mike Stump11289f42009-09-09 15:08:12 +00003806
John McCall550e0c22009-10-21 00:40:46 +00003807 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3808 NewTL.setLParenLoc(TL.getLParenLoc());
3809 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003810 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003811 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3812 NewTL.setArg(i, ParamDecls[i]);
3813
3814 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003815}
Mike Stump11289f42009-09-09 15:08:12 +00003816
Douglas Gregord6ff3322009-08-04 16:50:30 +00003817template<typename Derived>
3818QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003819 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003820 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003821 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003822 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3823 if (ResultType.isNull())
3824 return QualType();
3825
3826 QualType Result = TL.getType();
3827 if (getDerived().AlwaysRebuild() ||
3828 ResultType != T->getResultType())
3829 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3830
3831 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3832 NewTL.setLParenLoc(TL.getLParenLoc());
3833 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003834 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003835
3836 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003837}
Mike Stump11289f42009-09-09 15:08:12 +00003838
John McCallb96ec562009-12-04 22:46:56 +00003839template<typename Derived> QualType
3840TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003841 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003842 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003843 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003844 if (!D)
3845 return QualType();
3846
3847 QualType Result = TL.getType();
3848 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3849 Result = getDerived().RebuildUnresolvedUsingType(D);
3850 if (Result.isNull())
3851 return QualType();
3852 }
3853
3854 // We might get an arbitrary type spec type back. We should at
3855 // least always get a type spec type, though.
3856 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3857 NewTL.setNameLoc(TL.getNameLoc());
3858
3859 return Result;
3860}
3861
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003863QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003864 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003865 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003866 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003867 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3868 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869 if (!Typedef)
3870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003871
John McCall550e0c22009-10-21 00:40:46 +00003872 QualType Result = TL.getType();
3873 if (getDerived().AlwaysRebuild() ||
3874 Typedef != T->getDecl()) {
3875 Result = getDerived().RebuildTypedefType(Typedef);
3876 if (Result.isNull())
3877 return QualType();
3878 }
Mike Stump11289f42009-09-09 15:08:12 +00003879
John McCall550e0c22009-10-21 00:40:46 +00003880 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3881 NewTL.setNameLoc(TL.getNameLoc());
3882
3883 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003884}
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregord6ff3322009-08-04 16:50:30 +00003886template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003887QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003888 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003889 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003890 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003891
John McCalldadc5752010-08-24 06:29:42 +00003892 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003893 if (E.isInvalid())
3894 return QualType();
3895
John McCall550e0c22009-10-21 00:40:46 +00003896 QualType Result = TL.getType();
3897 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003898 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003899 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003900 if (Result.isNull())
3901 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003902 }
John McCall550e0c22009-10-21 00:40:46 +00003903 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003904
John McCall550e0c22009-10-21 00:40:46 +00003905 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003906 NewTL.setTypeofLoc(TL.getTypeofLoc());
3907 NewTL.setLParenLoc(TL.getLParenLoc());
3908 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003909
3910 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
3913template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003914QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003915 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003916 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3917 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3918 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003919 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003920
John McCall550e0c22009-10-21 00:40:46 +00003921 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003922 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3923 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003924 if (Result.isNull())
3925 return QualType();
3926 }
Mike Stump11289f42009-09-09 15:08:12 +00003927
John McCall550e0c22009-10-21 00:40:46 +00003928 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003929 NewTL.setTypeofLoc(TL.getTypeofLoc());
3930 NewTL.setLParenLoc(TL.getLParenLoc());
3931 NewTL.setRParenLoc(TL.getRParenLoc());
3932 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003933
3934 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003935}
Mike Stump11289f42009-09-09 15:08:12 +00003936
3937template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003938QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003939 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003940 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003941
Douglas Gregore922c772009-08-04 22:27:00 +00003942 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003943 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003944
John McCalldadc5752010-08-24 06:29:42 +00003945 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003946 if (E.isInvalid())
3947 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003948
John McCall550e0c22009-10-21 00:40:46 +00003949 QualType Result = TL.getType();
3950 if (getDerived().AlwaysRebuild() ||
3951 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003952 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003953 if (Result.isNull())
3954 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955 }
John McCall550e0c22009-10-21 00:40:46 +00003956 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003957
John McCall550e0c22009-10-21 00:40:46 +00003958 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3959 NewTL.setNameLoc(TL.getNameLoc());
3960
3961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003962}
3963
3964template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003965QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003966 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003967 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003969 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3970 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003971 if (!Record)
3972 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003973
John McCall550e0c22009-10-21 00:40:46 +00003974 QualType Result = TL.getType();
3975 if (getDerived().AlwaysRebuild() ||
3976 Record != T->getDecl()) {
3977 Result = getDerived().RebuildRecordType(Record);
3978 if (Result.isNull())
3979 return QualType();
3980 }
Mike Stump11289f42009-09-09 15:08:12 +00003981
John McCall550e0c22009-10-21 00:40:46 +00003982 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3983 NewTL.setNameLoc(TL.getNameLoc());
3984
3985 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986}
Mike Stump11289f42009-09-09 15:08:12 +00003987
3988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003989QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003990 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003991 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003992 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003993 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3994 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003995 if (!Enum)
3996 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003997
John McCall550e0c22009-10-21 00:40:46 +00003998 QualType Result = TL.getType();
3999 if (getDerived().AlwaysRebuild() ||
4000 Enum != T->getDecl()) {
4001 Result = getDerived().RebuildEnumType(Enum);
4002 if (Result.isNull())
4003 return QualType();
4004 }
Mike Stump11289f42009-09-09 15:08:12 +00004005
John McCall550e0c22009-10-21 00:40:46 +00004006 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4007 NewTL.setNameLoc(TL.getNameLoc());
4008
4009 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004010}
John McCallfcc33b02009-09-05 00:15:47 +00004011
John McCalle78aac42010-03-10 03:28:59 +00004012template<typename Derived>
4013QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4014 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004015 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004016 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4017 TL.getTypePtr()->getDecl());
4018 if (!D) return QualType();
4019
4020 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4021 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4022 return T;
4023}
4024
Douglas Gregord6ff3322009-08-04 16:50:30 +00004025template<typename Derived>
4026QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004027 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004028 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004029 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030}
4031
Mike Stump11289f42009-09-09 15:08:12 +00004032template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004033QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004034 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004035 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004036 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004037}
4038
4039template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004040QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4041 TypeLocBuilder &TLB,
4042 SubstTemplateTypeParmPackTypeLoc TL) {
4043 return TransformTypeSpecType(TLB, TL);
4044}
4045
4046template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004047QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004048 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004049 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004050 const TemplateSpecializationType *T = TL.getTypePtr();
4051
Mike Stump11289f42009-09-09 15:08:12 +00004052 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004053 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004054 if (Template.isNull())
4055 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004056
John McCall31f82722010-11-12 08:19:04 +00004057 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4058}
4059
Douglas Gregorfe921a72010-12-20 23:36:19 +00004060namespace {
4061 /// \brief Simple iterator that traverses the template arguments in a
4062 /// container that provides a \c getArgLoc() member function.
4063 ///
4064 /// This iterator is intended to be used with the iterator form of
4065 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4066 template<typename ArgLocContainer>
4067 class TemplateArgumentLocContainerIterator {
4068 ArgLocContainer *Container;
4069 unsigned Index;
4070
4071 public:
4072 typedef TemplateArgumentLoc value_type;
4073 typedef TemplateArgumentLoc reference;
4074 typedef int difference_type;
4075 typedef std::input_iterator_tag iterator_category;
4076
4077 class pointer {
4078 TemplateArgumentLoc Arg;
4079
4080 public:
4081 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4082
4083 const TemplateArgumentLoc *operator->() const {
4084 return &Arg;
4085 }
4086 };
4087
4088
4089 TemplateArgumentLocContainerIterator() {}
4090
4091 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4092 unsigned Index)
4093 : Container(&Container), Index(Index) { }
4094
4095 TemplateArgumentLocContainerIterator &operator++() {
4096 ++Index;
4097 return *this;
4098 }
4099
4100 TemplateArgumentLocContainerIterator operator++(int) {
4101 TemplateArgumentLocContainerIterator Old(*this);
4102 ++(*this);
4103 return Old;
4104 }
4105
4106 TemplateArgumentLoc operator*() const {
4107 return Container->getArgLoc(Index);
4108 }
4109
4110 pointer operator->() const {
4111 return pointer(Container->getArgLoc(Index));
4112 }
4113
4114 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004115 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004116 return X.Container == Y.Container && X.Index == Y.Index;
4117 }
4118
4119 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004120 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004121 return !(X == Y);
4122 }
4123 };
4124}
4125
4126
John McCall31f82722010-11-12 08:19:04 +00004127template <typename Derived>
4128QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4129 TypeLocBuilder &TLB,
4130 TemplateSpecializationTypeLoc TL,
4131 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004132 TemplateArgumentListInfo NewTemplateArgs;
4133 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4134 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004135 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4136 ArgIterator;
4137 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4138 ArgIterator(TL, TL.getNumArgs()),
4139 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004140 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004141
John McCall0ad16662009-10-29 08:12:44 +00004142 // FIXME: maybe don't rebuild if all the template arguments are the same.
4143
4144 QualType Result =
4145 getDerived().RebuildTemplateSpecializationType(Template,
4146 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004147 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004148
4149 if (!Result.isNull()) {
4150 TemplateSpecializationTypeLoc NewTL
4151 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4152 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4153 NewTL.setLAngleLoc(TL.getLAngleLoc());
4154 NewTL.setRAngleLoc(TL.getRAngleLoc());
4155 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4156 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157 }
Mike Stump11289f42009-09-09 15:08:12 +00004158
John McCall0ad16662009-10-29 08:12:44 +00004159 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004160}
Mike Stump11289f42009-09-09 15:08:12 +00004161
4162template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004163QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004164TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004165 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004166 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004167
4168 NestedNameSpecifier *NNS = 0;
4169 // NOTE: the qualifier in an ElaboratedType is optional.
4170 if (T->getQualifier() != 0) {
4171 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004172 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004173 if (!NNS)
4174 return QualType();
4175 }
Mike Stump11289f42009-09-09 15:08:12 +00004176
John McCall31f82722010-11-12 08:19:04 +00004177 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4178 if (NamedT.isNull())
4179 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004180
John McCall550e0c22009-10-21 00:40:46 +00004181 QualType Result = TL.getType();
4182 if (getDerived().AlwaysRebuild() ||
4183 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004184 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004185 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4186 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004187 if (Result.isNull())
4188 return QualType();
4189 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004190
Abramo Bagnara6150c882010-05-11 21:36:43 +00004191 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004192 NewTL.setKeywordLoc(TL.getKeywordLoc());
4193 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004194
4195 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004196}
Mike Stump11289f42009-09-09 15:08:12 +00004197
4198template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004199QualType TreeTransform<Derived>::TransformAttributedType(
4200 TypeLocBuilder &TLB,
4201 AttributedTypeLoc TL) {
4202 const AttributedType *oldType = TL.getTypePtr();
4203 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4204 if (modifiedType.isNull())
4205 return QualType();
4206
4207 QualType result = TL.getType();
4208
4209 // FIXME: dependent operand expressions?
4210 if (getDerived().AlwaysRebuild() ||
4211 modifiedType != oldType->getModifiedType()) {
4212 // TODO: this is really lame; we should really be rebuilding the
4213 // equivalent type from first principles.
4214 QualType equivalentType
4215 = getDerived().TransformType(oldType->getEquivalentType());
4216 if (equivalentType.isNull())
4217 return QualType();
4218 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4219 modifiedType,
4220 equivalentType);
4221 }
4222
4223 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4224 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4225 if (TL.hasAttrOperand())
4226 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4227 if (TL.hasAttrExprOperand())
4228 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4229 else if (TL.hasAttrEnumOperand())
4230 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4231
4232 return result;
4233}
4234
4235template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004236QualType
4237TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4238 ParenTypeLoc TL) {
4239 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4240 if (Inner.isNull())
4241 return QualType();
4242
4243 QualType Result = TL.getType();
4244 if (getDerived().AlwaysRebuild() ||
4245 Inner != TL.getInnerLoc().getType()) {
4246 Result = getDerived().RebuildParenType(Inner);
4247 if (Result.isNull())
4248 return QualType();
4249 }
4250
4251 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4252 NewTL.setLParenLoc(TL.getLParenLoc());
4253 NewTL.setRParenLoc(TL.getRParenLoc());
4254 return Result;
4255}
4256
4257template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004258QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004259 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004260 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004261
Douglas Gregord6ff3322009-08-04 16:50:30 +00004262 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004263 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004264 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265 if (!NNS)
4266 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004267
John McCallc392f372010-06-11 00:33:02 +00004268 QualType Result
4269 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4270 T->getIdentifier(),
4271 TL.getKeywordLoc(),
4272 TL.getQualifierRange(),
4273 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004274 if (Result.isNull())
4275 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004276
Abramo Bagnarad7548482010-05-19 21:37:53 +00004277 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4278 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004279 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4280
Abramo Bagnarad7548482010-05-19 21:37:53 +00004281 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4282 NewTL.setKeywordLoc(TL.getKeywordLoc());
4283 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004284 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004285 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4286 NewTL.setKeywordLoc(TL.getKeywordLoc());
4287 NewTL.setQualifierRange(TL.getQualifierRange());
4288 NewTL.setNameLoc(TL.getNameLoc());
4289 }
John McCall550e0c22009-10-21 00:40:46 +00004290 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004291}
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregord6ff3322009-08-04 16:50:30 +00004293template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004294QualType TreeTransform<Derived>::
4295 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004296 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004297 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004298
4299 NestedNameSpecifier *NNS
4300 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004301 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004302 if (!NNS)
4303 return QualType();
4304
John McCall31f82722010-11-12 08:19:04 +00004305 return getDerived()
4306 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4307}
4308
4309template<typename Derived>
4310QualType TreeTransform<Derived>::
4311 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4312 DependentTemplateSpecializationTypeLoc TL,
4313 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004314 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004315
John McCallc392f372010-06-11 00:33:02 +00004316 TemplateArgumentListInfo NewTemplateArgs;
4317 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4318 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004319
4320 typedef TemplateArgumentLocContainerIterator<
4321 DependentTemplateSpecializationTypeLoc> ArgIterator;
4322 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4323 ArgIterator(TL, TL.getNumArgs()),
4324 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004325 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004326
Douglas Gregora5614c52010-09-08 23:56:00 +00004327 QualType Result
4328 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4329 NNS,
4330 TL.getQualifierRange(),
4331 T->getIdentifier(),
4332 TL.getNameLoc(),
4333 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004334 if (Result.isNull())
4335 return QualType();
4336
4337 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4338 QualType NamedT = ElabT->getNamedType();
4339
4340 // Copy information relevant to the template specialization.
4341 TemplateSpecializationTypeLoc NamedTL
4342 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4343 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4344 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4345 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4346 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4347
4348 // Copy information relevant to the elaborated type.
4349 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4350 NewTL.setKeywordLoc(TL.getKeywordLoc());
4351 NewTL.setQualifierRange(TL.getQualifierRange());
4352 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004353 TypeLoc NewTL(Result, TL.getOpaqueData());
4354 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004355 }
4356 return Result;
4357}
4358
4359template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004360QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4361 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004362 QualType Pattern
4363 = getDerived().TransformType(TLB, TL.getPatternLoc());
4364 if (Pattern.isNull())
4365 return QualType();
4366
4367 QualType Result = TL.getType();
4368 if (getDerived().AlwaysRebuild() ||
4369 Pattern != TL.getPatternLoc().getType()) {
4370 Result = getDerived().RebuildPackExpansionType(Pattern,
4371 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004372 TL.getEllipsisLoc(),
4373 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004374 if (Result.isNull())
4375 return QualType();
4376 }
4377
4378 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4379 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4380 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004381}
4382
4383template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004384QualType
4385TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004386 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004387 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004388 TLB.pushFullCopy(TL);
4389 return TL.getType();
4390}
4391
4392template<typename Derived>
4393QualType
4394TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004395 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004396 // ObjCObjectType is never dependent.
4397 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004398 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004399}
Mike Stump11289f42009-09-09 15:08:12 +00004400
4401template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004402QualType
4403TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004404 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004405 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004406 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004407 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004408}
4409
Douglas Gregord6ff3322009-08-04 16:50:30 +00004410//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004411// Statement transformation
4412//===----------------------------------------------------------------------===//
4413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004414StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004415TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004416 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004417}
4418
4419template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004420StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004421TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4422 return getDerived().TransformCompoundStmt(S, false);
4423}
4424
4425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004426StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004427TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004428 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004429 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004430 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004431 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004432 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4433 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004434 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004435 if (Result.isInvalid()) {
4436 // Immediately fail if this was a DeclStmt, since it's very
4437 // likely that this will cause problems for future statements.
4438 if (isa<DeclStmt>(*B))
4439 return StmtError();
4440
4441 // Otherwise, just keep processing substatements and fail later.
4442 SubStmtInvalid = true;
4443 continue;
4444 }
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregorebe10102009-08-20 07:17:43 +00004446 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4447 Statements.push_back(Result.takeAs<Stmt>());
4448 }
Mike Stump11289f42009-09-09 15:08:12 +00004449
John McCall1ababa62010-08-27 19:56:05 +00004450 if (SubStmtInvalid)
4451 return StmtError();
4452
Douglas Gregorebe10102009-08-20 07:17:43 +00004453 if (!getDerived().AlwaysRebuild() &&
4454 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004455 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004456
4457 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4458 move_arg(Statements),
4459 S->getRBracLoc(),
4460 IsStmtExpr);
4461}
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregorebe10102009-08-20 07:17:43 +00004463template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004464StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004465TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004466 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004467 {
4468 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004469 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004470
Eli Friedman06577382009-11-19 03:14:00 +00004471 // Transform the left-hand case value.
4472 LHS = getDerived().TransformExpr(S->getLHS());
4473 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004474 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004475
Eli Friedman06577382009-11-19 03:14:00 +00004476 // Transform the right-hand case value (for the GNU case-range extension).
4477 RHS = getDerived().TransformExpr(S->getRHS());
4478 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004479 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004480 }
Mike Stump11289f42009-09-09 15:08:12 +00004481
Douglas Gregorebe10102009-08-20 07:17:43 +00004482 // Build the case statement.
4483 // Case statements are always rebuilt so that they will attached to their
4484 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004485 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004486 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004487 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004488 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004489 S->getColonLoc());
4490 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004491 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004492
Douglas Gregorebe10102009-08-20 07:17:43 +00004493 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004494 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004495 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004496 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004497
Douglas Gregorebe10102009-08-20 07:17:43 +00004498 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004499 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004500}
4501
4502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004503StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004504TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004505 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004506 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004507 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004508 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregorebe10102009-08-20 07:17:43 +00004510 // Default statements are always rebuilt
4511 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004512 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004513}
Mike Stump11289f42009-09-09 15:08:12 +00004514
Douglas Gregorebe10102009-08-20 07:17:43 +00004515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004516StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004517TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004518 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004519 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004520 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004521
Douglas Gregorebe10102009-08-20 07:17:43 +00004522 // FIXME: Pass the real colon location in.
4523 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4524 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004525 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004526}
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregorebe10102009-08-20 07:17:43 +00004528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004529StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004530TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004531 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004532 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004533 VarDecl *ConditionVar = 0;
4534 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004535 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004536 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004537 getDerived().TransformDefinition(
4538 S->getConditionVariable()->getLocation(),
4539 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004540 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004541 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004542 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004543 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004544
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004545 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004546 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004547
4548 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004549 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004550 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4551 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004552 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004553 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004554
John McCallb268a282010-08-23 23:25:46 +00004555 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004556 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004557 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004558
John McCallb268a282010-08-23 23:25:46 +00004559 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4560 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004561 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004562
Douglas Gregorebe10102009-08-20 07:17:43 +00004563 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004564 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004565 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004566 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregorebe10102009-08-20 07:17:43 +00004568 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004569 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004570 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004571 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004572
Douglas Gregorebe10102009-08-20 07:17:43 +00004573 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004574 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004575 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004576 Then.get() == S->getThen() &&
4577 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004578 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004580 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004581 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004582 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004583}
4584
4585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004586StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004587TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004588 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004589 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004590 VarDecl *ConditionVar = 0;
4591 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004592 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004593 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004594 getDerived().TransformDefinition(
4595 S->getConditionVariable()->getLocation(),
4596 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004597 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004598 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004599 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004600 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004601
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004602 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004603 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004604 }
Mike Stump11289f42009-09-09 15:08:12 +00004605
Douglas Gregorebe10102009-08-20 07:17:43 +00004606 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004607 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004608 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004609 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004610 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004611 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregorebe10102009-08-20 07:17:43 +00004613 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004614 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004615 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004616 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregorebe10102009-08-20 07:17:43 +00004618 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004619 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4620 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004621}
Mike Stump11289f42009-09-09 15:08:12 +00004622
Douglas Gregorebe10102009-08-20 07:17:43 +00004623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004624StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004625TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004626 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004627 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004628 VarDecl *ConditionVar = 0;
4629 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004630 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004631 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004632 getDerived().TransformDefinition(
4633 S->getConditionVariable()->getLocation(),
4634 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004635 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004636 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004637 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004638 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004639
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004640 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004641 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004642
4643 if (S->getCond()) {
4644 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004645 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4646 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004647 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004648 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004649 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004650 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004651 }
Mike Stump11289f42009-09-09 15:08:12 +00004652
John McCallb268a282010-08-23 23:25:46 +00004653 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4654 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004655 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004656
Douglas Gregorebe10102009-08-20 07:17:43 +00004657 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004658 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004659 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004660 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregorebe10102009-08-20 07:17:43 +00004662 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004663 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004664 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004665 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004666 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004667
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004668 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004669 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregorebe10102009-08-20 07:17:43 +00004672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004673StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004674TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004675 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004676 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004677 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004678 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004680 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004681 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004682 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004683 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004684
Douglas Gregorebe10102009-08-20 07:17:43 +00004685 if (!getDerived().AlwaysRebuild() &&
4686 Cond.get() == S->getCond() &&
4687 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004688 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004689
John McCallb268a282010-08-23 23:25:46 +00004690 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4691 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004692 S->getRParenLoc());
4693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregorebe10102009-08-20 07:17:43 +00004695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004696StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004697TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004698 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004699 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004700 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004701 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregorebe10102009-08-20 07:17:43 +00004703 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004704 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004705 VarDecl *ConditionVar = 0;
4706 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004707 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004708 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004709 getDerived().TransformDefinition(
4710 S->getConditionVariable()->getLocation(),
4711 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004712 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004713 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004714 } else {
4715 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004716
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004717 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004718 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004719
4720 if (S->getCond()) {
4721 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004722 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4723 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004724 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004725 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004726
John McCallb268a282010-08-23 23:25:46 +00004727 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004728 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004729 }
Mike Stump11289f42009-09-09 15:08:12 +00004730
John McCallb268a282010-08-23 23:25:46 +00004731 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4732 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004733 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004734
Douglas Gregorebe10102009-08-20 07:17:43 +00004735 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004736 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004737 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004738 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004739
John McCallb268a282010-08-23 23:25:46 +00004740 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4741 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004742 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004743
Douglas Gregorebe10102009-08-20 07:17:43 +00004744 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004745 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004746 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004747 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004748
Douglas Gregorebe10102009-08-20 07:17:43 +00004749 if (!getDerived().AlwaysRebuild() &&
4750 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004751 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004752 Inc.get() == S->getInc() &&
4753 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004754 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregorebe10102009-08-20 07:17:43 +00004756 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004757 Init.get(), FullCond, ConditionVar,
4758 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004759}
4760
4761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004762StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004763TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004764 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004765 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004766 S->getLabel());
4767}
4768
4769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004770StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004771TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004772 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004774 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 if (!getDerived().AlwaysRebuild() &&
4777 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004778 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004779
4780 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004781 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004782}
4783
4784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004785StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004786TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004787 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004788}
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregorebe10102009-08-20 07:17:43 +00004790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004792TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004793 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004794}
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregorebe10102009-08-20 07:17:43 +00004796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004798TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004799 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004800 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004801 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004802
Mike Stump11289f42009-09-09 15:08:12 +00004803 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004804 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004805 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004806}
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregorebe10102009-08-20 07:17:43 +00004808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004809StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004810TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004811 bool DeclChanged = false;
4812 llvm::SmallVector<Decl *, 4> Decls;
4813 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4814 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004815 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4816 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004817 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004818 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 if (Transformed != *D)
4821 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 Decls.push_back(Transformed);
4824 }
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregorebe10102009-08-20 07:17:43 +00004826 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004827 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004828
4829 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004830 S->getStartLoc(), S->getEndLoc());
4831}
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregorebe10102009-08-20 07:17:43 +00004833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004834StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004835TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004836
John McCall37ad5512010-08-23 06:44:23 +00004837 ASTOwningVector<Expr*> Constraints(getSema());
4838 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004839 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004840
John McCalldadc5752010-08-24 06:29:42 +00004841 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004842 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004843
4844 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004845
Anders Carlssonaaeef072010-01-24 05:50:09 +00004846 // Go through the outputs.
4847 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004848 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004849
Anders Carlssonaaeef072010-01-24 05:50:09 +00004850 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004851 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004852
Anders Carlssonaaeef072010-01-24 05:50:09 +00004853 // Transform the output expr.
4854 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004855 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004856 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004857 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004858
Anders Carlssonaaeef072010-01-24 05:50:09 +00004859 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004860
John McCallb268a282010-08-23 23:25:46 +00004861 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004862 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004863
Anders Carlssonaaeef072010-01-24 05:50:09 +00004864 // Go through the inputs.
4865 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004866 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004867
Anders Carlssonaaeef072010-01-24 05:50:09 +00004868 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004869 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004870
Anders Carlssonaaeef072010-01-24 05:50:09 +00004871 // Transform the input expr.
4872 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004873 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004874 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004875 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004876
Anders Carlssonaaeef072010-01-24 05:50:09 +00004877 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004878
John McCallb268a282010-08-23 23:25:46 +00004879 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004880 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004881
Anders Carlssonaaeef072010-01-24 05:50:09 +00004882 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004883 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004884
4885 // Go through the clobbers.
4886 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004887 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004888
4889 // No need to transform the asm string literal.
4890 AsmString = SemaRef.Owned(S->getAsmString());
4891
4892 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4893 S->isSimple(),
4894 S->isVolatile(),
4895 S->getNumOutputs(),
4896 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004897 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004898 move_arg(Constraints),
4899 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004900 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004901 move_arg(Clobbers),
4902 S->getRParenLoc(),
4903 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004904}
4905
4906
4907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004908StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004909TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004910 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004911 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004912 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004914
Douglas Gregor96c79492010-04-23 22:50:49 +00004915 // Transform the @catch statements (if present).
4916 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004917 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004918 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004919 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004920 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004921 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004922 if (Catch.get() != S->getCatchStmt(I))
4923 AnyCatchChanged = true;
4924 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004925 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004926
Douglas Gregor306de2f2010-04-22 23:59:56 +00004927 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004928 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004929 if (S->getFinallyStmt()) {
4930 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4931 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004933 }
4934
4935 // If nothing changed, just retain this statement.
4936 if (!getDerived().AlwaysRebuild() &&
4937 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004938 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004939 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004940 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004941
Douglas Gregor306de2f2010-04-22 23:59:56 +00004942 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004943 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4944 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004945}
Mike Stump11289f42009-09-09 15:08:12 +00004946
Douglas Gregorebe10102009-08-20 07:17:43 +00004947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004948StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004949TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004950 // Transform the @catch parameter, if there is one.
4951 VarDecl *Var = 0;
4952 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4953 TypeSourceInfo *TSInfo = 0;
4954 if (FromVar->getTypeSourceInfo()) {
4955 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4956 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004957 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004958 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004959
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004960 QualType T;
4961 if (TSInfo)
4962 T = TSInfo->getType();
4963 else {
4964 T = getDerived().TransformType(FromVar->getType());
4965 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004966 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004967 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004968
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004969 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4970 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004971 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004972 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004973
John McCalldadc5752010-08-24 06:29:42 +00004974 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004975 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004976 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004977
4978 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004979 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004980 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004981}
Mike Stump11289f42009-09-09 15:08:12 +00004982
Douglas Gregorebe10102009-08-20 07:17:43 +00004983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004984StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004985TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004986 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004987 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004988 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004990
Douglas Gregor306de2f2010-04-22 23:59:56 +00004991 // If nothing changed, just retain this statement.
4992 if (!getDerived().AlwaysRebuild() &&
4993 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004994 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004995
4996 // Build a new statement.
4997 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004998 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004999}
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregorebe10102009-08-20 07:17:43 +00005001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005002StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005003TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005004 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005005 if (S->getThrowExpr()) {
5006 Operand = getDerived().TransformExpr(S->getThrowExpr());
5007 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005009 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005010
Douglas Gregor2900c162010-04-22 21:44:01 +00005011 if (!getDerived().AlwaysRebuild() &&
5012 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005013 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005014
John McCallb268a282010-08-23 23:25:46 +00005015 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregorebe10102009-08-20 07:17:43 +00005018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005019StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005020TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005021 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005022 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005024 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005025 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005026
Douglas Gregor6148de72010-04-22 22:01:21 +00005027 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005028 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005029 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005030 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005031
Douglas Gregor6148de72010-04-22 22:01:21 +00005032 // If nothing change, just retain the current statement.
5033 if (!getDerived().AlwaysRebuild() &&
5034 Object.get() == S->getSynchExpr() &&
5035 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005036 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005037
5038 // Build a new statement.
5039 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005040 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005041}
5042
5043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005044StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005045TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005046 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005047 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005048 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005049 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005050 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005051
Douglas Gregorf68a5082010-04-22 23:10:45 +00005052 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005053 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005054 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005055 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005056
Douglas Gregorf68a5082010-04-22 23:10:45 +00005057 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005058 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005059 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005061
Douglas Gregorf68a5082010-04-22 23:10:45 +00005062 // If nothing changed, just retain this statement.
5063 if (!getDerived().AlwaysRebuild() &&
5064 Element.get() == S->getElement() &&
5065 Collection.get() == S->getCollection() &&
5066 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005067 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005068
Douglas Gregorf68a5082010-04-22 23:10:45 +00005069 // Build a new statement.
5070 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5071 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005072 Element.get(),
5073 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005074 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005075 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005076}
5077
5078
5079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005080StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005081TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5082 // Transform the exception declaration, if any.
5083 VarDecl *Var = 0;
5084 if (S->getExceptionDecl()) {
5085 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005086 TypeSourceInfo *T = getDerived().TransformType(
5087 ExceptionDecl->getTypeSourceInfo());
5088 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005091 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005092 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005093 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005094 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005095 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 }
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005099 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005100 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005101 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 if (!getDerived().AlwaysRebuild() &&
5104 !Var &&
5105 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005106 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005107
5108 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5109 Var,
John McCallb268a282010-08-23 23:25:46 +00005110 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005111}
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregorebe10102009-08-20 07:17:43 +00005113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005114StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005115TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5116 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005117 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005118 = getDerived().TransformCompoundStmt(S->getTryBlock());
5119 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005120 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregorebe10102009-08-20 07:17:43 +00005122 // Transform the handlers.
5123 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005124 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005125 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005126 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5128 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005129 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregorebe10102009-08-20 07:17:43 +00005131 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5132 Handlers.push_back(Handler.takeAs<Stmt>());
5133 }
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregorebe10102009-08-20 07:17:43 +00005135 if (!getDerived().AlwaysRebuild() &&
5136 TryBlock.get() == S->getTryBlock() &&
5137 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005138 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005139
John McCallb268a282010-08-23 23:25:46 +00005140 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005141 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005142}
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregorebe10102009-08-20 07:17:43 +00005144//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005145// Expression transformation
5146//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005149TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005150 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005151}
Mike Stump11289f42009-09-09 15:08:12 +00005152
5153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005155TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005156 NestedNameSpecifier *Qualifier = 0;
5157 if (E->getQualifier()) {
5158 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005159 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005160 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005162 }
John McCallce546572009-12-08 09:08:17 +00005163
5164 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005165 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5166 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005169
John McCall815039a2010-08-17 21:27:17 +00005170 DeclarationNameInfo NameInfo = E->getNameInfo();
5171 if (NameInfo.getName()) {
5172 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5173 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005175 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005176
5177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005178 Qualifier == E->getQualifier() &&
5179 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005180 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005181 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005182
5183 // Mark it referenced in the new context regardless.
5184 // FIXME: this is a bit instantiation-specific.
5185 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5186
John McCallc3007a22010-10-26 07:05:15 +00005187 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005188 }
John McCallce546572009-12-08 09:08:17 +00005189
5190 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005191 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005192 TemplateArgs = &TransArgs;
5193 TransArgs.setLAngleLoc(E->getLAngleLoc());
5194 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005195 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5196 E->getNumTemplateArgs(),
5197 TransArgs))
5198 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005199 }
5200
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005201 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005202 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregora16548e2009-08-11 05:31:07 +00005205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005208 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005209}
Mike Stump11289f42009-09-09 15:08:12 +00005210
Douglas Gregora16548e2009-08-11 05:31:07 +00005211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005213TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005214 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005215}
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005219TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005220 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005221}
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregora16548e2009-08-11 05:31:07 +00005223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005225TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005226 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005227}
Mike Stump11289f42009-09-09 15:08:12 +00005228
Douglas Gregora16548e2009-08-11 05:31:07 +00005229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005232 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005233}
5234
5235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005237TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005238 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005243 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005244
John McCallb268a282010-08-23 23:25:46 +00005245 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 E->getRParen());
5247}
5248
Mike Stump11289f42009-09-09 15:08:12 +00005249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005251TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005252 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005257 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5260 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005261 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005262}
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregora16548e2009-08-11 05:31:07 +00005264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005266TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5267 // Transform the type.
5268 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5269 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Douglas Gregor882211c2010-04-28 22:16:22 +00005272 // Transform all of the components into components similar to what the
5273 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005274 // FIXME: It would be slightly more efficient in the non-dependent case to
5275 // just map FieldDecls, rather than requiring the rebuilder to look for
5276 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005277 // template code that we don't care.
5278 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005279 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005280 typedef OffsetOfExpr::OffsetOfNode Node;
5281 llvm::SmallVector<Component, 4> Components;
5282 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5283 const Node &ON = E->getComponent(I);
5284 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005285 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005286 Comp.LocStart = ON.getRange().getBegin();
5287 Comp.LocEnd = ON.getRange().getEnd();
5288 switch (ON.getKind()) {
5289 case Node::Array: {
5290 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005291 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005292 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005293 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005294
Douglas Gregor882211c2010-04-28 22:16:22 +00005295 ExprChanged = ExprChanged || Index.get() != FromIndex;
5296 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005297 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005298 break;
5299 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005300
Douglas Gregor882211c2010-04-28 22:16:22 +00005301 case Node::Field:
5302 case Node::Identifier:
5303 Comp.isBrackets = false;
5304 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005305 if (!Comp.U.IdentInfo)
5306 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005307
Douglas Gregor882211c2010-04-28 22:16:22 +00005308 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005309
Douglas Gregord1702062010-04-29 00:18:15 +00005310 case Node::Base:
5311 // Will be recomputed during the rebuild.
5312 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005313 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Douglas Gregor882211c2010-04-28 22:16:22 +00005315 Components.push_back(Comp);
5316 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
Douglas Gregor882211c2010-04-28 22:16:22 +00005318 // If nothing changed, retain the existing expression.
5319 if (!getDerived().AlwaysRebuild() &&
5320 Type == E->getTypeSourceInfo() &&
5321 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005322 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregor882211c2010-04-28 22:16:22 +00005324 // Build a new offsetof expression.
5325 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5326 Components.data(), Components.size(),
5327 E->getRParenLoc());
5328}
5329
5330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005331ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005332TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5333 assert(getDerived().AlreadyTransformed(E->getType()) &&
5334 "opaque value expression requires transformation");
5335 return SemaRef.Owned(E);
5336}
5337
5338template<typename Derived>
5339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005340TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005342 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005343
John McCallbcd03502009-12-07 02:54:59 +00005344 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005345 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall4c98fd82009-11-04 07:28:41 +00005348 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005349 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005350
John McCall4c98fd82009-11-04 07:28:41 +00005351 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005352 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 E->getSourceRange());
5354 }
Mike Stump11289f42009-09-09 15:08:12 +00005355
John McCalldadc5752010-08-24 06:29:42 +00005356 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005357 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 // C++0x [expr.sizeof]p1:
5359 // The operand is either an expression, which is an unevaluated operand
5360 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005361 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregora16548e2009-08-11 05:31:07 +00005363 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5364 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005368 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 }
Mike Stump11289f42009-09-09 15:08:12 +00005370
John McCallb268a282010-08-23 23:25:46 +00005371 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 E->isSizeOf(),
5373 E->getSourceRange());
5374}
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregora16548e2009-08-11 05:31:07 +00005376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005378TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005379 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005380 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005382
John McCalldadc5752010-08-24 06:29:42 +00005383 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005384 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005386
5387
Douglas Gregora16548e2009-08-11 05:31:07 +00005388 if (!getDerived().AlwaysRebuild() &&
5389 LHS.get() == E->getLHS() &&
5390 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005391 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005392
John McCallb268a282010-08-23 23:25:46 +00005393 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005395 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 E->getRBracketLoc());
5397}
Mike Stump11289f42009-09-09 15:08:12 +00005398
5399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005401TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005402 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005403 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005406
5407 // Transform arguments.
5408 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005409 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005410 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5411 &ArgChanged))
5412 return ExprError();
5413
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 if (!getDerived().AlwaysRebuild() &&
5415 Callee.get() == E->getCallee() &&
5416 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005417 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregora16548e2009-08-11 05:31:07 +00005419 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005420 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005421 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005422 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 E->getRParenLoc());
5425}
Mike Stump11289f42009-09-09 15:08:12 +00005426
5427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005429TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005430 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005431 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005434 NestedNameSpecifier *Qualifier = 0;
5435 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005436 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005437 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005438 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005439 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005440 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005441 }
Mike Stump11289f42009-09-09 15:08:12 +00005442
Eli Friedman2cfcef62009-12-04 06:40:45 +00005443 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005444 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5445 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005448
John McCall16df1e52010-03-30 21:47:33 +00005449 NamedDecl *FoundDecl = E->getFoundDecl();
5450 if (FoundDecl == E->getMemberDecl()) {
5451 FoundDecl = Member;
5452 } else {
5453 FoundDecl = cast_or_null<NamedDecl>(
5454 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5455 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005456 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005457 }
5458
Douglas Gregora16548e2009-08-11 05:31:07 +00005459 if (!getDerived().AlwaysRebuild() &&
5460 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005461 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005462 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005463 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005464 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005465
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005466 // Mark it referenced in the new context regardless.
5467 // FIXME: this is a bit instantiation-specific.
5468 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005469 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005470 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005471
John McCall6b51f282009-11-23 01:53:49 +00005472 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005473 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005474 TransArgs.setLAngleLoc(E->getLAngleLoc());
5475 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005476 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5477 E->getNumTemplateArgs(),
5478 TransArgs))
5479 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005480 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005481
Douglas Gregora16548e2009-08-11 05:31:07 +00005482 // FIXME: Bogus source location for the operator
5483 SourceLocation FakeOperatorLoc
5484 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5485
John McCall38836f02010-01-15 08:34:02 +00005486 // FIXME: to do this check properly, we will need to preserve the
5487 // first-qualifier-in-scope here, just in case we had a dependent
5488 // base (and therefore couldn't do the check) and a
5489 // nested-name-qualifier (and therefore could do the lookup).
5490 NamedDecl *FirstQualifierInScope = 0;
5491
John McCallb268a282010-08-23 23:25:46 +00005492 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005493 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005494 Qualifier,
5495 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005496 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005497 Member,
John McCall16df1e52010-03-30 21:47:33 +00005498 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005499 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005500 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005501 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005502}
Mike Stump11289f42009-09-09 15:08:12 +00005503
Douglas Gregora16548e2009-08-11 05:31:07 +00005504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005506TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005507 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005510
John McCalldadc5752010-08-24 06:29:42 +00005511 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregora16548e2009-08-11 05:31:07 +00005515 if (!getDerived().AlwaysRebuild() &&
5516 LHS.get() == E->getLHS() &&
5517 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005518 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005521 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005522}
5523
Mike Stump11289f42009-09-09 15:08:12 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005526TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005527 CompoundAssignOperator *E) {
5528 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005529}
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005532ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005533TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005534 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005537
John McCalldadc5752010-08-24 06:29:42 +00005538 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005540 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005541
John McCalldadc5752010-08-24 06:29:42 +00005542 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005543 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 if (!getDerived().AlwaysRebuild() &&
5547 Cond.get() == E->getCond() &&
5548 LHS.get() == E->getLHS() &&
5549 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005550 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005551
John McCallb268a282010-08-23 23:25:46 +00005552 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005553 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005554 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005555 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005556 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005557}
Mike Stump11289f42009-09-09 15:08:12 +00005558
5559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005561TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005562 // Implicit casts are eliminated during transformation, since they
5563 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005564 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005565}
Mike Stump11289f42009-09-09 15:08:12 +00005566
Douglas Gregora16548e2009-08-11 05:31:07 +00005567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005569TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005570 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5571 if (!Type)
5572 return ExprError();
5573
John McCalldadc5752010-08-24 06:29:42 +00005574 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005575 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005580 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005582 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005583
John McCall97513962010-01-15 18:39:57 +00005584 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005585 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005586 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005587 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005588}
Mike Stump11289f42009-09-09 15:08:12 +00005589
Douglas Gregora16548e2009-08-11 05:31:07 +00005590template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005591ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005592TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005593 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5594 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5595 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005597
John McCalldadc5752010-08-24 06:29:42 +00005598 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005603 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005605 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005606
John McCall5d7aa7f2010-01-19 22:33:45 +00005607 // Note: the expression type doesn't necessarily match the
5608 // type-as-written, but that's okay, because it should always be
5609 // derivable from the initializer.
5610
John McCalle15bbff2010-01-18 19:35:47 +00005611 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005613 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005618TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005619 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 if (!getDerived().AlwaysRebuild() &&
5624 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005625 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005628 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005630 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 E->getAccessorLoc(),
5632 E->getAccessor());
5633}
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregora16548e2009-08-11 05:31:07 +00005635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005636ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005637TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005639
John McCall37ad5512010-08-23 06:44:23 +00005640 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005641 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5642 Inits, &InitChanged))
5643 return ExprError();
5644
Douglas Gregora16548e2009-08-11 05:31:07 +00005645 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005646 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005647
Douglas Gregora16548e2009-08-11 05:31:07 +00005648 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005649 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005650}
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregora16548e2009-08-11 05:31:07 +00005652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005654TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregorebe10102009-08-20 07:17:43 +00005657 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005658 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregorebe10102009-08-20 07:17:43 +00005662 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005663 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 bool ExprChanged = false;
5665 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5666 DEnd = E->designators_end();
5667 D != DEnd; ++D) {
5668 if (D->isFieldDesignator()) {
5669 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5670 D->getDotLoc(),
5671 D->getFieldLoc()));
5672 continue;
5673 }
Mike Stump11289f42009-09-09 15:08:12 +00005674
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005676 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005678 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005679
5680 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregora16548e2009-08-11 05:31:07 +00005683 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5684 ArrayExprs.push_back(Index.release());
5685 continue;
5686 }
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005689 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005690 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5691 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005692 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005693
John McCalldadc5752010-08-24 06:29:42 +00005694 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005697
5698 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 End.get(),
5700 D->getLBracketLoc(),
5701 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5704 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 ArrayExprs.push_back(Start.release());
5707 ArrayExprs.push_back(End.release());
5708 }
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 if (!getDerived().AlwaysRebuild() &&
5711 Init.get() == E->getInit() &&
5712 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005713 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregora16548e2009-08-11 05:31:07 +00005715 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5716 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005717 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005718}
Mike Stump11289f42009-09-09 15:08:12 +00005719
Douglas Gregora16548e2009-08-11 05:31:07 +00005720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005721ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005722TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005723 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005724 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005725
Douglas Gregor3da3c062009-10-28 00:29:27 +00005726 // FIXME: Will we ever have proper type location here? Will we actually
5727 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 QualType T = getDerived().TransformType(E->getType());
5729 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 if (!getDerived().AlwaysRebuild() &&
5733 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005734 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 return getDerived().RebuildImplicitValueInitExpr(T);
5737}
Mike Stump11289f42009-09-09 15:08:12 +00005738
Douglas Gregora16548e2009-08-11 05:31:07 +00005739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005741TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005742 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5743 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005745
John McCalldadc5752010-08-24 06:29:42 +00005746 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005749
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005751 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005753 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005754
John McCallb268a282010-08-23 23:25:46 +00005755 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005756 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005757}
5758
5759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005761TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005762 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005763 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005764 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5765 &ArgumentChanged))
5766 return ExprError();
5767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5769 move_arg(Inits),
5770 E->getRParenLoc());
5771}
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregora16548e2009-08-11 05:31:07 +00005773/// \brief Transform an address-of-label expression.
5774///
5775/// By default, the transformation of an address-of-label expression always
5776/// rebuilds the expression, so that the label identifier can be resolved to
5777/// the corresponding label statement by semantic analysis.
5778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005780TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005781 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5782 E->getLabel());
5783}
Mike Stump11289f42009-09-09 15:08:12 +00005784
5785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005787TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005788 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5790 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005792
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 if (!getDerived().AlwaysRebuild() &&
5794 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005795 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005796
5797 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005798 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005799 E->getRParenLoc());
5800}
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregora16548e2009-08-11 05:31:07 +00005802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005803ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005804TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005805 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005807 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005808
John McCalldadc5752010-08-24 06:29:42 +00005809 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005812
John McCalldadc5752010-08-24 06:29:42 +00005813 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 if (!getDerived().AlwaysRebuild() &&
5818 Cond.get() == E->getCond() &&
5819 LHS.get() == E->getLHS() &&
5820 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005821 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005824 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 E->getRParenLoc());
5826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005830TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005831 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005832}
5833
5834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005836TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005837 switch (E->getOperator()) {
5838 case OO_New:
5839 case OO_Delete:
5840 case OO_Array_New:
5841 case OO_Array_Delete:
5842 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005843 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005844
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005845 case OO_Call: {
5846 // This is a call to an object's operator().
5847 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5848
5849 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005850 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005851 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005852 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005853
5854 // FIXME: Poor location information
5855 SourceLocation FakeLParenLoc
5856 = SemaRef.PP.getLocForEndOfToken(
5857 static_cast<Expr *>(Object.get())->getLocEnd());
5858
5859 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005860 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005861 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5862 Args))
5863 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005864
John McCallb268a282010-08-23 23:25:46 +00005865 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005866 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005867 E->getLocEnd());
5868 }
5869
5870#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5871 case OO_##Name:
5872#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5873#include "clang/Basic/OperatorKinds.def"
5874 case OO_Subscript:
5875 // Handled below.
5876 break;
5877
5878 case OO_Conditional:
5879 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005880 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005881
5882 case OO_None:
5883 case NUM_OVERLOADED_OPERATORS:
5884 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005885 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005886 }
5887
John McCalldadc5752010-08-24 06:29:42 +00005888 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005891
John McCalldadc5752010-08-24 06:29:42 +00005892 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005895
John McCalldadc5752010-08-24 06:29:42 +00005896 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (E->getNumArgs() == 2) {
5898 Second = getDerived().TransformExpr(E->getArg(1));
5899 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005900 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 }
Mike Stump11289f42009-09-09 15:08:12 +00005902
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 if (!getDerived().AlwaysRebuild() &&
5904 Callee.get() == E->getCallee() &&
5905 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005906 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005907 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005908
Douglas Gregora16548e2009-08-11 05:31:07 +00005909 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5910 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005911 Callee.get(),
5912 First.get(),
5913 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005914}
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregora16548e2009-08-11 05:31:07 +00005916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005917ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005918TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5919 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005920}
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005923ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005924TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005925 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5926 if (!Type)
5927 return ExprError();
5928
John McCalldadc5752010-08-24 06:29:42 +00005929 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005930 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005931 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005932 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005935 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005937 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005940 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005941 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5942 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5943 SourceLocation FakeRParenLoc
5944 = SemaRef.PP.getLocForEndOfToken(
5945 E->getSubExpr()->getSourceRange().getEnd());
5946 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005947 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005948 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005949 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005950 FakeRAngleLoc,
5951 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005952 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005953 FakeRParenLoc);
5954}
Mike Stump11289f42009-09-09 15:08:12 +00005955
Douglas Gregora16548e2009-08-11 05:31:07 +00005956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005957ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005958TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5959 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005960}
Mike Stump11289f42009-09-09 15:08:12 +00005961
5962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005964TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5965 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005966}
5967
Douglas Gregora16548e2009-08-11 05:31:07 +00005968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005969ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005970TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005971 CXXReinterpretCastExpr *E) {
5972 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005973}
Mike Stump11289f42009-09-09 15:08:12 +00005974
Douglas Gregora16548e2009-08-11 05:31:07 +00005975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005976ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005977TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5978 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005979}
Mike Stump11289f42009-09-09 15:08:12 +00005980
Douglas Gregora16548e2009-08-11 05:31:07 +00005981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005982ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005983TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005984 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005985 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5986 if (!Type)
5987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005988
John McCalldadc5752010-08-24 06:29:42 +00005989 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005990 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005992 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregora16548e2009-08-11 05:31:07 +00005994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005995 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005997 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005998
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005999 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006001 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 E->getRParenLoc());
6003}
Mike Stump11289f42009-09-09 15:08:12 +00006004
Douglas Gregora16548e2009-08-11 05:31:07 +00006005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006007TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006008 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006009 TypeSourceInfo *TInfo
6010 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6011 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006015 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006016 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006017
Douglas Gregor9da64192010-04-26 22:37:10 +00006018 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6019 E->getLocStart(),
6020 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 E->getLocEnd());
6022 }
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 // We don't know whether the expression is potentially evaluated until
6025 // after we perform semantic analysis, so the expression is potentially
6026 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006027 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006028 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006029
John McCalldadc5752010-08-24 06:29:42 +00006030 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006031 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 if (!getDerived().AlwaysRebuild() &&
6035 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006036 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregor9da64192010-04-26 22:37:10 +00006038 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6039 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006040 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 E->getLocEnd());
6042}
6043
6044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006045ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006046TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6047 if (E->isTypeOperand()) {
6048 TypeSourceInfo *TInfo
6049 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6050 if (!TInfo)
6051 return ExprError();
6052
6053 if (!getDerived().AlwaysRebuild() &&
6054 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006055 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006056
6057 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6058 E->getLocStart(),
6059 TInfo,
6060 E->getLocEnd());
6061 }
6062
6063 // We don't know whether the expression is potentially evaluated until
6064 // after we perform semantic analysis, so the expression is potentially
6065 // potentially evaluated.
6066 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6067
6068 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6069 if (SubExpr.isInvalid())
6070 return ExprError();
6071
6072 if (!getDerived().AlwaysRebuild() &&
6073 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006074 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006075
6076 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6077 E->getLocStart(),
6078 SubExpr.get(),
6079 E->getLocEnd());
6080}
6081
6082template<typename Derived>
6083ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006084TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006085 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006086}
Mike Stump11289f42009-09-09 15:08:12 +00006087
Douglas Gregora16548e2009-08-11 05:31:07 +00006088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006089ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006090TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006091 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006092 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006093}
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregora16548e2009-08-11 05:31:07 +00006095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006098 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6099 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6100 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006102 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006103 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006104
Douglas Gregorb15af892010-01-07 23:12:05 +00006105 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006106}
Mike Stump11289f42009-09-09 15:08:12 +00006107
Douglas Gregora16548e2009-08-11 05:31:07 +00006108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006109ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006110TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006111 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006114
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 if (!getDerived().AlwaysRebuild() &&
6116 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006117 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006118
John McCallb268a282010-08-23 23:25:46 +00006119 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
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
John McCall47f29ea2009-12-08 09:21:05 +00006124TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006125 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006126 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6127 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006128 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006130
Chandler Carruth794da4c2010-02-08 06:42:49 +00006131 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006133 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006134
Douglas Gregor033f6752009-12-23 23:03:06 +00006135 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006136}
Mike Stump11289f42009-09-09 15:08:12 +00006137
Douglas Gregora16548e2009-08-11 05:31:07 +00006138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006139ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006140TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6141 CXXScalarValueInitExpr *E) {
6142 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6143 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006144 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006145
Douglas Gregora16548e2009-08-11 05:31:07 +00006146 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006147 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregor2b88c112010-09-08 00:15:04 +00006150 return getDerived().RebuildCXXScalarValueInitExpr(T,
6151 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006152 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006153}
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregora16548e2009-08-11 05:31:07 +00006155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006157TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006158 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006159 TypeSourceInfo *AllocTypeInfo
6160 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6161 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006162 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregora16548e2009-08-11 05:31:07 +00006164 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006165 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregora16548e2009-08-11 05:31:07 +00006169 // Transform the placement arguments (if any).
6170 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006171 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006172 if (getDerived().TransformExprs(E->getPlacementArgs(),
6173 E->getNumPlacementArgs(), true,
6174 PlacementArgs, &ArgumentChanged))
6175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006176
Douglas Gregorebe10102009-08-20 07:17:43 +00006177 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006178 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006179 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6180 ConstructorArgs, &ArgumentChanged))
6181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006182
Douglas Gregord2d9da02010-02-26 00:38:10 +00006183 // Transform constructor, new operator, and delete operator.
6184 CXXConstructorDecl *Constructor = 0;
6185 if (E->getConstructor()) {
6186 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006187 getDerived().TransformDecl(E->getLocStart(),
6188 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006189 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006190 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006191 }
6192
6193 FunctionDecl *OperatorNew = 0;
6194 if (E->getOperatorNew()) {
6195 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006196 getDerived().TransformDecl(E->getLocStart(),
6197 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006198 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006199 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006200 }
6201
6202 FunctionDecl *OperatorDelete = 0;
6203 if (E->getOperatorDelete()) {
6204 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006205 getDerived().TransformDecl(E->getLocStart(),
6206 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006207 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006209 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006210
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006212 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006214 Constructor == E->getConstructor() &&
6215 OperatorNew == E->getOperatorNew() &&
6216 OperatorDelete == E->getOperatorDelete() &&
6217 !ArgumentChanged) {
6218 // Mark any declarations we need as referenced.
6219 // FIXME: instantiation-specific.
6220 if (Constructor)
6221 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6222 if (OperatorNew)
6223 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6224 if (OperatorDelete)
6225 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006226 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006227 }
Mike Stump11289f42009-09-09 15:08:12 +00006228
Douglas Gregor0744ef62010-09-07 21:49:58 +00006229 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006230 if (!ArraySize.get()) {
6231 // If no array size was specified, but the new expression was
6232 // instantiated with an array type (e.g., "new T" where T is
6233 // instantiated with "int[4]"), extract the outer bound from the
6234 // array type as our array size. We do this with constant and
6235 // dependently-sized array types.
6236 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6237 if (!ArrayT) {
6238 // Do nothing
6239 } else if (const ConstantArrayType *ConsArrayT
6240 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006241 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006242 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6243 ConsArrayT->getSize(),
6244 SemaRef.Context.getSizeType(),
6245 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006246 AllocType = ConsArrayT->getElementType();
6247 } else if (const DependentSizedArrayType *DepArrayT
6248 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6249 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006250 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006251 AllocType = DepArrayT->getElementType();
6252 }
6253 }
6254 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006255
Douglas Gregora16548e2009-08-11 05:31:07 +00006256 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6257 E->isGlobalNew(),
6258 /*FIXME:*/E->getLocStart(),
6259 move_arg(PlacementArgs),
6260 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006261 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006263 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006264 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 /*FIXME:*/E->getLocStart(),
6266 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006267 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006268}
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregora16548e2009-08-11 05:31:07 +00006270template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006271ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006272TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006273 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006274 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006276
Douglas Gregord2d9da02010-02-26 00:38:10 +00006277 // Transform the delete operator, if known.
6278 FunctionDecl *OperatorDelete = 0;
6279 if (E->getOperatorDelete()) {
6280 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006281 getDerived().TransformDecl(E->getLocStart(),
6282 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006283 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006284 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006285 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006286
Douglas Gregora16548e2009-08-11 05:31:07 +00006287 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006288 Operand.get() == E->getArgument() &&
6289 OperatorDelete == E->getOperatorDelete()) {
6290 // Mark any declarations we need as referenced.
6291 // FIXME: instantiation-specific.
6292 if (OperatorDelete)
6293 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006294
6295 if (!E->getArgument()->isTypeDependent()) {
6296 QualType Destroyed = SemaRef.Context.getBaseElementType(
6297 E->getDestroyedType());
6298 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6299 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6300 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6301 SemaRef.LookupDestructor(Record));
6302 }
6303 }
6304
John McCallc3007a22010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006306 }
Mike Stump11289f42009-09-09 15:08:12 +00006307
Douglas Gregora16548e2009-08-11 05:31:07 +00006308 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6309 E->isGlobalDelete(),
6310 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006311 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006312}
Mike Stump11289f42009-09-09 15:08:12 +00006313
Douglas Gregora16548e2009-08-11 05:31:07 +00006314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006315ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006316TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006317 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006318 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006319 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006321
John McCallba7bf592010-08-24 05:47:05 +00006322 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006323 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006324 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006325 E->getOperatorLoc(),
6326 E->isArrow()? tok::arrow : tok::period,
6327 ObjectTypePtr,
6328 MayBePseudoDestructor);
6329 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006330 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006331
John McCallba7bf592010-08-24 05:47:05 +00006332 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006333 NestedNameSpecifier *Qualifier = E->getQualifier();
6334 if (Qualifier) {
6335 Qualifier
6336 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6337 E->getQualifierRange(),
6338 ObjectType);
6339 if (!Qualifier)
6340 return ExprError();
6341 }
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregor678f90d2010-02-25 01:56:36 +00006343 PseudoDestructorTypeStorage Destroyed;
6344 if (E->getDestroyedTypeInfo()) {
6345 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006346 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6347 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006348 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006349 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006350 Destroyed = DestroyedTypeInfo;
6351 } else if (ObjectType->isDependentType()) {
6352 // We aren't likely to be able to resolve the identifier down to a type
6353 // now anyway, so just retain the identifier.
6354 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6355 E->getDestroyedTypeLoc());
6356 } else {
6357 // Look for a destructor known with the given name.
6358 CXXScopeSpec SS;
6359 if (Qualifier) {
6360 SS.setScopeRep(Qualifier);
6361 SS.setRange(E->getQualifierRange());
6362 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006363
John McCallba7bf592010-08-24 05:47:05 +00006364 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006365 *E->getDestroyedTypeIdentifier(),
6366 E->getDestroyedTypeLoc(),
6367 /*Scope=*/0,
6368 SS, ObjectTypePtr,
6369 false);
6370 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006371 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006372
Douglas Gregor678f90d2010-02-25 01:56:36 +00006373 Destroyed
6374 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6375 E->getDestroyedTypeLoc());
6376 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006377
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006378 TypeSourceInfo *ScopeTypeInfo = 0;
6379 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006380 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006381 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006382 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006383 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006384
John McCallb268a282010-08-23 23:25:46 +00006385 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006386 E->getOperatorLoc(),
6387 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006388 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006389 E->getQualifierRange(),
6390 ScopeTypeInfo,
6391 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006392 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006393 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006394}
Mike Stump11289f42009-09-09 15:08:12 +00006395
Douglas Gregorad8a3362009-09-04 17:36:40 +00006396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006397ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006398TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006399 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006400 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6401
6402 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6403 Sema::LookupOrdinaryName);
6404
6405 // Transform all the decls.
6406 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6407 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006408 NamedDecl *InstD = static_cast<NamedDecl*>(
6409 getDerived().TransformDecl(Old->getNameLoc(),
6410 *I));
John McCall84d87672009-12-10 09:41:52 +00006411 if (!InstD) {
6412 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6413 // This can happen because of dependent hiding.
6414 if (isa<UsingShadowDecl>(*I))
6415 continue;
6416 else
John McCallfaf5fb42010-08-26 23:41:50 +00006417 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006418 }
John McCalle66edc12009-11-24 19:00:30 +00006419
6420 // Expand using declarations.
6421 if (isa<UsingDecl>(InstD)) {
6422 UsingDecl *UD = cast<UsingDecl>(InstD);
6423 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6424 E = UD->shadow_end(); I != E; ++I)
6425 R.addDecl(*I);
6426 continue;
6427 }
6428
6429 R.addDecl(InstD);
6430 }
6431
6432 // Resolve a kind, but don't do any further analysis. If it's
6433 // ambiguous, the callee needs to deal with it.
6434 R.resolveKind();
6435
6436 // Rebuild the nested-name qualifier, if present.
6437 CXXScopeSpec SS;
6438 NestedNameSpecifier *Qualifier = 0;
6439 if (Old->getQualifier()) {
6440 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006441 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006442 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006443 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006444
John McCalle66edc12009-11-24 19:00:30 +00006445 SS.setScopeRep(Qualifier);
6446 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006447 }
6448
Douglas Gregor9262f472010-04-27 18:19:34 +00006449 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006450 CXXRecordDecl *NamingClass
6451 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6452 Old->getNameLoc(),
6453 Old->getNamingClass()));
6454 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006456
Douglas Gregorda7be082010-04-27 16:10:10 +00006457 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006458 }
6459
6460 // If we have no template arguments, it's a normal declaration name.
6461 if (!Old->hasExplicitTemplateArgs())
6462 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6463
6464 // If we have template arguments, rebuild them, then rebuild the
6465 // templateid expression.
6466 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006467 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6468 Old->getNumTemplateArgs(),
6469 TransArgs))
6470 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006471
6472 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6473 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006474}
Mike Stump11289f42009-09-09 15:08:12 +00006475
Douglas Gregora16548e2009-08-11 05:31:07 +00006476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006477ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006478TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006479 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6480 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006484 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006485 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006486
Mike Stump11289f42009-09-09 15:08:12 +00006487 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006489 T,
6490 E->getLocEnd());
6491}
Mike Stump11289f42009-09-09 15:08:12 +00006492
Douglas Gregora16548e2009-08-11 05:31:07 +00006493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006494ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006495TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6496 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6497 if (!LhsT)
6498 return ExprError();
6499
6500 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6501 if (!RhsT)
6502 return ExprError();
6503
6504 if (!getDerived().AlwaysRebuild() &&
6505 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6506 return SemaRef.Owned(E);
6507
6508 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6509 E->getLocStart(),
6510 LhsT, RhsT,
6511 E->getLocEnd());
6512}
6513
6514template<typename Derived>
6515ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006516TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006517 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006518 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006519 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006520 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006523
John McCall31f82722010-11-12 08:19:04 +00006524 // TODO: If this is a conversion-function-id, verify that the
6525 // destination type name (if present) resolves the same way after
6526 // instantiation as it did in the local scope.
6527
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006528 DeclarationNameInfo NameInfo
6529 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6530 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006532
John McCalle66edc12009-11-24 19:00:30 +00006533 if (!E->hasExplicitTemplateArgs()) {
6534 if (!getDerived().AlwaysRebuild() &&
6535 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006536 // Note: it is sufficient to compare the Name component of NameInfo:
6537 // if name has not changed, DNLoc has not changed either.
6538 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006539 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006540
John McCalle66edc12009-11-24 19:00:30 +00006541 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6542 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006543 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006544 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006545 }
John McCall6b51f282009-11-23 01:53:49 +00006546
6547 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006548 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6549 E->getNumTemplateArgs(),
6550 TransArgs))
6551 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006552
John McCalle66edc12009-11-24 19:00:30 +00006553 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6554 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006555 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006556 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006557}
6558
6559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006562 // CXXConstructExprs are always implicit, so when we have a
6563 // 1-argument construction we just transform that argument.
6564 if (E->getNumArgs() == 1 ||
6565 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6566 return getDerived().TransformExpr(E->getArg(0));
6567
Douglas Gregora16548e2009-08-11 05:31:07 +00006568 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6569
6570 QualType T = getDerived().TransformType(E->getType());
6571 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006572 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006573
6574 CXXConstructorDecl *Constructor
6575 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006576 getDerived().TransformDecl(E->getLocStart(),
6577 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006578 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006580
Douglas Gregora16548e2009-08-11 05:31:07 +00006581 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006582 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006583 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6584 &ArgumentChanged))
6585 return ExprError();
6586
Douglas Gregora16548e2009-08-11 05:31:07 +00006587 if (!getDerived().AlwaysRebuild() &&
6588 T == E->getType() &&
6589 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006590 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006591 // Mark the constructor as referenced.
6592 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006593 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006594 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006595 }
Mike Stump11289f42009-09-09 15:08:12 +00006596
Douglas Gregordb121ba2009-12-14 16:27:04 +00006597 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6598 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006599 move_arg(Args),
6600 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006601 E->getConstructionKind(),
6602 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006603}
Mike Stump11289f42009-09-09 15:08:12 +00006604
Douglas Gregora16548e2009-08-11 05:31:07 +00006605/// \brief Transform a C++ temporary-binding expression.
6606///
Douglas Gregor363b1512009-12-24 18:51:59 +00006607/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6608/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006610ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006611TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006612 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006613}
Mike Stump11289f42009-09-09 15:08:12 +00006614
John McCall5d413782010-12-06 08:20:24 +00006615/// \brief Transform a C++ expression that contains cleanups that should
6616/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006617///
John McCall5d413782010-12-06 08:20:24 +00006618/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006619/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006621ExprResult
John McCall5d413782010-12-06 08:20:24 +00006622TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006623 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006624}
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregora16548e2009-08-11 05:31:07 +00006626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006627ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006628TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006629 CXXTemporaryObjectExpr *E) {
6630 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6631 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006633
Douglas Gregora16548e2009-08-11 05:31:07 +00006634 CXXConstructorDecl *Constructor
6635 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006636 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006637 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006638 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006639 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregora16548e2009-08-11 05:31:07 +00006641 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006642 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006644 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6645 &ArgumentChanged))
6646 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006647
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006649 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006650 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006651 !ArgumentChanged) {
6652 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006653 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006654 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006655 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006656
6657 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6658 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006659 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006660 E->getLocEnd());
6661}
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregora16548e2009-08-11 05:31:07 +00006663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006664ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006665TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006666 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006667 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6668 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006670
Douglas Gregora16548e2009-08-11 05:31:07 +00006671 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006672 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006673 Args.reserve(E->arg_size());
6674 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6675 &ArgumentChanged))
6676 return ExprError();
6677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006679 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006681 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006682
Douglas Gregora16548e2009-08-11 05:31:07 +00006683 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006684 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 E->getLParenLoc(),
6686 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 E->getRParenLoc());
6688}
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregora16548e2009-08-11 05:31:07 +00006690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006692TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006693 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006694 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006695 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006696 Expr *OldBase;
6697 QualType BaseType;
6698 QualType ObjectType;
6699 if (!E->isImplicitAccess()) {
6700 OldBase = E->getBase();
6701 Base = getDerived().TransformExpr(OldBase);
6702 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006704
John McCall2d74de92009-12-01 22:10:20 +00006705 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006706 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006707 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006708 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006709 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006710 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006711 ObjectTy,
6712 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006713 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006714 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006715
John McCallba7bf592010-08-24 05:47:05 +00006716 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006717 BaseType = ((Expr*) Base.get())->getType();
6718 } else {
6719 OldBase = 0;
6720 BaseType = getDerived().TransformType(E->getBaseType());
6721 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6722 }
Mike Stump11289f42009-09-09 15:08:12 +00006723
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006724 // Transform the first part of the nested-name-specifier that qualifies
6725 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006726 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006727 = getDerived().TransformFirstQualifierInScope(
6728 E->getFirstQualifierFoundInScope(),
6729 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006730
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006731 NestedNameSpecifier *Qualifier = 0;
6732 if (E->getQualifier()) {
6733 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6734 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006735 ObjectType,
6736 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006737 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006738 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006739 }
Mike Stump11289f42009-09-09 15:08:12 +00006740
John McCall31f82722010-11-12 08:19:04 +00006741 // TODO: If this is a conversion-function-id, verify that the
6742 // destination type name (if present) resolves the same way after
6743 // instantiation as it did in the local scope.
6744
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006745 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006746 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006747 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006749
John McCall2d74de92009-12-01 22:10:20 +00006750 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006751 // This is a reference to a member without an explicitly-specified
6752 // template argument list. Optimize for this common case.
6753 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006754 Base.get() == OldBase &&
6755 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006756 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006757 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006758 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006759 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006760
John McCallb268a282010-08-23 23:25:46 +00006761 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006762 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006763 E->isArrow(),
6764 E->getOperatorLoc(),
6765 Qualifier,
6766 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006767 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006768 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006769 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006770 }
6771
John McCall6b51f282009-11-23 01:53:49 +00006772 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006773 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6774 E->getNumTemplateArgs(),
6775 TransArgs))
6776 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006777
John McCallb268a282010-08-23 23:25:46 +00006778 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006779 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006780 E->isArrow(),
6781 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006782 Qualifier,
6783 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006784 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006785 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006786 &TransArgs);
6787}
6788
6789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006791TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006792 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006793 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006794 QualType BaseType;
6795 if (!Old->isImplicitAccess()) {
6796 Base = getDerived().TransformExpr(Old->getBase());
6797 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006798 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006799 BaseType = ((Expr*) Base.get())->getType();
6800 } else {
6801 BaseType = getDerived().TransformType(Old->getBaseType());
6802 }
John McCall10eae182009-11-30 22:42:35 +00006803
6804 NestedNameSpecifier *Qualifier = 0;
6805 if (Old->getQualifier()) {
6806 Qualifier
6807 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006808 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006809 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006811 }
6812
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006813 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006814 Sema::LookupOrdinaryName);
6815
6816 // Transform all the decls.
6817 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6818 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006819 NamedDecl *InstD = static_cast<NamedDecl*>(
6820 getDerived().TransformDecl(Old->getMemberLoc(),
6821 *I));
John McCall84d87672009-12-10 09:41:52 +00006822 if (!InstD) {
6823 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6824 // This can happen because of dependent hiding.
6825 if (isa<UsingShadowDecl>(*I))
6826 continue;
6827 else
John McCallfaf5fb42010-08-26 23:41:50 +00006828 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006829 }
John McCall10eae182009-11-30 22:42:35 +00006830
6831 // Expand using declarations.
6832 if (isa<UsingDecl>(InstD)) {
6833 UsingDecl *UD = cast<UsingDecl>(InstD);
6834 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6835 E = UD->shadow_end(); I != E; ++I)
6836 R.addDecl(*I);
6837 continue;
6838 }
6839
6840 R.addDecl(InstD);
6841 }
6842
6843 R.resolveKind();
6844
Douglas Gregor9262f472010-04-27 18:19:34 +00006845 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006846 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006847 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006848 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006849 Old->getMemberLoc(),
6850 Old->getNamingClass()));
6851 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006852 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006853
Douglas Gregorda7be082010-04-27 16:10:10 +00006854 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006855 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006856
John McCall10eae182009-11-30 22:42:35 +00006857 TemplateArgumentListInfo TransArgs;
6858 if (Old->hasExplicitTemplateArgs()) {
6859 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6860 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006861 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6862 Old->getNumTemplateArgs(),
6863 TransArgs))
6864 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006865 }
John McCall38836f02010-01-15 08:34:02 +00006866
6867 // FIXME: to do this check properly, we will need to preserve the
6868 // first-qualifier-in-scope here, just in case we had a dependent
6869 // base (and therefore couldn't do the check) and a
6870 // nested-name-qualifier (and therefore could do the lookup).
6871 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006872
John McCallb268a282010-08-23 23:25:46 +00006873 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006874 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006875 Old->getOperatorLoc(),
6876 Old->isArrow(),
6877 Qualifier,
6878 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006879 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006880 R,
6881 (Old->hasExplicitTemplateArgs()
6882 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006883}
6884
6885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006886ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006887TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6888 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6889 if (SubExpr.isInvalid())
6890 return ExprError();
6891
6892 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006893 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006894
6895 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6896}
6897
6898template<typename Derived>
6899ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006900TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006901 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6902 if (Pattern.isInvalid())
6903 return ExprError();
6904
6905 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6906 return SemaRef.Owned(E);
6907
Douglas Gregorb8840002011-01-14 21:20:45 +00006908 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6909 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006910}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006911
6912template<typename Derived>
6913ExprResult
6914TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6915 // If E is not value-dependent, then nothing will change when we transform it.
6916 // Note: This is an instantiation-centric view.
6917 if (!E->isValueDependent())
6918 return SemaRef.Owned(E);
6919
6920 // Note: None of the implementations of TryExpandParameterPacks can ever
6921 // produce a diagnostic when given only a single unexpanded parameter pack,
6922 // so
6923 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6924 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006925 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006926 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006927 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6928 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006929 ShouldExpand, RetainExpansion,
6930 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006931 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006932
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006933 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006934 return SemaRef.Owned(E);
6935
6936 // We now know the length of the parameter pack, so build a new expression
6937 // that stores that length.
6938 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6939 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006940 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006941}
6942
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006943template<typename Derived>
6944ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00006945TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6946 SubstNonTypeTemplateParmPackExpr *E) {
6947 // Default behavior is to do nothing with this transformation.
6948 return SemaRef.Owned(E);
6949}
6950
6951template<typename Derived>
6952ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006953TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006954 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006955}
6956
Mike Stump11289f42009-09-09 15:08:12 +00006957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006959TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006960 TypeSourceInfo *EncodedTypeInfo
6961 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6962 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006963 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006964
Douglas Gregora16548e2009-08-11 05:31:07 +00006965 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006966 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006967 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006968
6969 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006970 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006971 E->getRParenLoc());
6972}
Mike Stump11289f42009-09-09 15:08:12 +00006973
Douglas Gregora16548e2009-08-11 05:31:07 +00006974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006977 // Transform arguments.
6978 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006979 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006980 Args.reserve(E->getNumArgs());
6981 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6982 &ArgChanged))
6983 return ExprError();
6984
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006985 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6986 // Class message: transform the receiver type.
6987 TypeSourceInfo *ReceiverTypeInfo
6988 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6989 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006990 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006991
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006992 // If nothing changed, just retain the existing message send.
6993 if (!getDerived().AlwaysRebuild() &&
6994 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006995 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006996
6997 // Build a new class message send.
6998 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6999 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007000 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007001 E->getMethodDecl(),
7002 E->getLeftLoc(),
7003 move_arg(Args),
7004 E->getRightLoc());
7005 }
7006
7007 // Instance message: transform the receiver
7008 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7009 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007010 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007011 = getDerived().TransformExpr(E->getInstanceReceiver());
7012 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007013 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007014
7015 // If nothing changed, just retain the existing message send.
7016 if (!getDerived().AlwaysRebuild() &&
7017 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007018 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007019
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007020 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007021 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007022 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007023 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007024 E->getMethodDecl(),
7025 E->getLeftLoc(),
7026 move_arg(Args),
7027 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007028}
7029
Mike Stump11289f42009-09-09 15:08:12 +00007030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007031ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007032TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007033 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007034}
7035
Mike Stump11289f42009-09-09 15:08:12 +00007036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007038TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007039 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007040}
7041
Mike Stump11289f42009-09-09 15:08:12 +00007042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007044TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007045 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007046 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007047 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007048 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007049
7050 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007051
Douglas Gregord51d90d2010-04-26 20:11:03 +00007052 // If nothing changed, just retain the existing expression.
7053 if (!getDerived().AlwaysRebuild() &&
7054 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007055 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007056
John McCallb268a282010-08-23 23:25:46 +00007057 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007058 E->getLocation(),
7059 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007060}
7061
Mike Stump11289f42009-09-09 15:08:12 +00007062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007063ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007064TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007065 // 'super' and types never change. Property never changes. Just
7066 // retain the existing expression.
7067 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007068 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007069
Douglas Gregor9faee212010-04-26 20:47:02 +00007070 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007071 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007072 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007073 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007074
Douglas Gregor9faee212010-04-26 20:47:02 +00007075 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007076
Douglas Gregor9faee212010-04-26 20:47:02 +00007077 // If nothing changed, just retain the existing expression.
7078 if (!getDerived().AlwaysRebuild() &&
7079 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007081
John McCallb7bd14f2010-12-02 01:19:52 +00007082 if (E->isExplicitProperty())
7083 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7084 E->getExplicitProperty(),
7085 E->getLocation());
7086
7087 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7088 E->getType(),
7089 E->getImplicitPropertyGetter(),
7090 E->getImplicitPropertySetter(),
7091 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007092}
7093
Mike Stump11289f42009-09-09 15:08:12 +00007094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007097 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007098 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007099 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007100 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007101
Douglas Gregord51d90d2010-04-26 20:11:03 +00007102 // If nothing changed, just retain the existing expression.
7103 if (!getDerived().AlwaysRebuild() &&
7104 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007105 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007106
John McCallb268a282010-08-23 23:25:46 +00007107 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007108 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007109}
7110
Mike Stump11289f42009-09-09 15:08:12 +00007111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007113TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007114 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007115 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007116 SubExprs.reserve(E->getNumSubExprs());
7117 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7118 SubExprs, &ArgumentChanged))
7119 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007120
Douglas Gregora16548e2009-08-11 05:31:07 +00007121 if (!getDerived().AlwaysRebuild() &&
7122 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007123 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007124
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7126 move_arg(SubExprs),
7127 E->getRParenLoc());
7128}
7129
Mike Stump11289f42009-09-09 15:08:12 +00007130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007132TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007133 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007134
John McCall490112f2011-02-04 18:33:18 +00007135 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7136 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7137
7138 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7139 llvm::SmallVector<ParmVarDecl*, 4> params;
7140 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007141
7142 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007143 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7144 oldBlock->param_begin(),
7145 oldBlock->param_size(),
7146 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007147 return true;
John McCall490112f2011-02-04 18:33:18 +00007148
7149 const FunctionType *exprFunctionType = E->getFunctionType();
7150 QualType exprResultType = exprFunctionType->getResultType();
7151 if (!exprResultType.isNull()) {
7152 if (!exprResultType->isDependentType())
7153 blockScope->ReturnType = exprResultType;
7154 else if (exprResultType != getSema().Context.DependentTy)
7155 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007156 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007157
7158 // If the return type has not been determined yet, leave it as a dependent
7159 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007160 if (blockScope->ReturnType.isNull())
7161 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007162
7163 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007164 if (blockScope->ReturnType->isObjCObjectType()) {
7165 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007166 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007167 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007168 return ExprError();
7169 }
John McCall3882ace2011-01-05 12:14:39 +00007170
John McCall490112f2011-02-04 18:33:18 +00007171 QualType functionType = getDerived().RebuildFunctionProtoType(
7172 blockScope->ReturnType,
7173 paramTypes.data(),
7174 paramTypes.size(),
7175 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007176 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007177 exprFunctionType->getExtInfo());
7178 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007179
7180 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007181 if (!params.empty())
7182 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007183
7184 // If the return type wasn't explicitly set, it will have been marked as a
7185 // dependent type (DependentTy); clear out the return type setting so
7186 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007187 if (blockScope->ReturnType == getSema().Context.DependentTy)
7188 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007189
John McCall3882ace2011-01-05 12:14:39 +00007190 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007191 StmtResult body = getDerived().TransformStmt(E->getBody());
7192 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007193 return ExprError();
7194
John McCall490112f2011-02-04 18:33:18 +00007195#ifndef NDEBUG
7196 // In builds with assertions, make sure that we captured everything we
7197 // captured before.
7198
7199 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7200
7201 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7202 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007203 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007204
7205 // Ignore parameter packs.
7206 if (isa<ParmVarDecl>(oldCapture) &&
7207 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7208 continue;
7209
7210 VarDecl *newCapture =
7211 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7212 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007213 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007214 }
7215#endif
7216
7217 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7218 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007219}
7220
Mike Stump11289f42009-09-09 15:08:12 +00007221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007223TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007224 NestedNameSpecifier *Qualifier = 0;
7225
7226 ValueDecl *ND
7227 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7228 E->getDecl()));
7229 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007230 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007231
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007232 if (!getDerived().AlwaysRebuild() &&
7233 ND == E->getDecl()) {
7234 // Mark it referenced in the new context regardless.
7235 // FIXME: this is a bit instantiation-specific.
7236 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7237
John McCallc3007a22010-10-26 07:05:15 +00007238 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007239 }
7240
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007241 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007242 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007243 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007244}
Mike Stump11289f42009-09-09 15:08:12 +00007245
Douglas Gregora16548e2009-08-11 05:31:07 +00007246//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007247// Type reconstruction
7248//===----------------------------------------------------------------------===//
7249
Mike Stump11289f42009-09-09 15:08:12 +00007250template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007251QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7252 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007253 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007254 getDerived().getBaseEntity());
7255}
7256
Mike Stump11289f42009-09-09 15:08:12 +00007257template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007258QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7259 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007260 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007261 getDerived().getBaseEntity());
7262}
7263
Mike Stump11289f42009-09-09 15:08:12 +00007264template<typename Derived>
7265QualType
John McCall70dd5f62009-10-30 00:06:24 +00007266TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7267 bool WrittenAsLValue,
7268 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007269 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007270 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007271}
7272
7273template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007274QualType
John McCall70dd5f62009-10-30 00:06:24 +00007275TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7276 QualType ClassType,
7277 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007278 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007279 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007280}
7281
7282template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007283QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007284TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7285 ArrayType::ArraySizeModifier SizeMod,
7286 const llvm::APInt *Size,
7287 Expr *SizeExpr,
7288 unsigned IndexTypeQuals,
7289 SourceRange BracketsRange) {
7290 if (SizeExpr || !Size)
7291 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7292 IndexTypeQuals, BracketsRange,
7293 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007294
7295 QualType Types[] = {
7296 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7297 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7298 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007299 };
7300 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7301 QualType SizeType;
7302 for (unsigned I = 0; I != NumTypes; ++I)
7303 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7304 SizeType = Types[I];
7305 break;
7306 }
Mike Stump11289f42009-09-09 15:08:12 +00007307
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007308 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7309 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007310 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007311 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007312 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007313}
Mike Stump11289f42009-09-09 15:08:12 +00007314
Douglas Gregord6ff3322009-08-04 16:50:30 +00007315template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007316QualType
7317TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007318 ArrayType::ArraySizeModifier SizeMod,
7319 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007320 unsigned IndexTypeQuals,
7321 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007322 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007323 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007324}
7325
7326template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007327QualType
Mike Stump11289f42009-09-09 15:08:12 +00007328TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007329 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007330 unsigned IndexTypeQuals,
7331 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007332 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007333 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007334}
Mike Stump11289f42009-09-09 15:08:12 +00007335
Douglas Gregord6ff3322009-08-04 16:50:30 +00007336template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007337QualType
7338TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007339 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007340 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007341 unsigned IndexTypeQuals,
7342 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007343 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007344 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007345 IndexTypeQuals, BracketsRange);
7346}
7347
7348template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007349QualType
7350TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007351 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007352 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007353 unsigned IndexTypeQuals,
7354 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007355 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007356 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007357 IndexTypeQuals, BracketsRange);
7358}
7359
7360template<typename Derived>
7361QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007362 unsigned NumElements,
7363 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007364 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007365 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregord6ff3322009-08-04 16:50:30 +00007368template<typename Derived>
7369QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7370 unsigned NumElements,
7371 SourceLocation AttributeLoc) {
7372 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7373 NumElements, true);
7374 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007375 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7376 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007377 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007378}
Mike Stump11289f42009-09-09 15:08:12 +00007379
Douglas Gregord6ff3322009-08-04 16:50:30 +00007380template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007381QualType
7382TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007383 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007384 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007385 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007386}
Mike Stump11289f42009-09-09 15:08:12 +00007387
Douglas Gregord6ff3322009-08-04 16:50:30 +00007388template<typename Derived>
7389QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007390 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007391 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007392 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007393 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007394 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007395 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007396 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007397 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007398 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007399 getDerived().getBaseEntity(),
7400 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007401}
Mike Stump11289f42009-09-09 15:08:12 +00007402
Douglas Gregord6ff3322009-08-04 16:50:30 +00007403template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007404QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7405 return SemaRef.Context.getFunctionNoProtoType(T);
7406}
7407
7408template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007409QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7410 assert(D && "no decl found");
7411 if (D->isInvalidDecl()) return QualType();
7412
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007413 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007414 TypeDecl *Ty;
7415 if (isa<UsingDecl>(D)) {
7416 UsingDecl *Using = cast<UsingDecl>(D);
7417 assert(Using->isTypeName() &&
7418 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7419
7420 // A valid resolved using typename decl points to exactly one type decl.
7421 assert(++Using->shadow_begin() == Using->shadow_end());
7422 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007423
John McCallb96ec562009-12-04 22:46:56 +00007424 } else {
7425 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7426 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7427 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7428 }
7429
7430 return SemaRef.Context.getTypeDeclType(Ty);
7431}
7432
7433template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007434QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7435 SourceLocation Loc) {
7436 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007437}
7438
7439template<typename Derived>
7440QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7441 return SemaRef.Context.getTypeOfType(Underlying);
7442}
7443
7444template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007445QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7446 SourceLocation Loc) {
7447 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007448}
7449
7450template<typename Derived>
7451QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007452 TemplateName Template,
7453 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007454 const TemplateArgumentListInfo &TemplateArgs) {
7455 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007456}
Mike Stump11289f42009-09-09 15:08:12 +00007457
Douglas Gregor1135c352009-08-06 05:28:30 +00007458template<typename Derived>
7459NestedNameSpecifier *
7460TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7461 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007462 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007463 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007464 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007465 CXXScopeSpec SS;
7466 // FIXME: The source location information is all wrong.
7467 SS.setRange(Range);
7468 SS.setScopeRep(Prefix);
7469 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007470 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007471 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007472 ObjectType,
7473 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007474 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007475}
7476
7477template<typename Derived>
7478NestedNameSpecifier *
7479TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7480 SourceRange Range,
7481 NamespaceDecl *NS) {
7482 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7483}
7484
7485template<typename Derived>
7486NestedNameSpecifier *
7487TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7488 SourceRange Range,
7489 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007490 QualType T) {
7491 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007492 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007493 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007494 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7495 T.getTypePtr());
7496 }
Mike Stump11289f42009-09-09 15:08:12 +00007497
Douglas Gregor1135c352009-08-06 05:28:30 +00007498 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7499 return 0;
7500}
Mike Stump11289f42009-09-09 15:08:12 +00007501
Douglas Gregor71dc5092009-08-06 06:41:21 +00007502template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007503TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007504TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7505 bool TemplateKW,
7506 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007507 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007508 Template);
7509}
7510
7511template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007512TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007513TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007514 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007515 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007516 QualType ObjectType,
7517 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007518 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007519 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007520 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007521 UnqualifiedId Name;
7522 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007523 Sema::TemplateTy Template;
7524 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7525 /*FIXME:*/getDerived().getBaseLocation(),
7526 SS,
7527 Name,
John McCallba7bf592010-08-24 05:47:05 +00007528 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007529 /*EnteringContext=*/false,
7530 Template);
John McCall31f82722010-11-12 08:19:04 +00007531 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007532}
Mike Stump11289f42009-09-09 15:08:12 +00007533
Douglas Gregora16548e2009-08-11 05:31:07 +00007534template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007535TemplateName
7536TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7537 OverloadedOperatorKind Operator,
7538 QualType ObjectType) {
7539 CXXScopeSpec SS;
7540 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7541 SS.setScopeRep(Qualifier);
7542 UnqualifiedId Name;
7543 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7544 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7545 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007546 Sema::TemplateTy Template;
7547 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007548 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007549 SS,
7550 Name,
John McCallba7bf592010-08-24 05:47:05 +00007551 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007552 /*EnteringContext=*/false,
7553 Template);
7554 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007555}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007556
Douglas Gregor71395fa2009-11-04 00:56:37 +00007557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007558ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007559TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7560 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007561 Expr *OrigCallee,
7562 Expr *First,
7563 Expr *Second) {
7564 Expr *Callee = OrigCallee->IgnoreParenCasts();
7565 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007566
Douglas Gregora16548e2009-08-11 05:31:07 +00007567 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007568 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007569 if (!First->getType()->isOverloadableType() &&
7570 !Second->getType()->isOverloadableType())
7571 return getSema().CreateBuiltinArraySubscriptExpr(First,
7572 Callee->getLocStart(),
7573 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007574 } else if (Op == OO_Arrow) {
7575 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007576 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7577 } else if (Second == 0 || isPostIncDec) {
7578 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 // The argument is not of overloadable type, so try to create a
7580 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007581 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007582 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007583
John McCallb268a282010-08-23 23:25:46 +00007584 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007585 }
7586 } else {
John McCallb268a282010-08-23 23:25:46 +00007587 if (!First->getType()->isOverloadableType() &&
7588 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007589 // Neither of the arguments is an overloadable type, so try to
7590 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007591 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007592 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007593 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007596
Douglas Gregora16548e2009-08-11 05:31:07 +00007597 return move(Result);
7598 }
7599 }
Mike Stump11289f42009-09-09 15:08:12 +00007600
7601 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007602 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007603 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007604
John McCallb268a282010-08-23 23:25:46 +00007605 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007606 assert(ULE->requiresADL());
7607
7608 // FIXME: Do we have to check
7609 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007610 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007611 } else {
John McCallb268a282010-08-23 23:25:46 +00007612 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007613 }
Mike Stump11289f42009-09-09 15:08:12 +00007614
Douglas Gregora16548e2009-08-11 05:31:07 +00007615 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007616 Expr *Args[2] = { First, Second };
7617 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007618
Douglas Gregora16548e2009-08-11 05:31:07 +00007619 // Create the overloaded operator invocation for unary operators.
7620 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007621 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007622 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007623 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007624 }
Mike Stump11289f42009-09-09 15:08:12 +00007625
Sebastian Redladba46e2009-10-29 20:17:01 +00007626 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007627 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007628 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007629 First,
7630 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007631
Douglas Gregora16548e2009-08-11 05:31:07 +00007632 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007633 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007634 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007635 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7636 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007638
Mike Stump11289f42009-09-09 15:08:12 +00007639 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007640}
Mike Stump11289f42009-09-09 15:08:12 +00007641
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007643ExprResult
John McCallb268a282010-08-23 23:25:46 +00007644TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007645 SourceLocation OperatorLoc,
7646 bool isArrow,
7647 NestedNameSpecifier *Qualifier,
7648 SourceRange QualifierRange,
7649 TypeSourceInfo *ScopeType,
7650 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007651 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007652 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007653 CXXScopeSpec SS;
7654 if (Qualifier) {
7655 SS.setRange(QualifierRange);
7656 SS.setScopeRep(Qualifier);
7657 }
7658
John McCallb268a282010-08-23 23:25:46 +00007659 QualType BaseType = Base->getType();
7660 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007661 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007662 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007663 !BaseType->getAs<PointerType>()->getPointeeType()
7664 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007665 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007666 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007667 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007668 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007669 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007670 /*FIXME?*/true);
7671 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007672
Douglas Gregor678f90d2010-02-25 01:56:36 +00007673 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007674 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7675 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7676 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7677 NameInfo.setNamedTypeInfo(DestroyedType);
7678
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007679 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007680
John McCallb268a282010-08-23 23:25:46 +00007681 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007682 OperatorLoc, isArrow,
7683 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007684 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007685 /*TemplateArgs*/ 0);
7686}
7687
Douglas Gregord6ff3322009-08-04 16:50:30 +00007688} // end namespace clang
7689
7690#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H