blob: 1cb24e70bf62dfdbaacd119dd9fdcc99a930823c [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();
172 Self.getDerived().setBase(Location, Entity);
173 }
Mike Stump11289f42009-09-09 15:08:12 +0000174
Douglas Gregora16548e2009-08-11 05:31:07 +0000175 ~TemporaryBase() {
176 Self.getDerived().setBase(OldLocation, OldEntity);
177 }
178 };
Mike Stump11289f42009-09-09 15:08:12 +0000179
180 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000181 /// transformed.
182 ///
183 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000184 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// not change. For example, template instantiation need not traverse
186 /// non-dependent types.
187 bool AlreadyTransformed(QualType T) {
188 return T.isNull();
189 }
190
Douglas Gregord196a582009-12-14 19:27:10 +0000191 /// \brief Determine whether the given call argument should be dropped, e.g.,
192 /// because it is a default argument.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine to
195 /// determine which kinds of call arguments get dropped. By default,
196 /// CXXDefaultArgument nodes are dropped (prior to transformation).
197 bool DropCallArgument(Expr *E) {
198 return E->isDefaultArgument();
199 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000200
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000201 /// \brief Determine whether we should expand a pack expansion with the
202 /// given set of parameter packs into separate arguments by repeatedly
203 /// transforming the pattern.
204 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000205 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// Subclasses can override this routine to provide different behavior.
207 ///
208 /// \param EllipsisLoc The location of the ellipsis that identifies the
209 /// pack expansion.
210 ///
211 /// \param PatternRange The source range that covers the entire pattern of
212 /// the pack expansion.
213 ///
214 /// \param Unexpanded The set of unexpanded parameter packs within the
215 /// pattern.
216 ///
217 /// \param NumUnexpanded The number of unexpanded parameter packs in
218 /// \p Unexpanded.
219 ///
220 /// \param ShouldExpand Will be set to \c true if the transformer should
221 /// expand the corresponding pack expansions into separate arguments. When
222 /// set, \c NumExpansions must also be set.
223 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000224 /// \param RetainExpansion Whether the caller should add an unexpanded
225 /// pack expansion after all of the expanded arguments. This is used
226 /// when extending explicitly-specified template argument packs per
227 /// C++0x [temp.arg.explicit]p9.
228 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000230 /// the expanded form of the corresponding pack expansion. This is both an
231 /// input and an output parameter, which can be set by the caller if the
232 /// number of expansions is known a priori (e.g., due to a prior substitution)
233 /// and will be set by the callee when the number of expansions is known.
234 /// The callee must set this value when \c ShouldExpand is \c true; it may
235 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000236 ///
237 /// \returns true if an error occurred (e.g., because the parameter packs
238 /// are to be instantiated with arguments of different lengths), false
239 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
240 /// must be set.
241 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
242 SourceRange PatternRange,
243 const UnexpandedParameterPack *Unexpanded,
244 unsigned NumUnexpanded,
245 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000246 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000247 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ShouldExpand = false;
249 return false;
250 }
251
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000252 /// \brief "Forget" about the partially-substituted pack template argument,
253 /// when performing an instantiation that must preserve the parameter pack
254 /// use.
255 ///
256 /// This routine is meant to be overridden by the template instantiator.
257 TemplateArgument ForgetPartiallySubstitutedPack() {
258 return TemplateArgument();
259 }
260
261 /// \brief "Remember" the partially-substituted pack template argument
262 /// after performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
267
Douglas Gregorf3010112011-01-07 16:43:16 +0000268 /// \brief Note to the derived class when a function parameter pack is
269 /// being expanded.
270 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
271
Douglas Gregord6ff3322009-08-04 16:50:30 +0000272 /// \brief Transforms the given type into another type.
273 ///
John McCall550e0c22009-10-21 00:40:46 +0000274 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000275 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000276 /// function. This is expensive, but we don't mind, because
277 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000278 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000279 ///
280 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000281 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000282
John McCall550e0c22009-10-21 00:40:46 +0000283 /// \brief Transforms the given type-with-location into a new
284 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000285 ///
John McCall550e0c22009-10-21 00:40:46 +0000286 /// By default, this routine transforms a type by delegating to the
287 /// appropriate TransformXXXType to build a new type. Subclasses
288 /// may override this function (to take over all type
289 /// transformations) or some set of the TransformXXXType functions
290 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000291 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000292
293 /// \brief Transform the given type-with-location into a new
294 /// type, collecting location information in the given builder
295 /// as necessary.
296 ///
John McCall31f82722010-11-12 08:19:04 +0000297 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000298
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000299 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000300 ///
Mike Stump11289f42009-09-09 15:08:12 +0000301 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000302 /// appropriate TransformXXXStmt function to transform a specific kind of
303 /// statement or the TransformExpr() function to transform an expression.
304 /// Subclasses may override this function to transform statements using some
305 /// other mechanism.
306 ///
307 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000308 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given expression.
311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000312 /// By default, this routine transforms an expression by delegating to the
313 /// appropriate TransformXXXExpr function to build a new expression.
314 /// Subclasses may override this function to transform expressions using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000318 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Douglas Gregora3efea12011-01-03 19:04:46 +0000320 /// \brief Transform the given list of expressions.
321 ///
322 /// This routine transforms a list of expressions by invoking
323 /// \c TransformExpr() for each subexpression. However, it also provides
324 /// support for variadic templates by expanding any pack expansions (if the
325 /// derived class permits such expansion) along the way. When pack expansions
326 /// are present, the number of outputs may not equal the number of inputs.
327 ///
328 /// \param Inputs The set of expressions to be transformed.
329 ///
330 /// \param NumInputs The number of expressions in \c Inputs.
331 ///
332 /// \param IsCall If \c true, then this transform is being performed on
333 /// function-call arguments, and any arguments that should be dropped, will
334 /// be.
335 ///
336 /// \param Outputs The transformed input expressions will be added to this
337 /// vector.
338 ///
339 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
340 /// due to transformation.
341 ///
342 /// \returns true if an error occurred, false otherwise.
343 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
344 llvm::SmallVectorImpl<Expr *> &Outputs,
345 bool *ArgChanged = 0);
346
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 /// \brief Transform the given declaration, which is referenced from a type
348 /// or expression.
349 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000350 /// By default, acts as the identity function on declarations. Subclasses
351 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000352 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000353
354 /// \brief Transform the definition of the given declaration.
355 ///
Mike Stump11289f42009-09-09 15:08:12 +0000356 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000357 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000358 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
359 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000360 }
Mike Stump11289f42009-09-09 15:08:12 +0000361
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000362 /// \brief Transform the given declaration, which was the first part of a
363 /// nested-name-specifier in a member access expression.
364 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000365 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// identifier in a nested-name-specifier of a member access expression, e.g.,
367 /// the \c T in \c x->T::member
368 ///
369 /// By default, invokes TransformDecl() to transform the declaration.
370 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000371 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
372 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374
Douglas Gregord6ff3322009-08-04 16:50:30 +0000375 /// \brief Transform the given nested-name-specifier.
376 ///
Mike Stump11289f42009-09-09 15:08:12 +0000377 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000378 /// nested-name-specifier. Subclasses may override this function to provide
379 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000380 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000381 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000382 QualType ObjectType = QualType(),
383 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000384
Douglas Gregorf816bd72009-09-03 22:13:48 +0000385 /// \brief Transform the given declaration name.
386 ///
387 /// By default, transforms the types of conversion function, constructor,
388 /// and destructor names and then (if needed) rebuilds the declaration name.
389 /// Identifiers and selectors are returned unmodified. Sublcasses may
390 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000391 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000392 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000395 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000396 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000397 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000398 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000399 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000400 QualType ObjectType = QualType(),
401 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000402
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403 /// \brief Transform the given template argument.
404 ///
Mike Stump11289f42009-09-09 15:08:12 +0000405 /// By default, this operation transforms the type, expression, or
406 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000407 /// new template argument from the transformed result. Subclasses may
408 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000409 ///
410 /// Returns true if there was an error.
411 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
412 TemplateArgumentLoc &Output);
413
Douglas Gregor62e06f22010-12-20 17:31:10 +0000414 /// \brief Transform the given set of template arguments.
415 ///
416 /// By default, this operation transforms all of the template arguments
417 /// in the input set using \c TransformTemplateArgument(), and appends
418 /// the transformed arguments to the output list.
419 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000420 /// Note that this overload of \c TransformTemplateArguments() is merely
421 /// a convenience function. Subclasses that wish to override this behavior
422 /// should override the iterator-based member template version.
423 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000424 /// \param Inputs The set of template arguments to be transformed.
425 ///
426 /// \param NumInputs The number of template arguments in \p Inputs.
427 ///
428 /// \param Outputs The set of transformed template arguments output by this
429 /// routine.
430 ///
431 /// Returns true if an error occurred.
432 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
433 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 TemplateArgumentListInfo &Outputs) {
435 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
436 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000437
438 /// \brief Transform the given set of template arguments.
439 ///
440 /// By default, this operation transforms all of the template arguments
441 /// in the input set using \c TransformTemplateArgument(), and appends
442 /// the transformed arguments to the output list.
443 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000444 /// \param First An iterator to the first template argument.
445 ///
446 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000447 ///
448 /// \param Outputs The set of transformed template arguments output by this
449 /// routine.
450 ///
451 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000452 template<typename InputIterator>
453 bool TransformTemplateArguments(InputIterator First,
454 InputIterator Last,
455 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000456
John McCall0ad16662009-10-29 08:12:44 +0000457 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
458 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
459 TemplateArgumentLoc &ArgLoc);
460
John McCallbcd03502009-12-07 02:54:59 +0000461 /// \brief Fakes up a TypeSourceInfo for a type.
462 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
463 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000464 getDerived().getBaseLocation());
465 }
Mike Stump11289f42009-09-09 15:08:12 +0000466
John McCall550e0c22009-10-21 00:40:46 +0000467#define ABSTRACT_TYPELOC(CLASS, PARENT)
468#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000469 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000470#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471
John McCall31f82722010-11-12 08:19:04 +0000472 QualType
473 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
474 TemplateSpecializationTypeLoc TL,
475 TemplateName Template);
476
477 QualType
478 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
479 DependentTemplateSpecializationTypeLoc TL,
480 NestedNameSpecifier *Prefix);
481
John McCall58f10c32010-03-11 09:03:00 +0000482 /// \brief Transforms the parameters of a function type into the
483 /// given vectors.
484 ///
485 /// The result vectors should be kept in sync; null entries in the
486 /// variables vector are acceptable.
487 ///
488 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000489 bool TransformFunctionTypeParams(SourceLocation Loc,
490 ParmVarDecl **Params, unsigned NumParams,
491 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000492 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000493 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000494
495 /// \brief Transforms a single function-type parameter. Return null
496 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000497 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
498 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000499
John McCall31f82722010-11-12 08:19:04 +0000500 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000501
John McCalldadc5752010-08-24 06:29:42 +0000502 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
503 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000504
Douglas Gregorebe10102009-08-20 07:17:43 +0000505#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000506 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000507#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000508 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000509#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000510#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new pointer type given its pointee type.
513 ///
514 /// By default, performs semantic analysis when building the pointer type.
515 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000516 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517
518 /// \brief Build a new block pointer type given its pointee type.
519 ///
Mike Stump11289f42009-09-09 15:08:12 +0000520 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000522 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523
John McCall70dd5f62009-10-30 00:06:24 +0000524 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 ///
John McCall70dd5f62009-10-30 00:06:24 +0000526 /// By default, performs semantic analysis when building the
527 /// reference type. Subclasses may override this routine to provide
528 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 ///
John McCall70dd5f62009-10-30 00:06:24 +0000530 /// \param LValue whether the type was written with an lvalue sigil
531 /// or an rvalue sigil.
532 QualType RebuildReferenceType(QualType ReferentType,
533 bool LValue,
534 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// \brief Build a new member pointer type given the pointee type and the
537 /// class type it refers into.
538 ///
539 /// By default, performs semantic analysis when building the member pointer
540 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000541 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
542 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000543
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 /// \brief Build a new array type given the element type, size
545 /// modifier, size of the array (if known), size expression, and index type
546 /// qualifiers.
547 ///
548 /// By default, performs semantic analysis when building the array type.
549 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000550 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000551 QualType RebuildArrayType(QualType ElementType,
552 ArrayType::ArraySizeModifier SizeMod,
553 const llvm::APInt *Size,
554 Expr *SizeExpr,
555 unsigned IndexTypeQuals,
556 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000557
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558 /// \brief Build a new constant array type given the element type, size
559 /// modifier, (known) size of the array, and index type qualifiers.
560 ///
561 /// By default, performs semantic analysis when building the array type.
562 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000563 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ArrayType::ArraySizeModifier SizeMod,
565 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000566 unsigned IndexTypeQuals,
567 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568
Douglas Gregord6ff3322009-08-04 16:50:30 +0000569 /// \brief Build a new incomplete array type given the element type, size
570 /// modifier, and index type qualifiers.
571 ///
572 /// By default, performs semantic analysis when building the array type.
573 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000574 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000575 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000576 unsigned IndexTypeQuals,
577 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Mike Stump11289f42009-09-09 15:08:12 +0000579 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000580 /// size modifier, size expression, and index type qualifiers.
581 ///
582 /// By default, performs semantic analysis when building the array type.
583 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000584 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000585 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000586 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587 unsigned IndexTypeQuals,
588 SourceRange BracketsRange);
589
Mike Stump11289f42009-09-09 15:08:12 +0000590 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000591 /// size modifier, size expression, and index type qualifiers.
592 ///
593 /// By default, performs semantic analysis when building the array type.
594 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000595 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000596 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000597 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000598 unsigned IndexTypeQuals,
599 SourceRange BracketsRange);
600
601 /// \brief Build a new vector type given the element type and
602 /// number of elements.
603 ///
604 /// By default, performs semantic analysis when building the vector type.
605 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000606 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000607 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000608
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609 /// \brief Build a new extended vector type given the element type and
610 /// number of elements.
611 ///
612 /// By default, performs semantic analysis when building the vector type.
613 /// Subclasses may override this routine to provide different behavior.
614 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
615 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000616
617 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000618 /// given the element type and number of elements.
619 ///
620 /// By default, performs semantic analysis when building the vector type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000622 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000623 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000624 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000625
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// \brief Build a new function type.
627 ///
628 /// By default, performs semantic analysis when building the function type.
629 /// Subclasses may override this routine to provide different behavior.
630 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000631 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000633 bool Variadic, unsigned Quals,
634 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000635
John McCall550e0c22009-10-21 00:40:46 +0000636 /// \brief Build a new unprototyped function type.
637 QualType RebuildFunctionNoProtoType(QualType ResultType);
638
John McCallb96ec562009-12-04 22:46:56 +0000639 /// \brief Rebuild an unresolved typename type, given the decl that
640 /// the UnresolvedUsingTypenameDecl was transformed to.
641 QualType RebuildUnresolvedUsingType(Decl *D);
642
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// \brief Build a new typedef type.
644 QualType RebuildTypedefType(TypedefDecl *Typedef) {
645 return SemaRef.Context.getTypeDeclType(Typedef);
646 }
647
648 /// \brief Build a new class/struct/union type.
649 QualType RebuildRecordType(RecordDecl *Record) {
650 return SemaRef.Context.getTypeDeclType(Record);
651 }
652
653 /// \brief Build a new Enum type.
654 QualType RebuildEnumType(EnumDecl *Enum) {
655 return SemaRef.Context.getTypeDeclType(Enum);
656 }
John McCallfcc33b02009-09-05 00:15:47 +0000657
Mike Stump11289f42009-09-09 15:08:12 +0000658 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 ///
660 /// By default, performs semantic analysis when building the typeof type.
661 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000662 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 ///
666 /// By default, builds a new TypeOfType with the given underlying type.
667 QualType RebuildTypeOfType(QualType Underlying);
668
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 ///
671 /// By default, performs semantic analysis when building the decltype type.
672 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000673 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000674
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675 /// \brief Build a new template specialization type.
676 ///
677 /// By default, performs semantic analysis when building the template
678 /// specialization type. Subclasses may override this routine to provide
679 /// different behavior.
680 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000681 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000682 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000683
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000684 /// \brief Build a new parenthesized type.
685 ///
686 /// By default, builds a new ParenType type from the inner type.
687 /// Subclasses may override this routine to provide different behavior.
688 QualType RebuildParenType(QualType InnerType) {
689 return SemaRef.Context.getParenType(InnerType);
690 }
691
Douglas Gregord6ff3322009-08-04 16:50:30 +0000692 /// \brief Build a new qualified name type.
693 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000694 /// By default, builds a new ElaboratedType type from the keyword,
695 /// the nested-name-specifier and the named type.
696 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000697 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
698 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000699 NestedNameSpecifier *NNS, QualType Named) {
700 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000701 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702
703 /// \brief Build a new typename type that refers to a template-id.
704 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000705 /// By default, builds a new DependentNameType type from the
706 /// nested-name-specifier and the given type. Subclasses may override
707 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000708 QualType RebuildDependentTemplateSpecializationType(
709 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000710 NestedNameSpecifier *Qualifier,
711 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000712 const IdentifierInfo *Name,
713 SourceLocation NameLoc,
714 const TemplateArgumentListInfo &Args) {
715 // Rebuild the template name.
716 // TODO: avoid TemplateName abstraction
717 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000718 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000719 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000720
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000721 if (InstName.isNull())
722 return QualType();
723
John McCallc392f372010-06-11 00:33:02 +0000724 // If it's still dependent, make a dependent specialization.
725 if (InstName.getAsDependentTemplateName())
726 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000727 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000728
729 // Otherwise, make an elaborated type wrapping a non-dependent
730 // specialization.
731 QualType T =
732 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
733 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000734
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000735 // NOTE: NNS is already recorded in template specialization type T.
736 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000737 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
739 /// \brief Build a new typename type that refers to an identifier.
740 ///
741 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000742 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000744 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000745 NestedNameSpecifier *NNS,
746 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000747 SourceLocation KeywordLoc,
748 SourceRange NNSRange,
749 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000750 CXXScopeSpec SS;
751 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000752 SS.setRange(NNSRange);
753
Douglas Gregore677daf2010-03-31 22:19:08 +0000754 if (NNS->isDependent()) {
755 // If the name is still dependent, just build a new dependent name type.
756 if (!SemaRef.computeDeclContext(SS))
757 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
758 }
759
Abramo Bagnara6150c882010-05-11 21:36:43 +0000760 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000761 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
762 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000763
764 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
765
Abramo Bagnarad7548482010-05-19 21:37:53 +0000766 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000767 // into a non-dependent elaborated-type-specifier. Find the tag we're
768 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000769 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000770 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
771 if (!DC)
772 return QualType();
773
John McCallbf8c5192010-05-27 06:40:31 +0000774 if (SemaRef.RequireCompleteDeclContext(SS, DC))
775 return QualType();
776
Douglas Gregore677daf2010-03-31 22:19:08 +0000777 TagDecl *Tag = 0;
778 SemaRef.LookupQualifiedName(Result, DC);
779 switch (Result.getResultKind()) {
780 case LookupResult::NotFound:
781 case LookupResult::NotFoundInCurrentInstantiation:
782 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000783
Douglas Gregore677daf2010-03-31 22:19:08 +0000784 case LookupResult::Found:
785 Tag = Result.getAsSingle<TagDecl>();
786 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000787
Douglas Gregore677daf2010-03-31 22:19:08 +0000788 case LookupResult::FoundOverloaded:
789 case LookupResult::FoundUnresolvedValue:
790 llvm_unreachable("Tag lookup cannot find non-tags");
791 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000792
Douglas Gregore677daf2010-03-31 22:19:08 +0000793 case LookupResult::Ambiguous:
794 // Let the LookupResult structure handle ambiguities.
795 return QualType();
796 }
797
798 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000799 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000800 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000801 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000802 return QualType();
803 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000804
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
806 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000807 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
808 return QualType();
809 }
810
811 // Build the elaborated-type-specifier type.
812 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000813 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000814 }
Mike Stump11289f42009-09-09 15:08:12 +0000815
Douglas Gregor822d0302011-01-12 17:07:58 +0000816 /// \brief Build a new pack expansion type.
817 ///
818 /// By default, builds a new PackExpansionType type from the given pattern.
819 /// Subclasses may override this routine to provide different behavior.
820 QualType RebuildPackExpansionType(QualType Pattern,
821 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000822 SourceLocation EllipsisLoc,
823 llvm::Optional<unsigned> NumExpansions) {
824 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
825 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000826 }
827
Douglas Gregor1135c352009-08-06 05:28:30 +0000828 /// \brief Build a new nested-name-specifier given the prefix and an
829 /// identifier that names the next step in the nested-name-specifier.
830 ///
831 /// By default, performs semantic analysis when building the new
832 /// nested-name-specifier. Subclasses may override this routine to provide
833 /// different behavior.
834 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
835 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000836 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000837 QualType ObjectType,
838 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000839
840 /// \brief Build a new nested-name-specifier given the prefix and the
841 /// namespace named in the next step in the nested-name-specifier.
842 ///
843 /// By default, performs semantic analysis when building the new
844 /// nested-name-specifier. Subclasses may override this routine to provide
845 /// different behavior.
846 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
847 SourceRange Range,
848 NamespaceDecl *NS);
849
850 /// \brief Build a new nested-name-specifier given the prefix and the
851 /// type named in the next step in the nested-name-specifier.
852 ///
853 /// By default, performs semantic analysis when building the new
854 /// nested-name-specifier. Subclasses may override this routine to provide
855 /// different behavior.
856 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
857 SourceRange Range,
858 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000859 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000860
861 /// \brief Build a new template name given a nested name specifier, a flag
862 /// indicating whether the "template" keyword was provided, and the template
863 /// that the template name refers to.
864 ///
865 /// By default, builds the new template name directly. Subclasses may override
866 /// this routine to provide different behavior.
867 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
868 bool TemplateKW,
869 TemplateDecl *Template);
870
Douglas Gregor71dc5092009-08-06 06:41:21 +0000871 /// \brief Build a new template name given a nested name specifier and the
872 /// name that is referred to as a template.
873 ///
874 /// By default, performs semantic analysis to determine whether the name can
875 /// be resolved to a specific template, then builds the appropriate kind of
876 /// template name. Subclasses may override this routine to provide different
877 /// behavior.
878 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000879 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000880 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000881 QualType ObjectType,
882 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000883
Douglas Gregor71395fa2009-11-04 00:56:37 +0000884 /// \brief Build a new template name given a nested name specifier and the
885 /// overloaded operator name that is referred to as a template.
886 ///
887 /// By default, performs semantic analysis to determine whether the name can
888 /// be resolved to a specific template, then builds the appropriate kind of
889 /// template name. Subclasses may override this routine to provide different
890 /// behavior.
891 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
892 OverloadedOperatorKind Operator,
893 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000894
895 /// \brief Build a new template name given a template template parameter pack
896 /// and the
897 ///
898 /// By default, performs semantic analysis to determine whether the name can
899 /// be resolved to a specific template, then builds the appropriate kind of
900 /// template name. Subclasses may override this routine to provide different
901 /// behavior.
902 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
903 const TemplateArgument &ArgPack) {
904 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
905 }
906
Douglas Gregorebe10102009-08-20 07:17:43 +0000907 /// \brief Build a new compound statement.
908 ///
909 /// By default, performs semantic analysis to build the new statement.
910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000911 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000912 MultiStmtArg Statements,
913 SourceLocation RBraceLoc,
914 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000915 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000916 IsStmtExpr);
917 }
918
919 /// \brief Build a new case statement.
920 ///
921 /// By default, performs semantic analysis to build the new statement.
922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000923 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000924 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000925 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000926 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000927 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000928 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000929 ColonLoc);
930 }
Mike Stump11289f42009-09-09 15:08:12 +0000931
Douglas Gregorebe10102009-08-20 07:17:43 +0000932 /// \brief Attach the body to a new case statement.
933 ///
934 /// By default, performs semantic analysis to build the new statement.
935 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000936 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000937 getSema().ActOnCaseStmtBody(S, Body);
938 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000939 }
Mike Stump11289f42009-09-09 15:08:12 +0000940
Douglas Gregorebe10102009-08-20 07:17:43 +0000941 /// \brief Build a new default statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000945 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000946 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000947 Stmt *SubStmt) {
948 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000949 /*CurScope=*/0);
950 }
Mike Stump11289f42009-09-09 15:08:12 +0000951
Douglas Gregorebe10102009-08-20 07:17:43 +0000952 /// \brief Build a new label statement.
953 ///
954 /// By default, performs semantic analysis to build the new statement.
955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000956 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 IdentifierInfo *Id,
958 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000959 Stmt *SubStmt, bool HasUnusedAttr) {
960 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
961 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 }
Mike Stump11289f42009-09-09 15:08:12 +0000963
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 /// \brief Build a new "if" statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000969 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000970 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000971 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 }
Mike Stump11289f42009-09-09 15:08:12 +0000973
Douglas Gregorebe10102009-08-20 07:17:43 +0000974 /// \brief Start building a new switch statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000979 Expr *Cond, VarDecl *CondVar) {
980 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000981 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 }
Mike Stump11289f42009-09-09 15:08:12 +0000983
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 /// \brief Attach the body to the switch statement.
985 ///
986 /// By default, performs semantic analysis to build the new statement.
987 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000988 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000989 Stmt *Switch, Stmt *Body) {
990 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 }
992
993 /// \brief Build a new while statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000997 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000998 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000999 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +00001000 Stmt *Body) {
1001 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 }
Mike Stump11289f42009-09-09 15:08:12 +00001003
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 /// \brief Build a new do-while statement.
1005 ///
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001008 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 SourceLocation WhileLoc,
1010 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001011 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001013 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1014 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001015 }
1016
1017 /// \brief Build a new for statement.
1018 ///
1019 /// By default, performs semantic analysis to build the new statement.
1020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001021 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001023 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001024 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +00001025 SourceLocation RParenLoc, Stmt *Body) {
1026 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +00001027 CondVar,
John McCallb268a282010-08-23 23:25:46 +00001028 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 /// \brief Build a new goto statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001035 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 SourceLocation LabelLoc,
1037 LabelStmt *Label) {
1038 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1039 }
1040
1041 /// \brief Build a new indirect goto statement.
1042 ///
1043 /// By default, performs semantic analysis to build the new statement.
1044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001045 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001046 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +00001047 Expr *Target) {
1048 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregorebe10102009-08-20 07:17:43 +00001051 /// \brief Build a new return statement.
1052 ///
1053 /// By default, performs semantic analysis to build the new statement.
1054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001055 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +00001056 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +00001057
John McCallb268a282010-08-23 23:25:46 +00001058 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 }
Mike Stump11289f42009-09-09 15:08:12 +00001060
Douglas Gregorebe10102009-08-20 07:17:43 +00001061 /// \brief Build a new declaration statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001065 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001066 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 SourceLocation EndLoc) {
1068 return getSema().Owned(
1069 new (getSema().Context) DeclStmt(
1070 DeclGroupRef::Create(getSema().Context,
1071 Decls, NumDecls),
1072 StartLoc, EndLoc));
1073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Anders Carlssonaaeef072010-01-24 05:50:09 +00001075 /// \brief Build a new inline asm statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001079 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001080 bool IsSimple,
1081 bool IsVolatile,
1082 unsigned NumOutputs,
1083 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001084 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001085 MultiExprArg Constraints,
1086 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001087 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001088 MultiExprArg Clobbers,
1089 SourceLocation RParenLoc,
1090 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001091 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001092 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001093 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001094 RParenLoc, MSAsm);
1095 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001096
1097 /// \brief Build a new Objective-C @try statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001102 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001103 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001104 Stmt *Finally) {
1105 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1106 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001107 }
1108
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001109 /// \brief Rebuild an Objective-C exception declaration.
1110 ///
1111 /// By default, performs semantic analysis to build the new declaration.
1112 /// Subclasses may override this routine to provide different behavior.
1113 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1114 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001115 return getSema().BuildObjCExceptionDecl(TInfo, T,
1116 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001117 ExceptionDecl->getLocation());
1118 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001119
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001120 /// \brief Build a new Objective-C @catch statement.
1121 ///
1122 /// By default, performs semantic analysis to build the new statement.
1123 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001124 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001125 SourceLocation RParenLoc,
1126 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001127 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001128 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001129 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001130 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001131
Douglas Gregor306de2f2010-04-22 23:59:56 +00001132 /// \brief Build a new Objective-C @finally statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *Body) {
1138 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001139 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001140
Douglas Gregor6148de72010-04-22 22:01:21 +00001141 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001145 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001146 Expr *Operand) {
1147 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001148 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001149
Douglas Gregor6148de72010-04-22 22:01:21 +00001150 /// \brief Build a new Objective-C @synchronized statement.
1151 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001154 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001155 Expr *Object,
1156 Stmt *Body) {
1157 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1158 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001159 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001160
1161 /// \brief Build a new Objective-C fast enumeration statement.
1162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001165 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001166 SourceLocation LParenLoc,
1167 Stmt *Element,
1168 Expr *Collection,
1169 SourceLocation RParenLoc,
1170 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001171 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001172 Element,
1173 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001174 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001175 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001176 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001177
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 /// \brief Build a new C++ exception declaration.
1179 ///
1180 /// By default, performs semantic analysis to build the new decaration.
1181 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001182 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001183 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001184 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001185 SourceLocation Loc) {
1186 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new C++ catch statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001193 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001194 VarDecl *ExceptionDecl,
1195 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001196 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1197 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 /// \brief Build a new C++ try statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001204 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001205 Stmt *TryBlock,
1206 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001207 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 /// \brief Build a new expression that references a declaration.
1211 ///
1212 /// By default, performs semantic analysis to build the new expression.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001215 LookupResult &R,
1216 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001217 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1218 }
1219
1220
1221 /// \brief Build a new expression that references a declaration.
1222 ///
1223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 SourceRange QualifierRange,
1227 ValueDecl *VD,
1228 const DeclarationNameInfo &NameInfo,
1229 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001230 CXXScopeSpec SS;
1231 SS.setScopeRep(Qualifier);
1232 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001233
1234 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001235
1236 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 }
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001240 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001243 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001245 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 }
1247
Douglas Gregorad8a3362009-09-04 17:36:40 +00001248 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001249 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001250 /// By default, performs semantic analysis to build the new expression.
1251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001252 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001253 SourceLocation OperatorLoc,
1254 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001255 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001256 SourceRange QualifierRange,
1257 TypeSourceInfo *ScopeType,
1258 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001259 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001260 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001261
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001263 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 /// By default, performs semantic analysis to build the new expression.
1265 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001266 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001267 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001268 Expr *SubExpr) {
1269 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 }
Mike Stump11289f42009-09-09 15:08:12 +00001271
Douglas Gregor882211c2010-04-28 22:16:22 +00001272 /// \brief Build a new builtin offsetof expression.
1273 ///
1274 /// By default, performs semantic analysis to build the new expression.
1275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001276 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001277 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001278 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001279 unsigned NumComponents,
1280 SourceLocation RParenLoc) {
1281 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1282 NumComponents, RParenLoc);
1283 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001286 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001289 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001290 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001292 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 }
1294
Mike Stump11289f42009-09-09 15:08:12 +00001295 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001302 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001303 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001305 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 return move(Result);
1308 }
Mike Stump11289f42009-09-09 15:08:12 +00001309
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001314 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001316 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001318 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1319 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 RBracketLoc);
1321 }
1322
1323 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001324 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001327 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001330 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001331 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 }
1333
1334 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001335 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001338 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001339 bool isArrow,
1340 NestedNameSpecifier *Qualifier,
1341 SourceRange QualifierRange,
1342 const DeclarationNameInfo &MemberNameInfo,
1343 ValueDecl *Member,
1344 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001345 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001346 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001347 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001348 // We have a reference to an unnamed field. This is always the
1349 // base of an anonymous struct/union member access, i.e. the
1350 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001351 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001352 assert(Member->getType()->isRecordType() &&
1353 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001354
John McCallb268a282010-08-23 23:25:46 +00001355 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001356 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001357 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001358
John McCall7decc9e2010-11-18 06:31:45 +00001359 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001360 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001361 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001362 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001363 cast<FieldDecl>(Member)->getType(),
1364 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001365 return getSema().Owned(ME);
1366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001368 CXXScopeSpec SS;
1369 if (Qualifier) {
1370 SS.setRange(QualifierRange);
1371 SS.setScopeRep(Qualifier);
1372 }
1373
John McCallb268a282010-08-23 23:25:46 +00001374 getSema().DefaultFunctionArrayConversion(Base);
1375 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001376
John McCall16df1e52010-03-30 21:47:33 +00001377 // FIXME: this involves duplicating earlier analysis in a lot of
1378 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001379 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001380 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001381 R.resolveKind();
1382
John McCallb268a282010-08-23 23:25:46 +00001383 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001384 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001385 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 }
Mike Stump11289f42009-09-09 15:08:12 +00001387
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001389 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001392 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001393 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001394 Expr *LHS, Expr *RHS) {
1395 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 }
1397
1398 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001399 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 /// By default, performs semantic analysis to build the new expression.
1401 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001402 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001404 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001406 Expr *RHS) {
1407 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1408 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 }
1410
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001412 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// By default, performs semantic analysis to build the new expression.
1414 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001415 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001416 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001418 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001419 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001420 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 }
Mike Stump11289f42009-09-09 15:08:12 +00001422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001424 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001428 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001430 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001431 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 }
Mike Stump11289f42009-09-09 15:08:12 +00001434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001436 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001439 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 SourceLocation OpLoc,
1441 SourceLocation AccessorLoc,
1442 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001443
John McCall10eae182009-11-30 22:42:35 +00001444 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001445 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001446 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001447 OpLoc, /*IsArrow*/ false,
1448 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001449 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001450 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 }
Mike Stump11289f42009-09-09 15:08:12 +00001452
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001454 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 /// By default, performs semantic analysis to build the new expression.
1456 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001457 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001459 SourceLocation RBraceLoc,
1460 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001461 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001462 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1463 if (Result.isInvalid() || ResultTy->isDependentType())
1464 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001465
Douglas Gregord3d93062009-11-09 17:16:50 +00001466 // Patch in the result type we were given, which may have been computed
1467 // when the initial InitListExpr was built.
1468 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1469 ILE->setType(ResultTy);
1470 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 }
Mike Stump11289f42009-09-09 15:08:12 +00001472
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001474 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001478 MultiExprArg ArrayExprs,
1479 SourceLocation EqualOrColonLoc,
1480 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001481 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001482 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001484 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001486 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001487
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 ArrayExprs.release();
1489 return move(Result);
1490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001493 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 /// By default, builds the implicit value initialization without performing
1495 /// any semantic analysis. Subclasses may override this routine to provide
1496 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001497 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1499 }
Mike Stump11289f42009-09-09 15:08:12 +00001500
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001502 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001505 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001506 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001507 SourceLocation RParenLoc) {
1508 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001509 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001510 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 }
1512
1513 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 MultiExprArg SubExprs,
1519 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001520 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001521 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 }
Mike Stump11289f42009-09-09 15:08:12 +00001523
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001525 ///
1526 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// rather than attempting to map the label statement itself.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 SourceLocation LabelLoc,
1531 LabelStmt *Label) {
1532 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1533 }
Mike Stump11289f42009-09-09 15:08:12 +00001534
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 /// \brief Build a new GNU statement expression.
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 RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001540 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001542 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
Mike Stump11289f42009-09-09 15:08:12 +00001544
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// \brief Build a new __builtin_choose_expr expression.
1546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001549 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001550 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 SourceLocation RParenLoc) {
1552 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001553 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 RParenLoc);
1555 }
Mike Stump11289f42009-09-09 15:08:12 +00001556
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// \brief Build a new overloaded operator call expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// The semantic analysis provides the behavior of template instantiation,
1561 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001562 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// argument-dependent lookup, etc. Subclasses may override this routine to
1564 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001567 Expr *Callee,
1568 Expr *First,
1569 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001570
1571 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 /// reinterpret_cast.
1573 ///
1574 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001575 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001577 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 Stmt::StmtClass Class,
1579 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001580 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 SourceLocation RAngleLoc,
1582 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001583 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 SourceLocation RParenLoc) {
1585 switch (Class) {
1586 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001587 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001588 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001589 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001590
1591 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001592 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001593 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001594 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001595
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001597 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001598 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001601
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001603 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001604 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001605 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 default:
1608 assert(false && "Invalid C++ named cast");
1609 break;
1610 }
Mike Stump11289f42009-09-09 15:08:12 +00001611
John McCallfaf5fb42010-08-26 23:41:50 +00001612 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 }
Mike Stump11289f42009-09-09 15:08:12 +00001614
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 /// \brief Build a new C++ static_cast expression.
1616 ///
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001619 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001621 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 SourceLocation RAngleLoc,
1623 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001624 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001626 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001627 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001628 SourceRange(LAngleLoc, RAngleLoc),
1629 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 }
1631
1632 /// \brief Build a new C++ dynamic_cast expression.
1633 ///
1634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001636 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001638 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 SourceLocation RAngleLoc,
1640 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001641 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001643 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001644 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001645 SourceRange(LAngleLoc, RAngleLoc),
1646 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 }
1648
1649 /// \brief Build a new C++ reinterpret_cast expression.
1650 ///
1651 /// By default, performs semantic analysis to build the new expression.
1652 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001653 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001655 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceLocation RAngleLoc,
1657 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001658 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001659 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001660 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001661 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001662 SourceRange(LAngleLoc, RAngleLoc),
1663 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 }
1665
1666 /// \brief Build a new C++ const_cast expression.
1667 ///
1668 /// By default, performs semantic analysis to build the new expression.
1669 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001670 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001672 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation RAngleLoc,
1674 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001675 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001677 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001678 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001679 SourceRange(LAngleLoc, RAngleLoc),
1680 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001681 }
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 /// \brief Build a new C++ functional-style cast expression.
1684 ///
1685 /// By default, performs semantic analysis to build the new expression.
1686 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001687 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1688 SourceLocation LParenLoc,
1689 Expr *Sub,
1690 SourceLocation RParenLoc) {
1691 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001692 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 RParenLoc);
1694 }
Mike Stump11289f42009-09-09 15:08:12 +00001695
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 /// \brief Build a new C++ typeid(type) expression.
1697 ///
1698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001701 SourceLocation TypeidLoc,
1702 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001704 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001705 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001706 }
Mike Stump11289f42009-09-09 15:08:12 +00001707
Francois Pichet9f4f2072010-09-08 12:20:18 +00001708
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 /// \brief Build a new C++ typeid(expr) expression.
1710 ///
1711 /// By default, performs semantic analysis to build the new expression.
1712 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001713 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001714 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001715 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001716 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001717 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001718 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001719 }
1720
Francois Pichet9f4f2072010-09-08 12:20:18 +00001721 /// \brief Build a new C++ __uuidof(type) expression.
1722 ///
1723 /// By default, performs semantic analysis to build the new expression.
1724 /// Subclasses may override this routine to provide different behavior.
1725 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1726 SourceLocation TypeidLoc,
1727 TypeSourceInfo *Operand,
1728 SourceLocation RParenLoc) {
1729 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1730 RParenLoc);
1731 }
1732
1733 /// \brief Build a new C++ __uuidof(expr) expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
1737 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1738 SourceLocation TypeidLoc,
1739 Expr *Operand,
1740 SourceLocation RParenLoc) {
1741 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1742 RParenLoc);
1743 }
1744
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 /// \brief Build a new C++ "this" expression.
1746 ///
1747 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001748 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001749 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001750 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001751 QualType ThisType,
1752 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001753 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001754 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1755 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 }
1757
1758 /// \brief Build a new C++ throw expression.
1759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001762 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001763 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 }
1765
1766 /// \brief Build a new C++ default-argument expression.
1767 ///
1768 /// By default, builds a new default-argument expression, which does not
1769 /// require any semantic analysis. Subclasses may override this routine to
1770 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001771 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001772 ParmVarDecl *Param) {
1773 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1774 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ zero-initialization expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001781 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1782 SourceLocation LParenLoc,
1783 SourceLocation RParenLoc) {
1784 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001785 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001786 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 }
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 /// \brief Build a new C++ "new" expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001794 bool UseGlobal,
1795 SourceLocation PlacementLParen,
1796 MultiExprArg PlacementArgs,
1797 SourceLocation PlacementRParen,
1798 SourceRange TypeIdParens,
1799 QualType AllocatedType,
1800 TypeSourceInfo *AllocatedTypeInfo,
1801 Expr *ArraySize,
1802 SourceLocation ConstructorLParen,
1803 MultiExprArg ConstructorArgs,
1804 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001805 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 PlacementLParen,
1807 move(PlacementArgs),
1808 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001809 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001810 AllocatedType,
1811 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001812 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001813 ConstructorLParen,
1814 move(ConstructorArgs),
1815 ConstructorRParen);
1816 }
Mike Stump11289f42009-09-09 15:08:12 +00001817
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// \brief Build a new C++ "delete" expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 bool IsGlobalDelete,
1824 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001825 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001826 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001827 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregora16548e2009-08-11 05:31:07 +00001830 /// \brief Build a new unary type trait expression.
1831 ///
1832 /// By default, performs semantic analysis to build the new expression.
1833 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001834 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001835 SourceLocation StartLoc,
1836 TypeSourceInfo *T,
1837 SourceLocation RParenLoc) {
1838 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
1840
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001841 /// \brief Build a new binary type trait expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
1845 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1846 SourceLocation StartLoc,
1847 TypeSourceInfo *LhsT,
1848 TypeSourceInfo *RhsT,
1849 SourceLocation RParenLoc) {
1850 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1851 }
1852
Mike Stump11289f42009-09-09 15:08:12 +00001853 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 /// expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001858 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001859 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001860 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001861 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 CXXScopeSpec SS;
1863 SS.setRange(QualifierRange);
1864 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001865
1866 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001867 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001868 *TemplateArgs);
1869
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001870 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new template-id expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001877 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001878 LookupResult &R,
1879 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001880 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001881 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new object-construction expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001888 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001889 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 CXXConstructorDecl *Constructor,
1891 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001892 MultiExprArg Args,
1893 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001894 CXXConstructExpr::ConstructionKind ConstructKind,
1895 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001896 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001897 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001898 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001899 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001900
Douglas Gregordb121ba2009-12-14 16:27:04 +00001901 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001902 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001903 RequiresZeroInit, ConstructKind,
1904 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 }
1906
1907 /// \brief Build a new object-construction expression.
1908 ///
1909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001911 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1912 SourceLocation LParenLoc,
1913 MultiExprArg Args,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 LParenLoc,
1917 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 RParenLoc);
1919 }
1920
1921 /// \brief Build a new object-construction expression.
1922 ///
1923 /// By default, performs semantic analysis to build the new expression.
1924 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001925 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1926 SourceLocation LParenLoc,
1927 MultiExprArg Args,
1928 SourceLocation RParenLoc) {
1929 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001930 LParenLoc,
1931 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 RParenLoc);
1933 }
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 /// \brief Build a new member reference expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001939 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001940 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 bool IsArrow,
1942 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001943 NestedNameSpecifier *Qualifier,
1944 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001945 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001946 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001947 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001949 SS.setRange(QualifierRange);
1950 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001951
John McCallb268a282010-08-23 23:25:46 +00001952 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001953 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001954 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001955 MemberNameInfo,
1956 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 }
1958
John McCall10eae182009-11-30 22:42:35 +00001959 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001963 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001964 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001965 SourceLocation OperatorLoc,
1966 bool IsArrow,
1967 NestedNameSpecifier *Qualifier,
1968 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001969 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001970 LookupResult &R,
1971 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001972 CXXScopeSpec SS;
1973 SS.setRange(QualifierRange);
1974 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001975
John McCallb268a282010-08-23 23:25:46 +00001976 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001977 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001978 SS, FirstQualifierInScope,
1979 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001980 }
Mike Stump11289f42009-09-09 15:08:12 +00001981
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001982 /// \brief Build a new noexcept expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1987 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1988 }
1989
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001990 /// \brief Build a new expression to compute the length of a parameter pack.
1991 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1992 SourceLocation PackLoc,
1993 SourceLocation RParenLoc,
1994 unsigned Length) {
1995 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1996 OperatorLoc, Pack, PackLoc,
1997 RParenLoc, Length);
1998 }
1999
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// \brief Build a new Objective-C @encode expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002004 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002005 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002007 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002009 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002010
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002011 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002012 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002013 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002014 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002015 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002016 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002017 MultiExprArg Args,
2018 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002019 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2020 ReceiverTypeInfo->getType(),
2021 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002022 Sel, Method, LBracLoc, SelectorLoc,
2023 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002024 }
2025
2026 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002028 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002029 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002030 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002031 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002032 MultiExprArg Args,
2033 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002034 return SemaRef.BuildInstanceMessage(Receiver,
2035 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002036 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002037 Sel, Method, LBracLoc, SelectorLoc,
2038 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002039 }
2040
Douglas Gregord51d90d2010-04-26 20:11:03 +00002041 /// \brief Build a new Objective-C ivar reference expression.
2042 ///
2043 /// By default, performs semantic analysis to build the new expression.
2044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002045 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002046 SourceLocation IvarLoc,
2047 bool IsArrow, bool IsFreeIvar) {
2048 // FIXME: We lose track of the IsFreeIvar bit.
2049 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002050 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002051 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2052 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002053 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002054 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002055 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002056 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002057 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002058 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002059
Douglas Gregord51d90d2010-04-26 20:11:03 +00002060 if (Result.get())
2061 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002062
John McCallb268a282010-08-23 23:25:46 +00002063 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002064 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002065 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002066 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002067 /*TemplateArgs=*/0);
2068 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002069
2070 /// \brief Build a new Objective-C property reference expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002075 ObjCPropertyDecl *Property,
2076 SourceLocation PropertyLoc) {
2077 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002078 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002079 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2080 Sema::LookupMemberName);
2081 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002082 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002083 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002084 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002085 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002086 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002087
Douglas Gregor9faee212010-04-26 20:47:02 +00002088 if (Result.get())
2089 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002090
John McCallb268a282010-08-23 23:25:46 +00002091 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002092 /*FIXME:*/PropertyLoc, IsArrow,
2093 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002094 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002095 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002096 /*TemplateArgs=*/0);
2097 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002098
John McCallb7bd14f2010-12-02 01:19:52 +00002099 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002100 ///
2101 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002102 /// Subclasses may override this routine to provide different behavior.
2103 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2104 ObjCMethodDecl *Getter,
2105 ObjCMethodDecl *Setter,
2106 SourceLocation PropertyLoc) {
2107 // Since these expressions can only be value-dependent, we do not
2108 // need to perform semantic analysis again.
2109 return Owned(
2110 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2111 VK_LValue, OK_ObjCProperty,
2112 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002113 }
2114
Douglas Gregord51d90d2010-04-26 20:11:03 +00002115 /// \brief Build a new Objective-C "isa" expression.
2116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002119 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002120 bool IsArrow) {
2121 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002122 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002123 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2124 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002125 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002126 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002127 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002128 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002129 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002130
Douglas Gregord51d90d2010-04-26 20:11:03 +00002131 if (Result.get())
2132 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002133
John McCallb268a282010-08-23 23:25:46 +00002134 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002135 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002136 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002137 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 /*TemplateArgs=*/0);
2139 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002140
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 /// \brief Build a new shuffle vector expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002145 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002146 MultiExprArg SubExprs,
2147 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002149 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2151 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2152 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2153 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 // Build a reference to the __builtin_shufflevector builtin
2156 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002157 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002159 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002161
2162 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 unsigned NumSubExprs = SubExprs.size();
2164 Expr **Subs = (Expr **)SubExprs.release();
2165 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2166 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002167 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002168 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002170 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002173 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002175 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002178 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 }
John McCall31f82722010-11-12 08:19:04 +00002180
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002181 /// \brief Build a new template argument pack expansion.
2182 ///
2183 /// By default, performs semantic analysis to build a new pack expansion
2184 /// for a template argument. Subclasses may override this routine to provide
2185 /// different behavior.
2186 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002187 SourceLocation EllipsisLoc,
2188 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002189 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002190 case TemplateArgument::Expression: {
2191 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002192 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2193 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002194 if (Result.isInvalid())
2195 return TemplateArgumentLoc();
2196
2197 return TemplateArgumentLoc(Result.get(), Result.get());
2198 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002199
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002200 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002201 return TemplateArgumentLoc(TemplateArgument(
2202 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002203 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002204 Pattern.getTemplateQualifierRange(),
2205 Pattern.getTemplateNameLoc(),
2206 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002207
2208 case TemplateArgument::Null:
2209 case TemplateArgument::Integral:
2210 case TemplateArgument::Declaration:
2211 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002212 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002213 llvm_unreachable("Pack expansion pattern has no parameter packs");
2214
2215 case TemplateArgument::Type:
2216 if (TypeSourceInfo *Expansion
2217 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002218 EllipsisLoc,
2219 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002220 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2221 Expansion);
2222 break;
2223 }
2224
2225 return TemplateArgumentLoc();
2226 }
2227
Douglas Gregor968f23a2011-01-03 19:31:53 +00002228 /// \brief Build a new expression pack expansion.
2229 ///
2230 /// By default, performs semantic analysis to build a new pack expansion
2231 /// for an expression. Subclasses may override this routine to provide
2232 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002233 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2234 llvm::Optional<unsigned> NumExpansions) {
2235 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002236 }
2237
John McCall31f82722010-11-12 08:19:04 +00002238private:
2239 QualType TransformTypeInObjectScope(QualType T,
2240 QualType ObjectType,
2241 NamedDecl *FirstQualifierInScope,
2242 NestedNameSpecifier *Prefix);
2243
2244 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2245 QualType ObjectType,
2246 NamedDecl *FirstQualifierInScope,
2247 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002248};
Douglas Gregora16548e2009-08-11 05:31:07 +00002249
Douglas Gregorebe10102009-08-20 07:17:43 +00002250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002251StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002252 if (!S)
2253 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002254
Douglas Gregorebe10102009-08-20 07:17:43 +00002255 switch (S->getStmtClass()) {
2256 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002257
Douglas Gregorebe10102009-08-20 07:17:43 +00002258 // Transform individual statement nodes
2259#define STMT(Node, Parent) \
2260 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2261#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002262#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002263
Douglas Gregorebe10102009-08-20 07:17:43 +00002264 // Transform expressions by calling TransformExpr.
2265#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002266#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002267#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002268#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002269 {
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002271 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002272 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002273
John McCallb268a282010-08-23 23:25:46 +00002274 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002275 }
Mike Stump11289f42009-09-09 15:08:12 +00002276 }
2277
John McCallc3007a22010-10-26 07:05:15 +00002278 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002279}
Mike Stump11289f42009-09-09 15:08:12 +00002280
2281
Douglas Gregore922c772009-08-04 22:27:00 +00002282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002283ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 if (!E)
2285 return SemaRef.Owned(E);
2286
2287 switch (E->getStmtClass()) {
2288 case Stmt::NoStmtClass: break;
2289#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002290#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002291#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002292 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002293#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002294 }
2295
John McCallc3007a22010-10-26 07:05:15 +00002296 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002297}
2298
2299template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002300bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2301 unsigned NumInputs,
2302 bool IsCall,
2303 llvm::SmallVectorImpl<Expr *> &Outputs,
2304 bool *ArgChanged) {
2305 for (unsigned I = 0; I != NumInputs; ++I) {
2306 // If requested, drop call arguments that need to be dropped.
2307 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2308 if (ArgChanged)
2309 *ArgChanged = true;
2310
2311 break;
2312 }
2313
Douglas Gregor968f23a2011-01-03 19:31:53 +00002314 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2315 Expr *Pattern = Expansion->getPattern();
2316
2317 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2318 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2319 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2320
2321 // Determine whether the set of unexpanded parameter packs can and should
2322 // be expanded.
2323 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002324 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002325 llvm::Optional<unsigned> OrigNumExpansions
2326 = Expansion->getNumExpansions();
2327 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002328 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2329 Pattern->getSourceRange(),
2330 Unexpanded.data(),
2331 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002332 Expand, RetainExpansion,
2333 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002334 return true;
2335
2336 if (!Expand) {
2337 // The transform has determined that we should perform a simple
2338 // transformation on the pack expansion, producing another pack
2339 // expansion.
2340 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2341 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2342 if (OutPattern.isInvalid())
2343 return true;
2344
2345 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002346 Expansion->getEllipsisLoc(),
2347 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002348 if (Out.isInvalid())
2349 return true;
2350
2351 if (ArgChanged)
2352 *ArgChanged = true;
2353 Outputs.push_back(Out.get());
2354 continue;
2355 }
2356
2357 // The transform has determined that we should perform an elementwise
2358 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002359 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002360 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2361 ExprResult Out = getDerived().TransformExpr(Pattern);
2362 if (Out.isInvalid())
2363 return true;
2364
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002365 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002366 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2367 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002368 if (Out.isInvalid())
2369 return true;
2370 }
2371
Douglas Gregor968f23a2011-01-03 19:31:53 +00002372 if (ArgChanged)
2373 *ArgChanged = true;
2374 Outputs.push_back(Out.get());
2375 }
2376
2377 continue;
2378 }
2379
Douglas Gregora3efea12011-01-03 19:04:46 +00002380 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2381 if (Result.isInvalid())
2382 return true;
2383
2384 if (Result.get() != Inputs[I] && ArgChanged)
2385 *ArgChanged = true;
2386
2387 Outputs.push_back(Result.get());
2388 }
2389
2390 return false;
2391}
2392
2393template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002394NestedNameSpecifier *
2395TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002396 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002397 QualType ObjectType,
2398 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002399 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002400
Douglas Gregorebe10102009-08-20 07:17:43 +00002401 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002402 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002403 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002404 ObjectType,
2405 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002406 if (!Prefix)
2407 return 0;
2408 }
Mike Stump11289f42009-09-09 15:08:12 +00002409
Douglas Gregor1135c352009-08-06 05:28:30 +00002410 switch (NNS->getKind()) {
2411 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002412 if (Prefix) {
2413 // The object type and qualifier-in-scope really apply to the
2414 // leftmost entity.
2415 ObjectType = QualType();
2416 FirstQualifierInScope = 0;
2417 }
2418
Mike Stump11289f42009-09-09 15:08:12 +00002419 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002420 "Identifier nested-name-specifier with no prefix or object type");
2421 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2422 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002423 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002424
2425 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002426 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002427 ObjectType,
2428 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002429
Douglas Gregor1135c352009-08-06 05:28:30 +00002430 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002431 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002432 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002433 getDerived().TransformDecl(Range.getBegin(),
2434 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002435 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002436 Prefix == NNS->getPrefix() &&
2437 NS == NNS->getAsNamespace())
2438 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregor1135c352009-08-06 05:28:30 +00002440 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2441 }
Mike Stump11289f42009-09-09 15:08:12 +00002442
Douglas Gregor1135c352009-08-06 05:28:30 +00002443 case NestedNameSpecifier::Global:
2444 // There is no meaningful transformation that one could perform on the
2445 // global scope.
2446 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002447
Douglas Gregor1135c352009-08-06 05:28:30 +00002448 case NestedNameSpecifier::TypeSpecWithTemplate:
2449 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002450 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002451 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2452 ObjectType,
2453 FirstQualifierInScope,
2454 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002455 if (T.isNull())
2456 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002457
Douglas Gregor1135c352009-08-06 05:28:30 +00002458 if (!getDerived().AlwaysRebuild() &&
2459 Prefix == NNS->getPrefix() &&
2460 T == QualType(NNS->getAsType(), 0))
2461 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002462
2463 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2464 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002465 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002466 }
2467 }
Mike Stump11289f42009-09-09 15:08:12 +00002468
Douglas Gregor1135c352009-08-06 05:28:30 +00002469 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002470 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002471}
2472
2473template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002474DeclarationNameInfo
2475TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002476::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002477 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002478 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002479 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002480
2481 switch (Name.getNameKind()) {
2482 case DeclarationName::Identifier:
2483 case DeclarationName::ObjCZeroArgSelector:
2484 case DeclarationName::ObjCOneArgSelector:
2485 case DeclarationName::ObjCMultiArgSelector:
2486 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002487 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002488 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002489 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002490
Douglas Gregorf816bd72009-09-03 22:13:48 +00002491 case DeclarationName::CXXConstructorName:
2492 case DeclarationName::CXXDestructorName:
2493 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002494 TypeSourceInfo *NewTInfo;
2495 CanQualType NewCanTy;
2496 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002497 NewTInfo = getDerived().TransformType(OldTInfo);
2498 if (!NewTInfo)
2499 return DeclarationNameInfo();
2500 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002501 }
2502 else {
2503 NewTInfo = 0;
2504 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002505 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002506 if (NewT.isNull())
2507 return DeclarationNameInfo();
2508 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2509 }
Mike Stump11289f42009-09-09 15:08:12 +00002510
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002511 DeclarationName NewName
2512 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2513 NewCanTy);
2514 DeclarationNameInfo NewNameInfo(NameInfo);
2515 NewNameInfo.setName(NewName);
2516 NewNameInfo.setNamedTypeInfo(NewTInfo);
2517 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002518 }
Mike Stump11289f42009-09-09 15:08:12 +00002519 }
2520
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002521 assert(0 && "Unknown name kind.");
2522 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002523}
2524
2525template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002526TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002527TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002528 QualType ObjectType,
2529 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002530 SourceLocation Loc = getDerived().getBaseLocation();
2531
Douglas Gregor71dc5092009-08-06 06:41:21 +00002532 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002533 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002534 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002535 /*FIXME*/ SourceRange(Loc),
2536 ObjectType,
2537 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002538 if (!NNS)
2539 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002540
Douglas Gregor71dc5092009-08-06 06:41:21 +00002541 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002542 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002543 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002544 if (!TransTemplate)
2545 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002546
Douglas Gregor71dc5092009-08-06 06:41:21 +00002547 if (!getDerived().AlwaysRebuild() &&
2548 NNS == QTN->getQualifier() &&
2549 TransTemplate == Template)
2550 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002551
Douglas Gregor71dc5092009-08-06 06:41:21 +00002552 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2553 TransTemplate);
2554 }
Mike Stump11289f42009-09-09 15:08:12 +00002555
John McCalle66edc12009-11-24 19:00:30 +00002556 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002557 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002558 }
Mike Stump11289f42009-09-09 15:08:12 +00002559
Douglas Gregor71dc5092009-08-06 06:41:21 +00002560 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002561 NestedNameSpecifier *NNS = DTN->getQualifier();
2562 if (NNS) {
2563 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2564 /*FIXME:*/SourceRange(Loc),
2565 ObjectType,
2566 FirstQualifierInScope);
2567 if (!NNS) return TemplateName();
2568
2569 // These apply to the scope specifier, not the template.
2570 ObjectType = QualType();
2571 FirstQualifierInScope = 0;
2572 }
Mike Stump11289f42009-09-09 15:08:12 +00002573
Douglas Gregor71dc5092009-08-06 06:41:21 +00002574 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002575 NNS == DTN->getQualifier() &&
2576 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002577 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002578
Douglas Gregora5614c52010-09-08 23:56:00 +00002579 if (DTN->isIdentifier()) {
2580 // FIXME: Bad range
2581 SourceRange QualifierRange(getDerived().getBaseLocation());
2582 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2583 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002584 ObjectType,
2585 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002586 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002587
2588 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002589 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002590 }
Mike Stump11289f42009-09-09 15:08:12 +00002591
Douglas Gregor71dc5092009-08-06 06:41:21 +00002592 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002593 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002594 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002595 if (!TransTemplate)
2596 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002597
Douglas Gregor71dc5092009-08-06 06:41:21 +00002598 if (!getDerived().AlwaysRebuild() &&
2599 TransTemplate == Template)
2600 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002601
Douglas Gregor71dc5092009-08-06 06:41:21 +00002602 return TemplateName(TransTemplate);
2603 }
Mike Stump11289f42009-09-09 15:08:12 +00002604
Douglas Gregor5590be02011-01-15 06:45:20 +00002605 if (SubstTemplateTemplateParmPackStorage *SubstPack
2606 = Name.getAsSubstTemplateTemplateParmPack()) {
2607 TemplateTemplateParmDecl *TransParam
2608 = cast_or_null<TemplateTemplateParmDecl>(
2609 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2610 if (!TransParam)
2611 return TemplateName();
2612
2613 if (!getDerived().AlwaysRebuild() &&
2614 TransParam == SubstPack->getParameterPack())
2615 return Name;
2616
2617 return getDerived().RebuildTemplateName(TransParam,
2618 SubstPack->getArgumentPack());
2619 }
2620
John McCalle66edc12009-11-24 19:00:30 +00002621 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002622 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002623 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002624}
2625
2626template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002627void TreeTransform<Derived>::InventTemplateArgumentLoc(
2628 const TemplateArgument &Arg,
2629 TemplateArgumentLoc &Output) {
2630 SourceLocation Loc = getDerived().getBaseLocation();
2631 switch (Arg.getKind()) {
2632 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002633 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002634 break;
2635
2636 case TemplateArgument::Type:
2637 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002638 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002639
John McCall0ad16662009-10-29 08:12:44 +00002640 break;
2641
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002642 case TemplateArgument::Template:
2643 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2644 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002645
2646 case TemplateArgument::TemplateExpansion:
2647 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2648 break;
2649
John McCall0ad16662009-10-29 08:12:44 +00002650 case TemplateArgument::Expression:
2651 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2652 break;
2653
2654 case TemplateArgument::Declaration:
2655 case TemplateArgument::Integral:
2656 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002657 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002658 break;
2659 }
2660}
2661
2662template<typename Derived>
2663bool TreeTransform<Derived>::TransformTemplateArgument(
2664 const TemplateArgumentLoc &Input,
2665 TemplateArgumentLoc &Output) {
2666 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002667 switch (Arg.getKind()) {
2668 case TemplateArgument::Null:
2669 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002670 Output = Input;
2671 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002672
Douglas Gregore922c772009-08-04 22:27:00 +00002673 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002674 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002675 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002676 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002677
2678 DI = getDerived().TransformType(DI);
2679 if (!DI) return true;
2680
2681 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2682 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002683 }
Mike Stump11289f42009-09-09 15:08:12 +00002684
Douglas Gregore922c772009-08-04 22:27:00 +00002685 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002686 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002687 DeclarationName Name;
2688 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2689 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002690 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002691 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002692 if (!D) return true;
2693
John McCall0d07eb32009-10-29 18:45:58 +00002694 Expr *SourceExpr = Input.getSourceDeclExpression();
2695 if (SourceExpr) {
2696 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002697 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002698 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002699 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002700 }
2701
2702 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002703 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002704 }
Mike Stump11289f42009-09-09 15:08:12 +00002705
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002706 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002707 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002708 TemplateName Template
2709 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2710 if (Template.isNull())
2711 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002712
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002713 Output = TemplateArgumentLoc(TemplateArgument(Template),
2714 Input.getTemplateQualifierRange(),
2715 Input.getTemplateNameLoc());
2716 return false;
2717 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002718
2719 case TemplateArgument::TemplateExpansion:
2720 llvm_unreachable("Caller should expand pack expansions");
2721
Douglas Gregore922c772009-08-04 22:27:00 +00002722 case TemplateArgument::Expression: {
2723 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002724 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002725 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002726
John McCall0ad16662009-10-29 08:12:44 +00002727 Expr *InputExpr = Input.getSourceExpression();
2728 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2729
John McCalldadc5752010-08-24 06:29:42 +00002730 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002731 = getDerived().TransformExpr(InputExpr);
2732 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002733 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002734 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002735 }
Mike Stump11289f42009-09-09 15:08:12 +00002736
Douglas Gregore922c772009-08-04 22:27:00 +00002737 case TemplateArgument::Pack: {
2738 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2739 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002740 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002741 AEnd = Arg.pack_end();
2742 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002743
John McCall0ad16662009-10-29 08:12:44 +00002744 // FIXME: preserve source information here when we start
2745 // caring about parameter packs.
2746
John McCall0d07eb32009-10-29 18:45:58 +00002747 TemplateArgumentLoc InputArg;
2748 TemplateArgumentLoc OutputArg;
2749 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2750 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002751 return true;
2752
John McCall0d07eb32009-10-29 18:45:58 +00002753 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002754 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002755
2756 TemplateArgument *TransformedArgsPtr
2757 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2758 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2759 TransformedArgsPtr);
2760 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2761 TransformedArgs.size()),
2762 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002763 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002764 }
2765 }
Mike Stump11289f42009-09-09 15:08:12 +00002766
Douglas Gregore922c772009-08-04 22:27:00 +00002767 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002768 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002769}
2770
Douglas Gregorfe921a72010-12-20 23:36:19 +00002771/// \brief Iterator adaptor that invents template argument location information
2772/// for each of the template arguments in its underlying iterator.
2773template<typename Derived, typename InputIterator>
2774class TemplateArgumentLocInventIterator {
2775 TreeTransform<Derived> &Self;
2776 InputIterator Iter;
2777
2778public:
2779 typedef TemplateArgumentLoc value_type;
2780 typedef TemplateArgumentLoc reference;
2781 typedef typename std::iterator_traits<InputIterator>::difference_type
2782 difference_type;
2783 typedef std::input_iterator_tag iterator_category;
2784
2785 class pointer {
2786 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002787
Douglas Gregorfe921a72010-12-20 23:36:19 +00002788 public:
2789 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2790
2791 const TemplateArgumentLoc *operator->() const { return &Arg; }
2792 };
2793
2794 TemplateArgumentLocInventIterator() { }
2795
2796 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2797 InputIterator Iter)
2798 : Self(Self), Iter(Iter) { }
2799
2800 TemplateArgumentLocInventIterator &operator++() {
2801 ++Iter;
2802 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002803 }
2804
Douglas Gregorfe921a72010-12-20 23:36:19 +00002805 TemplateArgumentLocInventIterator operator++(int) {
2806 TemplateArgumentLocInventIterator Old(*this);
2807 ++(*this);
2808 return Old;
2809 }
2810
2811 reference operator*() const {
2812 TemplateArgumentLoc Result;
2813 Self.InventTemplateArgumentLoc(*Iter, Result);
2814 return Result;
2815 }
2816
2817 pointer operator->() const { return pointer(**this); }
2818
2819 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2820 const TemplateArgumentLocInventIterator &Y) {
2821 return X.Iter == Y.Iter;
2822 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002823
Douglas Gregorfe921a72010-12-20 23:36:19 +00002824 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2825 const TemplateArgumentLocInventIterator &Y) {
2826 return X.Iter != Y.Iter;
2827 }
2828};
2829
Douglas Gregor42cafa82010-12-20 17:42:22 +00002830template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002831template<typename InputIterator>
2832bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2833 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002834 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002835 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002836 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002837 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002838
2839 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2840 // Unpack argument packs, which we translate them into separate
2841 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002842 // FIXME: We could do much better if we could guarantee that the
2843 // TemplateArgumentLocInfo for the pack expansion would be usable for
2844 // all of the template arguments in the argument pack.
2845 typedef TemplateArgumentLocInventIterator<Derived,
2846 TemplateArgument::pack_iterator>
2847 PackLocIterator;
2848 if (TransformTemplateArguments(PackLocIterator(*this,
2849 In.getArgument().pack_begin()),
2850 PackLocIterator(*this,
2851 In.getArgument().pack_end()),
2852 Outputs))
2853 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002854
2855 continue;
2856 }
2857
2858 if (In.getArgument().isPackExpansion()) {
2859 // We have a pack expansion, for which we will be substituting into
2860 // the pattern.
2861 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002862 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002863 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002864 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2865 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002866
2867 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2868 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2869 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2870
2871 // Determine whether the set of unexpanded parameter packs can and should
2872 // be expanded.
2873 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002874 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002875 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002876 if (getDerived().TryExpandParameterPacks(Ellipsis,
2877 Pattern.getSourceRange(),
2878 Unexpanded.data(),
2879 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002880 Expand,
2881 RetainExpansion,
2882 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002883 return true;
2884
2885 if (!Expand) {
2886 // The transform has determined that we should perform a simple
2887 // transformation on the pack expansion, producing another pack
2888 // expansion.
2889 TemplateArgumentLoc OutPattern;
2890 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2891 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2892 return true;
2893
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002894 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2895 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002896 if (Out.getArgument().isNull())
2897 return true;
2898
2899 Outputs.addArgument(Out);
2900 continue;
2901 }
2902
2903 // The transform has determined that we should perform an elementwise
2904 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002905 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2907
2908 if (getDerived().TransformTemplateArgument(Pattern, Out))
2909 return true;
2910
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002911 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002912 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2913 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002914 if (Out.getArgument().isNull())
2915 return true;
2916 }
2917
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002918 Outputs.addArgument(Out);
2919 }
2920
Douglas Gregor48d24112011-01-10 20:53:55 +00002921 // If we're supposed to retain a pack expansion, do so by temporarily
2922 // forgetting the partially-substituted parameter pack.
2923 if (RetainExpansion) {
2924 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2925
2926 if (getDerived().TransformTemplateArgument(Pattern, Out))
2927 return true;
2928
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002929 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2930 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002931 if (Out.getArgument().isNull())
2932 return true;
2933
2934 Outputs.addArgument(Out);
2935 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002936
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002937 continue;
2938 }
2939
2940 // The simple case:
2941 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002942 return true;
2943
2944 Outputs.addArgument(Out);
2945 }
2946
2947 return false;
2948
2949}
2950
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951//===----------------------------------------------------------------------===//
2952// Type transformation
2953//===----------------------------------------------------------------------===//
2954
2955template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002956QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957 if (getDerived().AlreadyTransformed(T))
2958 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002959
John McCall550e0c22009-10-21 00:40:46 +00002960 // Temporary workaround. All of these transformations should
2961 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002962 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002963 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002964
John McCall31f82722010-11-12 08:19:04 +00002965 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002966
John McCall550e0c22009-10-21 00:40:46 +00002967 if (!NewDI)
2968 return QualType();
2969
2970 return NewDI->getType();
2971}
2972
2973template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002974TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002975 if (getDerived().AlreadyTransformed(DI->getType()))
2976 return DI;
2977
2978 TypeLocBuilder TLB;
2979
2980 TypeLoc TL = DI->getTypeLoc();
2981 TLB.reserve(TL.getFullDataSize());
2982
John McCall31f82722010-11-12 08:19:04 +00002983 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002984 if (Result.isNull())
2985 return 0;
2986
John McCallbcd03502009-12-07 02:54:59 +00002987 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002988}
2989
2990template<typename Derived>
2991QualType
John McCall31f82722010-11-12 08:19:04 +00002992TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002993 switch (T.getTypeLocClass()) {
2994#define ABSTRACT_TYPELOC(CLASS, PARENT)
2995#define TYPELOC(CLASS, PARENT) \
2996 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002997 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002998#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002999 }
Mike Stump11289f42009-09-09 15:08:12 +00003000
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003001 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003002 return QualType();
3003}
3004
3005/// FIXME: By default, this routine adds type qualifiers only to types
3006/// that can have qualifiers, and silently suppresses those qualifiers
3007/// that are not permitted (e.g., qualifiers on reference or function
3008/// types). This is the right thing for template instantiation, but
3009/// probably not for other clients.
3010template<typename Derived>
3011QualType
3012TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003013 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003014 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003015
John McCall31f82722010-11-12 08:19:04 +00003016 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003017 if (Result.isNull())
3018 return QualType();
3019
3020 // Silently suppress qualifiers if the result type can't be qualified.
3021 // FIXME: this is the right thing for template instantiation, but
3022 // probably not for other clients.
3023 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003024 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003025
John McCallcb0f89a2010-06-05 06:41:15 +00003026 if (!Quals.empty()) {
3027 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3028 TLB.push<QualifiedTypeLoc>(Result);
3029 // No location information to preserve.
3030 }
John McCall550e0c22009-10-21 00:40:46 +00003031
3032 return Result;
3033}
3034
John McCall31f82722010-11-12 08:19:04 +00003035/// \brief Transforms a type that was written in a scope specifier,
3036/// given an object type, the results of unqualified lookup, and
3037/// an already-instantiated prefix.
3038///
3039/// The object type is provided iff the scope specifier qualifies the
3040/// member of a dependent member-access expression. The prefix is
3041/// provided iff the the scope specifier in which this appears has a
3042/// prefix.
3043///
3044/// This is private to TreeTransform.
3045template<typename Derived>
3046QualType
3047TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3048 QualType ObjectType,
3049 NamedDecl *UnqualLookup,
3050 NestedNameSpecifier *Prefix) {
3051 if (getDerived().AlreadyTransformed(T))
3052 return T;
3053
3054 TypeSourceInfo *TSI =
3055 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
3056
3057 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3058 UnqualLookup, Prefix);
3059 if (!TSI) return QualType();
3060 return TSI->getType();
3061}
3062
3063template<typename Derived>
3064TypeSourceInfo *
3065TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3066 QualType ObjectType,
3067 NamedDecl *UnqualLookup,
3068 NestedNameSpecifier *Prefix) {
3069 // TODO: in some cases, we might be some verification to do here.
3070 if (ObjectType.isNull())
3071 return getDerived().TransformType(TSI);
3072
3073 QualType T = TSI->getType();
3074 if (getDerived().AlreadyTransformed(T))
3075 return TSI;
3076
3077 TypeLocBuilder TLB;
3078 QualType Result;
3079
3080 if (isa<TemplateSpecializationType>(T)) {
3081 TemplateSpecializationTypeLoc TL
3082 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3083
3084 TemplateName Template =
3085 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3086 ObjectType, UnqualLookup);
3087 if (Template.isNull()) return 0;
3088
3089 Result = getDerived()
3090 .TransformTemplateSpecializationType(TLB, TL, Template);
3091 } else if (isa<DependentTemplateSpecializationType>(T)) {
3092 DependentTemplateSpecializationTypeLoc TL
3093 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3094
3095 Result = getDerived()
3096 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3097 } else {
3098 // Nothing special needs to be done for these.
3099 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3100 }
3101
3102 if (Result.isNull()) return 0;
3103 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3104}
3105
John McCall550e0c22009-10-21 00:40:46 +00003106template <class TyLoc> static inline
3107QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3108 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3109 NewT.setNameLoc(T.getNameLoc());
3110 return T.getType();
3111}
3112
John McCall550e0c22009-10-21 00:40:46 +00003113template<typename Derived>
3114QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003115 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003116 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3117 NewT.setBuiltinLoc(T.getBuiltinLoc());
3118 if (T.needsExtraLocalData())
3119 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3120 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121}
Mike Stump11289f42009-09-09 15:08:12 +00003122
Douglas Gregord6ff3322009-08-04 16:50:30 +00003123template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003124QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003125 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003126 // FIXME: recurse?
3127 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128}
Mike Stump11289f42009-09-09 15:08:12 +00003129
Douglas Gregord6ff3322009-08-04 16:50:30 +00003130template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003131QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003132 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003133 QualType PointeeType
3134 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003135 if (PointeeType.isNull())
3136 return QualType();
3137
3138 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003139 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003140 // A dependent pointer type 'T *' has is being transformed such
3141 // that an Objective-C class type is being replaced for 'T'. The
3142 // resulting pointer type is an ObjCObjectPointerType, not a
3143 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003144 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003145
John McCall8b07ec22010-05-15 11:32:37 +00003146 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3147 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003148 return Result;
3149 }
John McCall31f82722010-11-12 08:19:04 +00003150
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003151 if (getDerived().AlwaysRebuild() ||
3152 PointeeType != TL.getPointeeLoc().getType()) {
3153 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3154 if (Result.isNull())
3155 return QualType();
3156 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003157
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003158 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3159 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003160 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003161}
Mike Stump11289f42009-09-09 15:08:12 +00003162
3163template<typename Derived>
3164QualType
John McCall550e0c22009-10-21 00:40:46 +00003165TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003166 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003167 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003168 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3169 if (PointeeType.isNull())
3170 return QualType();
3171
3172 QualType Result = TL.getType();
3173 if (getDerived().AlwaysRebuild() ||
3174 PointeeType != TL.getPointeeLoc().getType()) {
3175 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003176 TL.getSigilLoc());
3177 if (Result.isNull())
3178 return QualType();
3179 }
3180
Douglas Gregor049211a2010-04-22 16:50:51 +00003181 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003182 NewT.setSigilLoc(TL.getSigilLoc());
3183 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003184}
3185
John McCall70dd5f62009-10-30 00:06:24 +00003186/// Transforms a reference type. Note that somewhat paradoxically we
3187/// don't care whether the type itself is an l-value type or an r-value
3188/// type; we only care if the type was *written* as an l-value type
3189/// or an r-value type.
3190template<typename Derived>
3191QualType
3192TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003193 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003194 const ReferenceType *T = TL.getTypePtr();
3195
3196 // Note that this works with the pointee-as-written.
3197 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3198 if (PointeeType.isNull())
3199 return QualType();
3200
3201 QualType Result = TL.getType();
3202 if (getDerived().AlwaysRebuild() ||
3203 PointeeType != T->getPointeeTypeAsWritten()) {
3204 Result = getDerived().RebuildReferenceType(PointeeType,
3205 T->isSpelledAsLValue(),
3206 TL.getSigilLoc());
3207 if (Result.isNull())
3208 return QualType();
3209 }
3210
3211 // r-value references can be rebuilt as l-value references.
3212 ReferenceTypeLoc NewTL;
3213 if (isa<LValueReferenceType>(Result))
3214 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3215 else
3216 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3217 NewTL.setSigilLoc(TL.getSigilLoc());
3218
3219 return Result;
3220}
3221
Mike Stump11289f42009-09-09 15:08:12 +00003222template<typename Derived>
3223QualType
John McCall550e0c22009-10-21 00:40:46 +00003224TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003225 LValueReferenceTypeLoc TL) {
3226 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003227}
3228
Mike Stump11289f42009-09-09 15:08:12 +00003229template<typename Derived>
3230QualType
John McCall550e0c22009-10-21 00:40:46 +00003231TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003232 RValueReferenceTypeLoc TL) {
3233 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003234}
Mike Stump11289f42009-09-09 15:08:12 +00003235
Douglas Gregord6ff3322009-08-04 16:50:30 +00003236template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003237QualType
John McCall550e0c22009-10-21 00:40:46 +00003238TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003239 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003240 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003241
3242 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003243 if (PointeeType.isNull())
3244 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003245
John McCall550e0c22009-10-21 00:40:46 +00003246 // TODO: preserve source information for this.
3247 QualType ClassType
3248 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003249 if (ClassType.isNull())
3250 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003251
John McCall550e0c22009-10-21 00:40:46 +00003252 QualType Result = TL.getType();
3253 if (getDerived().AlwaysRebuild() ||
3254 PointeeType != T->getPointeeType() ||
3255 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003256 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3257 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003258 if (Result.isNull())
3259 return QualType();
3260 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003261
John McCall550e0c22009-10-21 00:40:46 +00003262 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3263 NewTL.setSigilLoc(TL.getSigilLoc());
3264
3265 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266}
3267
Mike Stump11289f42009-09-09 15:08:12 +00003268template<typename Derived>
3269QualType
John McCall550e0c22009-10-21 00:40:46 +00003270TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003271 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003272 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003273 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003274 if (ElementType.isNull())
3275 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003276
John McCall550e0c22009-10-21 00:40:46 +00003277 QualType Result = TL.getType();
3278 if (getDerived().AlwaysRebuild() ||
3279 ElementType != T->getElementType()) {
3280 Result = getDerived().RebuildConstantArrayType(ElementType,
3281 T->getSizeModifier(),
3282 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003283 T->getIndexTypeCVRQualifiers(),
3284 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003285 if (Result.isNull())
3286 return QualType();
3287 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003288
John McCall550e0c22009-10-21 00:40:46 +00003289 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3290 NewTL.setLBracketLoc(TL.getLBracketLoc());
3291 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003292
John McCall550e0c22009-10-21 00:40:46 +00003293 Expr *Size = TL.getSizeExpr();
3294 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003295 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003296 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3297 }
3298 NewTL.setSizeExpr(Size);
3299
3300 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003301}
Mike Stump11289f42009-09-09 15:08:12 +00003302
Douglas Gregord6ff3322009-08-04 16:50:30 +00003303template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003305 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003306 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003307 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003308 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003309 if (ElementType.isNull())
3310 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 QualType Result = TL.getType();
3313 if (getDerived().AlwaysRebuild() ||
3314 ElementType != T->getElementType()) {
3315 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003317 T->getIndexTypeCVRQualifiers(),
3318 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003319 if (Result.isNull())
3320 return QualType();
3321 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003322
John McCall550e0c22009-10-21 00:40:46 +00003323 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3324 NewTL.setLBracketLoc(TL.getLBracketLoc());
3325 NewTL.setRBracketLoc(TL.getRBracketLoc());
3326 NewTL.setSizeExpr(0);
3327
3328 return Result;
3329}
3330
3331template<typename Derived>
3332QualType
3333TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003334 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003335 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003336 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3337 if (ElementType.isNull())
3338 return QualType();
3339
3340 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003341 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003342
John McCalldadc5752010-08-24 06:29:42 +00003343 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003344 = getDerived().TransformExpr(T->getSizeExpr());
3345 if (SizeResult.isInvalid())
3346 return QualType();
3347
John McCallb268a282010-08-23 23:25:46 +00003348 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003349
3350 QualType Result = TL.getType();
3351 if (getDerived().AlwaysRebuild() ||
3352 ElementType != T->getElementType() ||
3353 Size != T->getSizeExpr()) {
3354 Result = getDerived().RebuildVariableArrayType(ElementType,
3355 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003356 Size,
John McCall550e0c22009-10-21 00:40:46 +00003357 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003358 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003359 if (Result.isNull())
3360 return QualType();
3361 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003362
John McCall550e0c22009-10-21 00:40:46 +00003363 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3364 NewTL.setLBracketLoc(TL.getLBracketLoc());
3365 NewTL.setRBracketLoc(TL.getRBracketLoc());
3366 NewTL.setSizeExpr(Size);
3367
3368 return Result;
3369}
3370
3371template<typename Derived>
3372QualType
3373TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003374 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003375 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003376 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3377 if (ElementType.isNull())
3378 return QualType();
3379
3380 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003381 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003382
John McCall33ddac02011-01-19 10:06:00 +00003383 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3384 Expr *origSize = TL.getSizeExpr();
3385 if (!origSize) origSize = T->getSizeExpr();
3386
3387 ExprResult sizeResult
3388 = getDerived().TransformExpr(origSize);
3389 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003390 return QualType();
3391
John McCall33ddac02011-01-19 10:06:00 +00003392 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003393
3394 QualType Result = TL.getType();
3395 if (getDerived().AlwaysRebuild() ||
3396 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003397 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003398 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3399 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003400 size,
John McCall550e0c22009-10-21 00:40:46 +00003401 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003402 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003403 if (Result.isNull())
3404 return QualType();
3405 }
John McCall550e0c22009-10-21 00:40:46 +00003406
3407 // We might have any sort of array type now, but fortunately they
3408 // all have the same location layout.
3409 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3410 NewTL.setLBracketLoc(TL.getLBracketLoc());
3411 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003412 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003413
3414 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003415}
Mike Stump11289f42009-09-09 15:08:12 +00003416
3417template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003418QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003419 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003420 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003421 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003422
3423 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424 QualType ElementType = getDerived().TransformType(T->getElementType());
3425 if (ElementType.isNull())
3426 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003427
Douglas Gregore922c772009-08-04 22:27:00 +00003428 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003429 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003430
John McCalldadc5752010-08-24 06:29:42 +00003431 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003432 if (Size.isInvalid())
3433 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003434
John McCall550e0c22009-10-21 00:40:46 +00003435 QualType Result = TL.getType();
3436 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003437 ElementType != T->getElementType() ||
3438 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003439 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003440 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003441 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003442 if (Result.isNull())
3443 return QualType();
3444 }
John McCall550e0c22009-10-21 00:40:46 +00003445
3446 // Result might be dependent or not.
3447 if (isa<DependentSizedExtVectorType>(Result)) {
3448 DependentSizedExtVectorTypeLoc NewTL
3449 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3450 NewTL.setNameLoc(TL.getNameLoc());
3451 } else {
3452 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3453 NewTL.setNameLoc(TL.getNameLoc());
3454 }
3455
3456 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003457}
Mike Stump11289f42009-09-09 15:08:12 +00003458
3459template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003460QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003461 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003462 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003463 QualType ElementType = getDerived().TransformType(T->getElementType());
3464 if (ElementType.isNull())
3465 return QualType();
3466
John McCall550e0c22009-10-21 00:40:46 +00003467 QualType Result = TL.getType();
3468 if (getDerived().AlwaysRebuild() ||
3469 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003470 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003471 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003472 if (Result.isNull())
3473 return QualType();
3474 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003475
John McCall550e0c22009-10-21 00:40:46 +00003476 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3477 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003478
John McCall550e0c22009-10-21 00:40:46 +00003479 return Result;
3480}
3481
3482template<typename Derived>
3483QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003484 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003485 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003486 QualType ElementType = getDerived().TransformType(T->getElementType());
3487 if (ElementType.isNull())
3488 return QualType();
3489
3490 QualType Result = TL.getType();
3491 if (getDerived().AlwaysRebuild() ||
3492 ElementType != T->getElementType()) {
3493 Result = getDerived().RebuildExtVectorType(ElementType,
3494 T->getNumElements(),
3495 /*FIXME*/ SourceLocation());
3496 if (Result.isNull())
3497 return QualType();
3498 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003499
John McCall550e0c22009-10-21 00:40:46 +00003500 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3501 NewTL.setNameLoc(TL.getNameLoc());
3502
3503 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504}
Mike Stump11289f42009-09-09 15:08:12 +00003505
3506template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003507ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003508TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3509 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003510 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003511 TypeSourceInfo *NewDI = 0;
3512
3513 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3514 // If we're substituting into a pack expansion type and we know the
3515 TypeLoc OldTL = OldDI->getTypeLoc();
3516 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3517
3518 TypeLocBuilder TLB;
3519 TypeLoc NewTL = OldDI->getTypeLoc();
3520 TLB.reserve(NewTL.getFullDataSize());
3521
3522 QualType Result = getDerived().TransformType(TLB,
3523 OldExpansionTL.getPatternLoc());
3524 if (Result.isNull())
3525 return 0;
3526
3527 Result = RebuildPackExpansionType(Result,
3528 OldExpansionTL.getPatternLoc().getSourceRange(),
3529 OldExpansionTL.getEllipsisLoc(),
3530 NumExpansions);
3531 if (Result.isNull())
3532 return 0;
3533
3534 PackExpansionTypeLoc NewExpansionTL
3535 = TLB.push<PackExpansionTypeLoc>(Result);
3536 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3537 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3538 } else
3539 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003540 if (!NewDI)
3541 return 0;
3542
3543 if (NewDI == OldDI)
3544 return OldParm;
3545 else
3546 return ParmVarDecl::Create(SemaRef.Context,
3547 OldParm->getDeclContext(),
3548 OldParm->getLocation(),
3549 OldParm->getIdentifier(),
3550 NewDI->getType(),
3551 NewDI,
3552 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003553 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003554 /* DefArg */ NULL);
3555}
3556
3557template<typename Derived>
3558bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003559 TransformFunctionTypeParams(SourceLocation Loc,
3560 ParmVarDecl **Params, unsigned NumParams,
3561 const QualType *ParamTypes,
3562 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3563 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3564 for (unsigned i = 0; i != NumParams; ++i) {
3565 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003566 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003567 if (OldParm->isParameterPack()) {
3568 // We have a function parameter pack that may need to be expanded.
3569 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003570
Douglas Gregor5499af42011-01-05 23:12:31 +00003571 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003572 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3573 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3574 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3575 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003576
3577 // Determine whether we should expand the parameter packs.
3578 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003579 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003580 llvm::Optional<unsigned> OrigNumExpansions
3581 = ExpansionTL.getTypePtr()->getNumExpansions();
3582 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003583 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3584 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003585 Unexpanded.data(),
3586 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003587 ShouldExpand,
3588 RetainExpansion,
3589 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003590 return true;
3591 }
3592
3593 if (ShouldExpand) {
3594 // Expand the function parameter pack into multiple, separate
3595 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003596 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003597 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003598 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3599 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003600 = getDerived().TransformFunctionTypeParam(OldParm,
3601 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003602 if (!NewParm)
3603 return true;
3604
Douglas Gregordd472162011-01-07 00:20:55 +00003605 OutParamTypes.push_back(NewParm->getType());
3606 if (PVars)
3607 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003608 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003609
3610 // If we're supposed to retain a pack expansion, do so by temporarily
3611 // forgetting the partially-substituted parameter pack.
3612 if (RetainExpansion) {
3613 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3614 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003615 = getDerived().TransformFunctionTypeParam(OldParm,
3616 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003617 if (!NewParm)
3618 return true;
3619
3620 OutParamTypes.push_back(NewParm->getType());
3621 if (PVars)
3622 PVars->push_back(NewParm);
3623 }
3624
Douglas Gregor5499af42011-01-05 23:12:31 +00003625 // We're done with the pack expansion.
3626 continue;
3627 }
3628
3629 // We'll substitute the parameter now without expanding the pack
3630 // expansion.
3631 }
3632
3633 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003634 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3635 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003636 if (!NewParm)
3637 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003638
Douglas Gregordd472162011-01-07 00:20:55 +00003639 OutParamTypes.push_back(NewParm->getType());
3640 if (PVars)
3641 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003642 continue;
3643 }
John McCall58f10c32010-03-11 09:03:00 +00003644
3645 // Deal with the possibility that we don't have a parameter
3646 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003647 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003648 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003649 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003650 if (const PackExpansionType *Expansion
3651 = dyn_cast<PackExpansionType>(OldType)) {
3652 // We have a function parameter pack that may need to be expanded.
3653 QualType Pattern = Expansion->getPattern();
3654 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3655 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3656
3657 // Determine whether we should expand the parameter packs.
3658 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003659 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003660 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003661 Unexpanded.data(),
3662 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003663 ShouldExpand,
3664 RetainExpansion,
3665 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003666 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003667 }
3668
3669 if (ShouldExpand) {
3670 // Expand the function parameter pack into multiple, separate
3671 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003672 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003673 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3674 QualType NewType = getDerived().TransformType(Pattern);
3675 if (NewType.isNull())
3676 return true;
John McCall58f10c32010-03-11 09:03:00 +00003677
Douglas Gregordd472162011-01-07 00:20:55 +00003678 OutParamTypes.push_back(NewType);
3679 if (PVars)
3680 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003681 }
3682
3683 // We're done with the pack expansion.
3684 continue;
3685 }
3686
Douglas Gregor48d24112011-01-10 20:53:55 +00003687 // If we're supposed to retain a pack expansion, do so by temporarily
3688 // forgetting the partially-substituted parameter pack.
3689 if (RetainExpansion) {
3690 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3691 QualType NewType = getDerived().TransformType(Pattern);
3692 if (NewType.isNull())
3693 return true;
3694
3695 OutParamTypes.push_back(NewType);
3696 if (PVars)
3697 PVars->push_back(0);
3698 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003699
Douglas Gregor5499af42011-01-05 23:12:31 +00003700 // We'll substitute the parameter now without expanding the pack
3701 // expansion.
3702 OldType = Expansion->getPattern();
3703 IsPackExpansion = true;
3704 }
3705
3706 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3707 QualType NewType = getDerived().TransformType(OldType);
3708 if (NewType.isNull())
3709 return true;
3710
3711 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003712 NewType = getSema().Context.getPackExpansionType(NewType,
3713 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003714
Douglas Gregordd472162011-01-07 00:20:55 +00003715 OutParamTypes.push_back(NewType);
3716 if (PVars)
3717 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003718 }
3719
3720 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003721 }
John McCall58f10c32010-03-11 09:03:00 +00003722
3723template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003724QualType
John McCall550e0c22009-10-21 00:40:46 +00003725TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003726 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003727 // Transform the parameters and return type.
3728 //
3729 // We instantiate in source order, with the return type first followed by
3730 // the parameters, because users tend to expect this (even if they shouldn't
3731 // rely on it!).
3732 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003733 // When the function has a trailing return type, we instantiate the
3734 // parameters before the return type, since the return type can then refer
3735 // to the parameters themselves (via decltype, sizeof, etc.).
3736 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003737 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003738 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003739 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003740
Douglas Gregor7fb25412010-10-01 18:44:50 +00003741 QualType ResultType;
3742
3743 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003744 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3745 TL.getParmArray(),
3746 TL.getNumArgs(),
3747 TL.getTypePtr()->arg_type_begin(),
3748 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003749 return QualType();
3750
3751 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3752 if (ResultType.isNull())
3753 return QualType();
3754 }
3755 else {
3756 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3757 if (ResultType.isNull())
3758 return QualType();
3759
Douglas Gregordd472162011-01-07 00:20:55 +00003760 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3761 TL.getParmArray(),
3762 TL.getNumArgs(),
3763 TL.getTypePtr()->arg_type_begin(),
3764 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003765 return QualType();
3766 }
3767
John McCall550e0c22009-10-21 00:40:46 +00003768 QualType Result = TL.getType();
3769 if (getDerived().AlwaysRebuild() ||
3770 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003771 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003772 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3773 Result = getDerived().RebuildFunctionProtoType(ResultType,
3774 ParamTypes.data(),
3775 ParamTypes.size(),
3776 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003777 T->getTypeQuals(),
3778 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003779 if (Result.isNull())
3780 return QualType();
3781 }
Mike Stump11289f42009-09-09 15:08:12 +00003782
John McCall550e0c22009-10-21 00:40:46 +00003783 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3784 NewTL.setLParenLoc(TL.getLParenLoc());
3785 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003786 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003787 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3788 NewTL.setArg(i, ParamDecls[i]);
3789
3790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003791}
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregord6ff3322009-08-04 16:50:30 +00003793template<typename Derived>
3794QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003795 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003796 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003797 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003798 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3799 if (ResultType.isNull())
3800 return QualType();
3801
3802 QualType Result = TL.getType();
3803 if (getDerived().AlwaysRebuild() ||
3804 ResultType != T->getResultType())
3805 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3806
3807 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3808 NewTL.setLParenLoc(TL.getLParenLoc());
3809 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003810 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003811
3812 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003813}
Mike Stump11289f42009-09-09 15:08:12 +00003814
John McCallb96ec562009-12-04 22:46:56 +00003815template<typename Derived> QualType
3816TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003817 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003818 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003819 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003820 if (!D)
3821 return QualType();
3822
3823 QualType Result = TL.getType();
3824 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3825 Result = getDerived().RebuildUnresolvedUsingType(D);
3826 if (Result.isNull())
3827 return QualType();
3828 }
3829
3830 // We might get an arbitrary type spec type back. We should at
3831 // least always get a type spec type, though.
3832 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3833 NewTL.setNameLoc(TL.getNameLoc());
3834
3835 return Result;
3836}
3837
Douglas Gregord6ff3322009-08-04 16:50:30 +00003838template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003839QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003840 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003841 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003842 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003843 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3844 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003845 if (!Typedef)
3846 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003847
John McCall550e0c22009-10-21 00:40:46 +00003848 QualType Result = TL.getType();
3849 if (getDerived().AlwaysRebuild() ||
3850 Typedef != T->getDecl()) {
3851 Result = getDerived().RebuildTypedefType(Typedef);
3852 if (Result.isNull())
3853 return QualType();
3854 }
Mike Stump11289f42009-09-09 15:08:12 +00003855
John McCall550e0c22009-10-21 00:40:46 +00003856 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3857 NewTL.setNameLoc(TL.getNameLoc());
3858
3859 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003860}
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003863QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003864 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003865 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003866 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003867
John McCalldadc5752010-08-24 06:29:42 +00003868 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003869 if (E.isInvalid())
3870 return QualType();
3871
John McCall550e0c22009-10-21 00:40:46 +00003872 QualType Result = TL.getType();
3873 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003874 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003875 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003876 if (Result.isNull())
3877 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003878 }
John McCall550e0c22009-10-21 00:40:46 +00003879 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003880
John McCall550e0c22009-10-21 00:40:46 +00003881 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003882 NewTL.setTypeofLoc(TL.getTypeofLoc());
3883 NewTL.setLParenLoc(TL.getLParenLoc());
3884 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003885
3886 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003887}
Mike Stump11289f42009-09-09 15:08:12 +00003888
3889template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003890QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003891 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003892 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3893 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3894 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003895 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003896
John McCall550e0c22009-10-21 00:40:46 +00003897 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003898 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3899 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003900 if (Result.isNull())
3901 return QualType();
3902 }
Mike Stump11289f42009-09-09 15:08:12 +00003903
John McCall550e0c22009-10-21 00:40:46 +00003904 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003905 NewTL.setTypeofLoc(TL.getTypeofLoc());
3906 NewTL.setLParenLoc(TL.getLParenLoc());
3907 NewTL.setRParenLoc(TL.getRParenLoc());
3908 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003915 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003916 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003917
Douglas Gregore922c772009-08-04 22:27:00 +00003918 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003919 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003920
John McCalldadc5752010-08-24 06:29:42 +00003921 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003922 if (E.isInvalid())
3923 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003924
John McCall550e0c22009-10-21 00:40:46 +00003925 QualType Result = TL.getType();
3926 if (getDerived().AlwaysRebuild() ||
3927 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003928 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003929 if (Result.isNull())
3930 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003931 }
John McCall550e0c22009-10-21 00:40:46 +00003932 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003933
John McCall550e0c22009-10-21 00:40:46 +00003934 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3935 NewTL.setNameLoc(TL.getNameLoc());
3936
3937 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003938}
3939
3940template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003941QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003942 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003943 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003944 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003945 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3946 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003947 if (!Record)
3948 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003949
John McCall550e0c22009-10-21 00:40:46 +00003950 QualType Result = TL.getType();
3951 if (getDerived().AlwaysRebuild() ||
3952 Record != T->getDecl()) {
3953 Result = getDerived().RebuildRecordType(Record);
3954 if (Result.isNull())
3955 return QualType();
3956 }
Mike Stump11289f42009-09-09 15:08:12 +00003957
John McCall550e0c22009-10-21 00:40:46 +00003958 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3959 NewTL.setNameLoc(TL.getNameLoc());
3960
3961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003962}
Mike Stump11289f42009-09-09 15:08:12 +00003963
3964template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003965QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003966 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003967 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003969 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3970 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003971 if (!Enum)
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 Enum != T->getDecl()) {
3977 Result = getDerived().RebuildEnumType(Enum);
3978 if (Result.isNull())
3979 return QualType();
3980 }
Mike Stump11289f42009-09-09 15:08:12 +00003981
John McCall550e0c22009-10-21 00:40:46 +00003982 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3983 NewTL.setNameLoc(TL.getNameLoc());
3984
3985 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986}
John McCallfcc33b02009-09-05 00:15:47 +00003987
John McCalle78aac42010-03-10 03:28:59 +00003988template<typename Derived>
3989QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3990 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003991 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003992 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3993 TL.getTypePtr()->getDecl());
3994 if (!D) return QualType();
3995
3996 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3997 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3998 return T;
3999}
4000
Douglas Gregord6ff3322009-08-04 16:50:30 +00004001template<typename Derived>
4002QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004003 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004004 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004005 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004006}
4007
Mike Stump11289f42009-09-09 15:08:12 +00004008template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004009QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004010 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004011 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004012 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004013}
4014
4015template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004016QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4017 TypeLocBuilder &TLB,
4018 SubstTemplateTypeParmPackTypeLoc TL) {
4019 return TransformTypeSpecType(TLB, TL);
4020}
4021
4022template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004023QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004024 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004025 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004026 const TemplateSpecializationType *T = TL.getTypePtr();
4027
Mike Stump11289f42009-09-09 15:08:12 +00004028 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004029 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004030 if (Template.isNull())
4031 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004032
John McCall31f82722010-11-12 08:19:04 +00004033 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4034}
4035
Douglas Gregorfe921a72010-12-20 23:36:19 +00004036namespace {
4037 /// \brief Simple iterator that traverses the template arguments in a
4038 /// container that provides a \c getArgLoc() member function.
4039 ///
4040 /// This iterator is intended to be used with the iterator form of
4041 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4042 template<typename ArgLocContainer>
4043 class TemplateArgumentLocContainerIterator {
4044 ArgLocContainer *Container;
4045 unsigned Index;
4046
4047 public:
4048 typedef TemplateArgumentLoc value_type;
4049 typedef TemplateArgumentLoc reference;
4050 typedef int difference_type;
4051 typedef std::input_iterator_tag iterator_category;
4052
4053 class pointer {
4054 TemplateArgumentLoc Arg;
4055
4056 public:
4057 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4058
4059 const TemplateArgumentLoc *operator->() const {
4060 return &Arg;
4061 }
4062 };
4063
4064
4065 TemplateArgumentLocContainerIterator() {}
4066
4067 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4068 unsigned Index)
4069 : Container(&Container), Index(Index) { }
4070
4071 TemplateArgumentLocContainerIterator &operator++() {
4072 ++Index;
4073 return *this;
4074 }
4075
4076 TemplateArgumentLocContainerIterator operator++(int) {
4077 TemplateArgumentLocContainerIterator Old(*this);
4078 ++(*this);
4079 return Old;
4080 }
4081
4082 TemplateArgumentLoc operator*() const {
4083 return Container->getArgLoc(Index);
4084 }
4085
4086 pointer operator->() const {
4087 return pointer(Container->getArgLoc(Index));
4088 }
4089
4090 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004091 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004092 return X.Container == Y.Container && X.Index == Y.Index;
4093 }
4094
4095 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004096 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004097 return !(X == Y);
4098 }
4099 };
4100}
4101
4102
John McCall31f82722010-11-12 08:19:04 +00004103template <typename Derived>
4104QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4105 TypeLocBuilder &TLB,
4106 TemplateSpecializationTypeLoc TL,
4107 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004108 TemplateArgumentListInfo NewTemplateArgs;
4109 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4110 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004111 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4112 ArgIterator;
4113 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4114 ArgIterator(TL, TL.getNumArgs()),
4115 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004117
John McCall0ad16662009-10-29 08:12:44 +00004118 // FIXME: maybe don't rebuild if all the template arguments are the same.
4119
4120 QualType Result =
4121 getDerived().RebuildTemplateSpecializationType(Template,
4122 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004123 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004124
4125 if (!Result.isNull()) {
4126 TemplateSpecializationTypeLoc NewTL
4127 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4128 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4129 NewTL.setLAngleLoc(TL.getLAngleLoc());
4130 NewTL.setRAngleLoc(TL.getRAngleLoc());
4131 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4132 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133 }
Mike Stump11289f42009-09-09 15:08:12 +00004134
John McCall0ad16662009-10-29 08:12:44 +00004135 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136}
Mike Stump11289f42009-09-09 15:08:12 +00004137
4138template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004139QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004140TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004141 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004142 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004143
4144 NestedNameSpecifier *NNS = 0;
4145 // NOTE: the qualifier in an ElaboratedType is optional.
4146 if (T->getQualifier() != 0) {
4147 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004148 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004149 if (!NNS)
4150 return QualType();
4151 }
Mike Stump11289f42009-09-09 15:08:12 +00004152
John McCall31f82722010-11-12 08:19:04 +00004153 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4154 if (NamedT.isNull())
4155 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004156
John McCall550e0c22009-10-21 00:40:46 +00004157 QualType Result = TL.getType();
4158 if (getDerived().AlwaysRebuild() ||
4159 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004160 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004161 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4162 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004163 if (Result.isNull())
4164 return QualType();
4165 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004166
Abramo Bagnara6150c882010-05-11 21:36:43 +00004167 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004168 NewTL.setKeywordLoc(TL.getKeywordLoc());
4169 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004170
4171 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
4174template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004175QualType TreeTransform<Derived>::TransformAttributedType(
4176 TypeLocBuilder &TLB,
4177 AttributedTypeLoc TL) {
4178 const AttributedType *oldType = TL.getTypePtr();
4179 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4180 if (modifiedType.isNull())
4181 return QualType();
4182
4183 QualType result = TL.getType();
4184
4185 // FIXME: dependent operand expressions?
4186 if (getDerived().AlwaysRebuild() ||
4187 modifiedType != oldType->getModifiedType()) {
4188 // TODO: this is really lame; we should really be rebuilding the
4189 // equivalent type from first principles.
4190 QualType equivalentType
4191 = getDerived().TransformType(oldType->getEquivalentType());
4192 if (equivalentType.isNull())
4193 return QualType();
4194 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4195 modifiedType,
4196 equivalentType);
4197 }
4198
4199 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4200 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4201 if (TL.hasAttrOperand())
4202 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4203 if (TL.hasAttrExprOperand())
4204 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4205 else if (TL.hasAttrEnumOperand())
4206 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4207
4208 return result;
4209}
4210
4211template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004212QualType
4213TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4214 ParenTypeLoc TL) {
4215 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4216 if (Inner.isNull())
4217 return QualType();
4218
4219 QualType Result = TL.getType();
4220 if (getDerived().AlwaysRebuild() ||
4221 Inner != TL.getInnerLoc().getType()) {
4222 Result = getDerived().RebuildParenType(Inner);
4223 if (Result.isNull())
4224 return QualType();
4225 }
4226
4227 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4228 NewTL.setLParenLoc(TL.getLParenLoc());
4229 NewTL.setRParenLoc(TL.getRParenLoc());
4230 return Result;
4231}
4232
4233template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004234QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004235 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004236 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004237
Douglas Gregord6ff3322009-08-04 16:50:30 +00004238 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004239 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004240 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004241 if (!NNS)
4242 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004243
John McCallc392f372010-06-11 00:33:02 +00004244 QualType Result
4245 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4246 T->getIdentifier(),
4247 TL.getKeywordLoc(),
4248 TL.getQualifierRange(),
4249 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004250 if (Result.isNull())
4251 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004252
Abramo Bagnarad7548482010-05-19 21:37:53 +00004253 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4254 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004255 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4256
Abramo Bagnarad7548482010-05-19 21:37:53 +00004257 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4258 NewTL.setKeywordLoc(TL.getKeywordLoc());
4259 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004260 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004261 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4262 NewTL.setKeywordLoc(TL.getKeywordLoc());
4263 NewTL.setQualifierRange(TL.getQualifierRange());
4264 NewTL.setNameLoc(TL.getNameLoc());
4265 }
John McCall550e0c22009-10-21 00:40:46 +00004266 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004267}
Mike Stump11289f42009-09-09 15:08:12 +00004268
Douglas Gregord6ff3322009-08-04 16:50:30 +00004269template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004270QualType TreeTransform<Derived>::
4271 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004272 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004273 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004274
4275 NestedNameSpecifier *NNS
4276 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004277 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004278 if (!NNS)
4279 return QualType();
4280
John McCall31f82722010-11-12 08:19:04 +00004281 return getDerived()
4282 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4283}
4284
4285template<typename Derived>
4286QualType TreeTransform<Derived>::
4287 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4288 DependentTemplateSpecializationTypeLoc TL,
4289 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004290 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004291
John McCallc392f372010-06-11 00:33:02 +00004292 TemplateArgumentListInfo NewTemplateArgs;
4293 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4294 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004295
4296 typedef TemplateArgumentLocContainerIterator<
4297 DependentTemplateSpecializationTypeLoc> ArgIterator;
4298 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4299 ArgIterator(TL, TL.getNumArgs()),
4300 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004301 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004302
Douglas Gregora5614c52010-09-08 23:56:00 +00004303 QualType Result
4304 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4305 NNS,
4306 TL.getQualifierRange(),
4307 T->getIdentifier(),
4308 TL.getNameLoc(),
4309 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004310 if (Result.isNull())
4311 return QualType();
4312
4313 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4314 QualType NamedT = ElabT->getNamedType();
4315
4316 // Copy information relevant to the template specialization.
4317 TemplateSpecializationTypeLoc NamedTL
4318 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4319 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4320 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4321 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4322 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4323
4324 // Copy information relevant to the elaborated type.
4325 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4326 NewTL.setKeywordLoc(TL.getKeywordLoc());
4327 NewTL.setQualifierRange(TL.getQualifierRange());
4328 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004329 TypeLoc NewTL(Result, TL.getOpaqueData());
4330 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004331 }
4332 return Result;
4333}
4334
4335template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004336QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4337 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004338 QualType Pattern
4339 = getDerived().TransformType(TLB, TL.getPatternLoc());
4340 if (Pattern.isNull())
4341 return QualType();
4342
4343 QualType Result = TL.getType();
4344 if (getDerived().AlwaysRebuild() ||
4345 Pattern != TL.getPatternLoc().getType()) {
4346 Result = getDerived().RebuildPackExpansionType(Pattern,
4347 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004348 TL.getEllipsisLoc(),
4349 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004350 if (Result.isNull())
4351 return QualType();
4352 }
4353
4354 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4355 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4356 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004357}
4358
4359template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004360QualType
4361TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004362 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004363 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004364 TLB.pushFullCopy(TL);
4365 return TL.getType();
4366}
4367
4368template<typename Derived>
4369QualType
4370TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004371 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004372 // ObjCObjectType is never dependent.
4373 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004374 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004375}
Mike Stump11289f42009-09-09 15:08:12 +00004376
4377template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004378QualType
4379TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004380 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004381 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004382 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004383 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004384}
4385
Douglas Gregord6ff3322009-08-04 16:50:30 +00004386//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004387// Statement transformation
4388//===----------------------------------------------------------------------===//
4389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004390StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004391TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004392 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004393}
4394
4395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004396StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004397TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4398 return getDerived().TransformCompoundStmt(S, false);
4399}
4400
4401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004402StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004403TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004404 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004405 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004406 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004407 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004408 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4409 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004410 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004411 if (Result.isInvalid()) {
4412 // Immediately fail if this was a DeclStmt, since it's very
4413 // likely that this will cause problems for future statements.
4414 if (isa<DeclStmt>(*B))
4415 return StmtError();
4416
4417 // Otherwise, just keep processing substatements and fail later.
4418 SubStmtInvalid = true;
4419 continue;
4420 }
Mike Stump11289f42009-09-09 15:08:12 +00004421
Douglas Gregorebe10102009-08-20 07:17:43 +00004422 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4423 Statements.push_back(Result.takeAs<Stmt>());
4424 }
Mike Stump11289f42009-09-09 15:08:12 +00004425
John McCall1ababa62010-08-27 19:56:05 +00004426 if (SubStmtInvalid)
4427 return StmtError();
4428
Douglas Gregorebe10102009-08-20 07:17:43 +00004429 if (!getDerived().AlwaysRebuild() &&
4430 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004431 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004432
4433 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4434 move_arg(Statements),
4435 S->getRBracLoc(),
4436 IsStmtExpr);
4437}
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregorebe10102009-08-20 07:17:43 +00004439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004440StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004441TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004442 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004443 {
4444 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004445 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004446
Eli Friedman06577382009-11-19 03:14:00 +00004447 // Transform the left-hand case value.
4448 LHS = getDerived().TransformExpr(S->getLHS());
4449 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004450 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004451
Eli Friedman06577382009-11-19 03:14:00 +00004452 // Transform the right-hand case value (for the GNU case-range extension).
4453 RHS = getDerived().TransformExpr(S->getRHS());
4454 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004455 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004456 }
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregorebe10102009-08-20 07:17:43 +00004458 // Build the case statement.
4459 // Case statements are always rebuilt so that they will attached to their
4460 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004461 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004462 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004463 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004464 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004465 S->getColonLoc());
4466 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004467 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004468
Douglas Gregorebe10102009-08-20 07:17:43 +00004469 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004470 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004471 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004472 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregorebe10102009-08-20 07:17:43 +00004474 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004475 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004476}
4477
4478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004479StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004480TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004481 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004482 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004483 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004484 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregorebe10102009-08-20 07:17:43 +00004486 // Default statements are always rebuilt
4487 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004488 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004489}
Mike Stump11289f42009-09-09 15:08:12 +00004490
Douglas Gregorebe10102009-08-20 07:17:43 +00004491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004492StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004493TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
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 // FIXME: Pass the real colon location in.
4499 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4500 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004501 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004502}
Mike Stump11289f42009-09-09 15:08:12 +00004503
Douglas Gregorebe10102009-08-20 07:17:43 +00004504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004505StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004506TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004507 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004508 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004509 VarDecl *ConditionVar = 0;
4510 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004511 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004512 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004513 getDerived().TransformDefinition(
4514 S->getConditionVariable()->getLocation(),
4515 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004516 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004517 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004518 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004519 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004520
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004521 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004522 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004523
4524 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004525 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004526 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4527 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004528 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004529 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004530
John McCallb268a282010-08-23 23:25:46 +00004531 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004532 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004533 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004534
John McCallb268a282010-08-23 23:25:46 +00004535 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4536 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004537 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004538
Douglas Gregorebe10102009-08-20 07:17:43 +00004539 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004540 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004541 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004542 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregorebe10102009-08-20 07:17:43 +00004544 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004545 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004546 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004547 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregorebe10102009-08-20 07:17:43 +00004549 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004550 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004551 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004552 Then.get() == S->getThen() &&
4553 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004554 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004555
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004556 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004557 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004558 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004559}
4560
4561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004562StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004563TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004564 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004565 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004566 VarDecl *ConditionVar = 0;
4567 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004568 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004569 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004570 getDerived().TransformDefinition(
4571 S->getConditionVariable()->getLocation(),
4572 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004573 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004574 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004575 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004576 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004577
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004578 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004579 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004580 }
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregorebe10102009-08-20 07:17:43 +00004582 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004583 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004584 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004585 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004586 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004587 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004588
Douglas Gregorebe10102009-08-20 07:17:43 +00004589 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004590 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004591 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004592 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004593
Douglas Gregorebe10102009-08-20 07:17:43 +00004594 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004595 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4596 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004597}
Mike Stump11289f42009-09-09 15:08:12 +00004598
Douglas Gregorebe10102009-08-20 07:17:43 +00004599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004600StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004601TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004602 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004603 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004604 VarDecl *ConditionVar = 0;
4605 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004606 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004607 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004608 getDerived().TransformDefinition(
4609 S->getConditionVariable()->getLocation(),
4610 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004611 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004612 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004613 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004614 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004615
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004616 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004617 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004618
4619 if (S->getCond()) {
4620 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004621 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4622 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004623 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004624 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004625 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004626 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004627 }
Mike Stump11289f42009-09-09 15:08:12 +00004628
John McCallb268a282010-08-23 23:25:46 +00004629 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4630 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004631 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004632
Douglas Gregorebe10102009-08-20 07:17:43 +00004633 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004634 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004635 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004636 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregorebe10102009-08-20 07:17:43 +00004638 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004639 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004640 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004641 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004642 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004643
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004644 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004645 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004646}
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregorebe10102009-08-20 07:17:43 +00004648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004649StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004650TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004651 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004652 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004653 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004654 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004655
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004656 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004657 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004658 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004659 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004660
Douglas Gregorebe10102009-08-20 07:17:43 +00004661 if (!getDerived().AlwaysRebuild() &&
4662 Cond.get() == S->getCond() &&
4663 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004664 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004665
John McCallb268a282010-08-23 23:25:46 +00004666 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4667 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004668 S->getRParenLoc());
4669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregorebe10102009-08-20 07:17:43 +00004671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004672StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004673TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004674 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004675 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004676 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004677 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregorebe10102009-08-20 07:17:43 +00004679 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004680 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004681 VarDecl *ConditionVar = 0;
4682 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004683 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004684 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004685 getDerived().TransformDefinition(
4686 S->getConditionVariable()->getLocation(),
4687 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004688 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004689 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004690 } else {
4691 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004692
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004693 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004694 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004695
4696 if (S->getCond()) {
4697 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004698 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4699 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004700 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004701 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004702
John McCallb268a282010-08-23 23:25:46 +00004703 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004704 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004705 }
Mike Stump11289f42009-09-09 15:08:12 +00004706
John McCallb268a282010-08-23 23:25:46 +00004707 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4708 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004709 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004710
Douglas Gregorebe10102009-08-20 07:17:43 +00004711 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004712 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004713 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004714 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004715
John McCallb268a282010-08-23 23:25:46 +00004716 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4717 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004718 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004719
Douglas Gregorebe10102009-08-20 07:17:43 +00004720 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004721 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004722 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004723 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregorebe10102009-08-20 07:17:43 +00004725 if (!getDerived().AlwaysRebuild() &&
4726 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004727 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004728 Inc.get() == S->getInc() &&
4729 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004730 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregorebe10102009-08-20 07:17:43 +00004732 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004733 Init.get(), FullCond, ConditionVar,
4734 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004735}
4736
4737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004738StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004739TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004740 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004741 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004742 S->getLabel());
4743}
4744
4745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004746StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004747TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004748 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004749 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004750 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregorebe10102009-08-20 07:17:43 +00004752 if (!getDerived().AlwaysRebuild() &&
4753 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004754 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004755
4756 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004757 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004758}
4759
4760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004761StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004762TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004763 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004764}
Mike Stump11289f42009-09-09 15:08:12 +00004765
Douglas Gregorebe10102009-08-20 07:17:43 +00004766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004767StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004768TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004769 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004770}
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregorebe10102009-08-20 07:17:43 +00004772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004773StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004774TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004775 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004777 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004778
Mike Stump11289f42009-09-09 15:08:12 +00004779 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004780 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004781 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004782}
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregorebe10102009-08-20 07:17:43 +00004784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004785StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004786TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004787 bool DeclChanged = false;
4788 llvm::SmallVector<Decl *, 4> Decls;
4789 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4790 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004791 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4792 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004793 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004794 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregorebe10102009-08-20 07:17:43 +00004796 if (Transformed != *D)
4797 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregorebe10102009-08-20 07:17:43 +00004799 Decls.push_back(Transformed);
4800 }
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregorebe10102009-08-20 07:17:43 +00004802 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004803 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004804
4805 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004806 S->getStartLoc(), S->getEndLoc());
4807}
Mike Stump11289f42009-09-09 15:08:12 +00004808
Douglas Gregorebe10102009-08-20 07:17:43 +00004809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004810StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004811TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004812 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004813 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004814}
4815
4816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004817StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004818TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004819
John McCall37ad5512010-08-23 06:44:23 +00004820 ASTOwningVector<Expr*> Constraints(getSema());
4821 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004822 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004823
John McCalldadc5752010-08-24 06:29:42 +00004824 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004825 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004826
4827 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004828
Anders Carlssonaaeef072010-01-24 05:50:09 +00004829 // Go through the outputs.
4830 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004831 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004832
Anders Carlssonaaeef072010-01-24 05:50:09 +00004833 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004834 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004835
Anders Carlssonaaeef072010-01-24 05:50:09 +00004836 // Transform the output expr.
4837 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004838 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004839 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004840 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004841
Anders Carlssonaaeef072010-01-24 05:50:09 +00004842 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004843
John McCallb268a282010-08-23 23:25:46 +00004844 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004845 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004846
Anders Carlssonaaeef072010-01-24 05:50:09 +00004847 // Go through the inputs.
4848 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004849 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004850
Anders Carlssonaaeef072010-01-24 05:50:09 +00004851 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004852 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004853
Anders Carlssonaaeef072010-01-24 05:50:09 +00004854 // Transform the input expr.
4855 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004856 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004857 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004859
Anders Carlssonaaeef072010-01-24 05:50:09 +00004860 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004861
John McCallb268a282010-08-23 23:25:46 +00004862 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004863 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004864
Anders Carlssonaaeef072010-01-24 05:50:09 +00004865 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004866 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004867
4868 // Go through the clobbers.
4869 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004870 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004871
4872 // No need to transform the asm string literal.
4873 AsmString = SemaRef.Owned(S->getAsmString());
4874
4875 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4876 S->isSimple(),
4877 S->isVolatile(),
4878 S->getNumOutputs(),
4879 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004880 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004881 move_arg(Constraints),
4882 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004883 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004884 move_arg(Clobbers),
4885 S->getRParenLoc(),
4886 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004887}
4888
4889
4890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004891StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004892TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004893 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004894 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004895 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004896 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004897
Douglas Gregor96c79492010-04-23 22:50:49 +00004898 // Transform the @catch statements (if present).
4899 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004900 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004901 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004902 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004903 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004904 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004905 if (Catch.get() != S->getCatchStmt(I))
4906 AnyCatchChanged = true;
4907 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004908 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004909
Douglas Gregor306de2f2010-04-22 23:59:56 +00004910 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004911 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004912 if (S->getFinallyStmt()) {
4913 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4914 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004915 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004916 }
4917
4918 // If nothing changed, just retain this statement.
4919 if (!getDerived().AlwaysRebuild() &&
4920 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004921 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004922 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004923 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004924
Douglas Gregor306de2f2010-04-22 23:59:56 +00004925 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004926 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4927 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004928}
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregorebe10102009-08-20 07:17:43 +00004930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004931StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004932TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004933 // Transform the @catch parameter, if there is one.
4934 VarDecl *Var = 0;
4935 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4936 TypeSourceInfo *TSInfo = 0;
4937 if (FromVar->getTypeSourceInfo()) {
4938 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4939 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004940 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004941 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004942
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004943 QualType T;
4944 if (TSInfo)
4945 T = TSInfo->getType();
4946 else {
4947 T = getDerived().TransformType(FromVar->getType());
4948 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004949 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004950 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004951
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004952 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4953 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004954 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004955 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004956
John McCalldadc5752010-08-24 06:29:42 +00004957 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004958 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004959 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004960
4961 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004962 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004963 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004964}
Mike Stump11289f42009-09-09 15:08:12 +00004965
Douglas Gregorebe10102009-08-20 07:17:43 +00004966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004967StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004968TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004969 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004970 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004971 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004972 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004973
Douglas Gregor306de2f2010-04-22 23:59:56 +00004974 // If nothing changed, just retain this statement.
4975 if (!getDerived().AlwaysRebuild() &&
4976 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004977 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004978
4979 // Build a new statement.
4980 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004981 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004982}
Mike Stump11289f42009-09-09 15:08:12 +00004983
Douglas Gregorebe10102009-08-20 07:17:43 +00004984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004985StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004986TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004987 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004988 if (S->getThrowExpr()) {
4989 Operand = getDerived().TransformExpr(S->getThrowExpr());
4990 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004991 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004992 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004993
Douglas Gregor2900c162010-04-22 21:44:01 +00004994 if (!getDerived().AlwaysRebuild() &&
4995 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004996 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004997
John McCallb268a282010-08-23 23:25:46 +00004998 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.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
Douglas Gregorebe10102009-08-20 07:17:43 +00005003TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005004 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005005 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005006 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005007 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005009
Douglas Gregor6148de72010-04-22 22:01:21 +00005010 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005011 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005012 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005014
Douglas Gregor6148de72010-04-22 22:01:21 +00005015 // If nothing change, just retain the current statement.
5016 if (!getDerived().AlwaysRebuild() &&
5017 Object.get() == S->getSynchExpr() &&
5018 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005019 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005020
5021 // Build a new statement.
5022 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005023 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005024}
5025
5026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005027StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005028TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005029 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005030 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005031 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005032 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005033 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005034
Douglas Gregorf68a5082010-04-22 23:10:45 +00005035 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005036 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005037 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005038 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005039
Douglas Gregorf68a5082010-04-22 23:10:45 +00005040 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005041 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005042 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005043 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005044
Douglas Gregorf68a5082010-04-22 23:10:45 +00005045 // If nothing changed, just retain this statement.
5046 if (!getDerived().AlwaysRebuild() &&
5047 Element.get() == S->getElement() &&
5048 Collection.get() == S->getCollection() &&
5049 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005050 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005051
Douglas Gregorf68a5082010-04-22 23:10:45 +00005052 // Build a new statement.
5053 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5054 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005055 Element.get(),
5056 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005057 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005058 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005059}
5060
5061
5062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005063StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005064TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5065 // Transform the exception declaration, if any.
5066 VarDecl *Var = 0;
5067 if (S->getExceptionDecl()) {
5068 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005069 TypeSourceInfo *T = getDerived().TransformType(
5070 ExceptionDecl->getTypeSourceInfo());
5071 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005072 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005074 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005075 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005076 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005077 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005078 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005079 }
Mike Stump11289f42009-09-09 15:08:12 +00005080
Douglas Gregorebe10102009-08-20 07:17:43 +00005081 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005082 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005083 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005084 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregorebe10102009-08-20 07:17:43 +00005086 if (!getDerived().AlwaysRebuild() &&
5087 !Var &&
5088 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005089 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005090
5091 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5092 Var,
John McCallb268a282010-08-23 23:25:46 +00005093 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregorebe10102009-08-20 07:17:43 +00005096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005097StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005098TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5099 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005100 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005101 = getDerived().TransformCompoundStmt(S->getTryBlock());
5102 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregorebe10102009-08-20 07:17:43 +00005105 // Transform the handlers.
5106 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005107 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005108 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005109 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005110 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5111 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005112 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregorebe10102009-08-20 07:17:43 +00005114 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5115 Handlers.push_back(Handler.takeAs<Stmt>());
5116 }
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregorebe10102009-08-20 07:17:43 +00005118 if (!getDerived().AlwaysRebuild() &&
5119 TryBlock.get() == S->getTryBlock() &&
5120 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005121 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005122
John McCallb268a282010-08-23 23:25:46 +00005123 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005124 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005125}
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregorebe10102009-08-20 07:17:43 +00005127//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005128// Expression transformation
5129//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005130template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005131ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005132TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005133 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005134}
Mike Stump11289f42009-09-09 15:08:12 +00005135
5136template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005137ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005138TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005139 NestedNameSpecifier *Qualifier = 0;
5140 if (E->getQualifier()) {
5141 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005142 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005143 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005144 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005145 }
John McCallce546572009-12-08 09:08:17 +00005146
5147 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005148 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5149 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005150 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005152
John McCall815039a2010-08-17 21:27:17 +00005153 DeclarationNameInfo NameInfo = E->getNameInfo();
5154 if (NameInfo.getName()) {
5155 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5156 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005157 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005158 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005159
5160 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005161 Qualifier == E->getQualifier() &&
5162 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005163 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005164 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005165
5166 // Mark it referenced in the new context regardless.
5167 // FIXME: this is a bit instantiation-specific.
5168 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5169
John McCallc3007a22010-10-26 07:05:15 +00005170 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005171 }
John McCallce546572009-12-08 09:08:17 +00005172
5173 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005174 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005175 TemplateArgs = &TransArgs;
5176 TransArgs.setLAngleLoc(E->getLAngleLoc());
5177 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005178 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5179 E->getNumTemplateArgs(),
5180 TransArgs))
5181 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005182 }
5183
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005184 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005185 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005186}
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregora16548e2009-08-11 05:31:07 +00005188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005191 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005192}
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregora16548e2009-08-11 05:31:07 +00005194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005195ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005196TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005197 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregora16548e2009-08-11 05:31:07 +00005200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005202TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005203 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
Mike Stump11289f42009-09-09 15:08:12 +00005205
Douglas Gregora16548e2009-08-11 05:31:07 +00005206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005208TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005209 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005210}
Mike Stump11289f42009-09-09 15:08:12 +00005211
Douglas Gregora16548e2009-08-11 05:31:07 +00005212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005214TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005215 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005216}
5217
5218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005220TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005221 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005222 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005223 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005224
Douglas Gregora16548e2009-08-11 05:31:07 +00005225 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005226 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005227
John McCallb268a282010-08-23 23:25:46 +00005228 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 E->getRParen());
5230}
5231
Mike Stump11289f42009-09-09 15:08:12 +00005232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005234TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005235 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005238
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005240 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5243 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005244 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005245}
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005248ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005249TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5250 // Transform the type.
5251 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5252 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005253 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005254
Douglas Gregor882211c2010-04-28 22:16:22 +00005255 // Transform all of the components into components similar to what the
5256 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005257 // FIXME: It would be slightly more efficient in the non-dependent case to
5258 // just map FieldDecls, rather than requiring the rebuilder to look for
5259 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005260 // template code that we don't care.
5261 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005262 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005263 typedef OffsetOfExpr::OffsetOfNode Node;
5264 llvm::SmallVector<Component, 4> Components;
5265 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5266 const Node &ON = E->getComponent(I);
5267 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005268 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005269 Comp.LocStart = ON.getRange().getBegin();
5270 Comp.LocEnd = ON.getRange().getEnd();
5271 switch (ON.getKind()) {
5272 case Node::Array: {
5273 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005274 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005275 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005276 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005277
Douglas Gregor882211c2010-04-28 22:16:22 +00005278 ExprChanged = ExprChanged || Index.get() != FromIndex;
5279 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005280 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005281 break;
5282 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005283
Douglas Gregor882211c2010-04-28 22:16:22 +00005284 case Node::Field:
5285 case Node::Identifier:
5286 Comp.isBrackets = false;
5287 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005288 if (!Comp.U.IdentInfo)
5289 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005290
Douglas Gregor882211c2010-04-28 22:16:22 +00005291 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005292
Douglas Gregord1702062010-04-29 00:18:15 +00005293 case Node::Base:
5294 // Will be recomputed during the rebuild.
5295 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005296 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005297
Douglas Gregor882211c2010-04-28 22:16:22 +00005298 Components.push_back(Comp);
5299 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005300
Douglas Gregor882211c2010-04-28 22:16:22 +00005301 // If nothing changed, retain the existing expression.
5302 if (!getDerived().AlwaysRebuild() &&
5303 Type == E->getTypeSourceInfo() &&
5304 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005305 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005306
Douglas Gregor882211c2010-04-28 22:16:22 +00005307 // Build a new offsetof expression.
5308 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5309 Components.data(), Components.size(),
5310 E->getRParenLoc());
5311}
5312
5313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005314ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005315TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5316 assert(getDerived().AlreadyTransformed(E->getType()) &&
5317 "opaque value expression requires transformation");
5318 return SemaRef.Owned(E);
5319}
5320
5321template<typename Derived>
5322ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005323TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005325 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005326
John McCallbcd03502009-12-07 02:54:59 +00005327 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005328 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005329 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005330
John McCall4c98fd82009-11-04 07:28:41 +00005331 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005333
John McCall4c98fd82009-11-04 07:28:41 +00005334 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005335 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005336 E->getSourceRange());
5337 }
Mike Stump11289f42009-09-09 15:08:12 +00005338
John McCalldadc5752010-08-24 06:29:42 +00005339 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005340 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 // C++0x [expr.sizeof]p1:
5342 // The operand is either an expression, which is an unevaluated operand
5343 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005344 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregora16548e2009-08-11 05:31:07 +00005346 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5347 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005349
Douglas Gregora16548e2009-08-11 05:31:07 +00005350 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005351 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005352 }
Mike Stump11289f42009-09-09 15:08:12 +00005353
John McCallb268a282010-08-23 23:25:46 +00005354 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 E->isSizeOf(),
5356 E->getSourceRange());
5357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregora16548e2009-08-11 05:31:07 +00005359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005361TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005362 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005363 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005365
John McCalldadc5752010-08-24 06:29:42 +00005366 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005369
5370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 if (!getDerived().AlwaysRebuild() &&
5372 LHS.get() == E->getLHS() &&
5373 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005374 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005375
John McCallb268a282010-08-23 23:25:46 +00005376 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005377 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005378 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005379 E->getRBracketLoc());
5380}
Mike Stump11289f42009-09-09 15:08:12 +00005381
5382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005384TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005386 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005388 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005389
5390 // Transform arguments.
5391 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005392 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005393 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5394 &ArgChanged))
5395 return ExprError();
5396
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 if (!getDerived().AlwaysRebuild() &&
5398 Callee.get() == E->getCallee() &&
5399 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005400 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregora16548e2009-08-11 05:31:07 +00005402 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005403 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005405 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005407 E->getRParenLoc());
5408}
Mike Stump11289f42009-09-09 15:08:12 +00005409
5410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005413 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005415 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005417 NestedNameSpecifier *Qualifier = 0;
5418 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005419 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005420 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005421 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005422 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005424 }
Mike Stump11289f42009-09-09 15:08:12 +00005425
Eli Friedman2cfcef62009-12-04 06:40:45 +00005426 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005427 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5428 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005429 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005431
John McCall16df1e52010-03-30 21:47:33 +00005432 NamedDecl *FoundDecl = E->getFoundDecl();
5433 if (FoundDecl == E->getMemberDecl()) {
5434 FoundDecl = Member;
5435 } else {
5436 FoundDecl = cast_or_null<NamedDecl>(
5437 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5438 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005439 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005440 }
5441
Douglas Gregora16548e2009-08-11 05:31:07 +00005442 if (!getDerived().AlwaysRebuild() &&
5443 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005444 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005445 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005446 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005447 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005448
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005449 // Mark it referenced in the new context regardless.
5450 // FIXME: this is a bit instantiation-specific.
5451 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005452 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005453 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005454
John McCall6b51f282009-11-23 01:53:49 +00005455 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005456 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005457 TransArgs.setLAngleLoc(E->getLAngleLoc());
5458 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005459 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5460 E->getNumTemplateArgs(),
5461 TransArgs))
5462 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005463 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464
Douglas Gregora16548e2009-08-11 05:31:07 +00005465 // FIXME: Bogus source location for the operator
5466 SourceLocation FakeOperatorLoc
5467 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5468
John McCall38836f02010-01-15 08:34:02 +00005469 // FIXME: to do this check properly, we will need to preserve the
5470 // first-qualifier-in-scope here, just in case we had a dependent
5471 // base (and therefore couldn't do the check) and a
5472 // nested-name-qualifier (and therefore could do the lookup).
5473 NamedDecl *FirstQualifierInScope = 0;
5474
John McCallb268a282010-08-23 23:25:46 +00005475 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005477 Qualifier,
5478 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005479 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005480 Member,
John McCall16df1e52010-03-30 21:47:33 +00005481 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005482 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005483 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005484 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005485}
Mike Stump11289f42009-09-09 15:08:12 +00005486
Douglas Gregora16548e2009-08-11 05:31:07 +00005487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005489TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005490 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005493
John McCalldadc5752010-08-24 06:29:42 +00005494 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005495 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregora16548e2009-08-11 05:31:07 +00005498 if (!getDerived().AlwaysRebuild() &&
5499 LHS.get() == E->getLHS() &&
5500 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005501 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005502
Douglas Gregora16548e2009-08-11 05:31:07 +00005503 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005504 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005505}
5506
Mike Stump11289f42009-09-09 15:08:12 +00005507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005508ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005509TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005510 CompoundAssignOperator *E) {
5511 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005512}
Mike Stump11289f42009-09-09 15:08:12 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005516TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005517 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005520
John McCalldadc5752010-08-24 06:29:42 +00005521 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005524
John McCalldadc5752010-08-24 06:29:42 +00005525 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005526 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005527 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005528
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 if (!getDerived().AlwaysRebuild() &&
5530 Cond.get() == E->getCond() &&
5531 LHS.get() == E->getLHS() &&
5532 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005533 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005534
John McCallb268a282010-08-23 23:25:46 +00005535 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005536 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005537 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005538 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005539 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005540}
Mike Stump11289f42009-09-09 15:08:12 +00005541
5542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005544TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005545 // Implicit casts are eliminated during transformation, since they
5546 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005547 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005548}
Mike Stump11289f42009-09-09 15:08:12 +00005549
Douglas Gregora16548e2009-08-11 05:31:07 +00005550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005551ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005552TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005553 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5554 if (!Type)
5555 return ExprError();
5556
John McCalldadc5752010-08-24 06:29:42 +00005557 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005558 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005559 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005560 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005563 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005565 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005566
John McCall97513962010-01-15 18:39:57 +00005567 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005568 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005570 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005571}
Mike Stump11289f42009-09-09 15:08:12 +00005572
Douglas Gregora16548e2009-08-11 05:31:07 +00005573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005575TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005576 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5577 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5578 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
John McCalldadc5752010-08-24 06:29:42 +00005581 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005583 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005586 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005588 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005589
John McCall5d7aa7f2010-01-19 22:33:45 +00005590 // Note: the expression type doesn't necessarily match the
5591 // type-as-written, but that's okay, because it should always be
5592 // derivable from the initializer.
5593
John McCalle15bbff2010-01-18 19:35:47 +00005594 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005596 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005597}
Mike Stump11289f42009-09-09 15:08:12 +00005598
Douglas Gregora16548e2009-08-11 05:31:07 +00005599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005600ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005601TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005602 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 if (!getDerived().AlwaysRebuild() &&
5607 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005608 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005609
Douglas Gregora16548e2009-08-11 05:31:07 +00005610 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005611 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005613 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005614 E->getAccessorLoc(),
5615 E->getAccessor());
5616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregora16548e2009-08-11 05:31:07 +00005618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005621 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005622
John McCall37ad5512010-08-23 06:44:23 +00005623 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005624 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5625 Inits, &InitChanged))
5626 return ExprError();
5627
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005629 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005630
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005632 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005633}
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>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005639
Douglas Gregorebe10102009-08-20 07:17:43 +00005640 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005641 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005644
Douglas Gregorebe10102009-08-20 07:17:43 +00005645 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005646 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 bool ExprChanged = false;
5648 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5649 DEnd = E->designators_end();
5650 D != DEnd; ++D) {
5651 if (D->isFieldDesignator()) {
5652 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5653 D->getDotLoc(),
5654 D->getFieldLoc()));
5655 continue;
5656 }
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregora16548e2009-08-11 05:31:07 +00005658 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005659 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005662
5663 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005665
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5667 ArrayExprs.push_back(Index.release());
5668 continue;
5669 }
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005672 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005673 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5674 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005675 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005676
John McCalldadc5752010-08-24 06:29:42 +00005677 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005680
5681 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 End.get(),
5683 D->getLBracketLoc(),
5684 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5687 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 ArrayExprs.push_back(Start.release());
5690 ArrayExprs.push_back(End.release());
5691 }
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregora16548e2009-08-11 05:31:07 +00005693 if (!getDerived().AlwaysRebuild() &&
5694 Init.get() == E->getInit() &&
5695 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005696 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005697
Douglas Gregora16548e2009-08-11 05:31:07 +00005698 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5699 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005700 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005701}
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregora16548e2009-08-11 05:31:07 +00005703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005704ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005705TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005706 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005707 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005708
Douglas Gregor3da3c062009-10-28 00:29:27 +00005709 // FIXME: Will we ever have proper type location here? Will we actually
5710 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 QualType T = getDerived().TransformType(E->getType());
5712 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregora16548e2009-08-11 05:31:07 +00005715 if (!getDerived().AlwaysRebuild() &&
5716 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005717 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 return getDerived().RebuildImplicitValueInitExpr(T);
5720}
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005723ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005724TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005725 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5726 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
John McCalldadc5752010-08-24 06:29:42 +00005729 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005734 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005736 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005737
John McCallb268a282010-08-23 23:25:46 +00005738 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005739 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005740}
5741
5742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005743ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005744TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005746 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005747 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5748 &ArgumentChanged))
5749 return ExprError();
5750
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5752 move_arg(Inits),
5753 E->getRParenLoc());
5754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregora16548e2009-08-11 05:31:07 +00005756/// \brief Transform an address-of-label expression.
5757///
5758/// By default, the transformation of an address-of-label expression always
5759/// rebuilds the expression, so that the label identifier can be resolved to
5760/// the corresponding label statement by semantic analysis.
5761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005762ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005763TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5765 E->getLabel());
5766}
Mike Stump11289f42009-09-09 15:08:12 +00005767
5768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005769ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005770TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005771 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5773 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 if (!getDerived().AlwaysRebuild() &&
5777 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005778 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005779
5780 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005781 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005782 E->getRParenLoc());
5783}
Mike Stump11289f42009-09-09 15:08:12 +00005784
Douglas Gregora16548e2009-08-11 05:31:07 +00005785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005787TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005788 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005790 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005791
John McCalldadc5752010-08-24 06:29:42 +00005792 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005795
John McCalldadc5752010-08-24 06:29:42 +00005796 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005799
Douglas Gregora16548e2009-08-11 05:31:07 +00005800 if (!getDerived().AlwaysRebuild() &&
5801 Cond.get() == E->getCond() &&
5802 LHS.get() == E->getLHS() &&
5803 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005804 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005807 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 E->getRParenLoc());
5809}
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregora16548e2009-08-11 05:31:07 +00005811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005813TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005814 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005815}
5816
5817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005818ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005819TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005820 switch (E->getOperator()) {
5821 case OO_New:
5822 case OO_Delete:
5823 case OO_Array_New:
5824 case OO_Array_Delete:
5825 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005826 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005827
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005828 case OO_Call: {
5829 // This is a call to an object's operator().
5830 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5831
5832 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005833 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005834 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005835 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005836
5837 // FIXME: Poor location information
5838 SourceLocation FakeLParenLoc
5839 = SemaRef.PP.getLocForEndOfToken(
5840 static_cast<Expr *>(Object.get())->getLocEnd());
5841
5842 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005843 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005844 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5845 Args))
5846 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005847
John McCallb268a282010-08-23 23:25:46 +00005848 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005849 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005850 E->getLocEnd());
5851 }
5852
5853#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5854 case OO_##Name:
5855#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5856#include "clang/Basic/OperatorKinds.def"
5857 case OO_Subscript:
5858 // Handled below.
5859 break;
5860
5861 case OO_Conditional:
5862 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005863 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005864
5865 case OO_None:
5866 case NUM_OVERLOADED_OPERATORS:
5867 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005869 }
5870
John McCalldadc5752010-08-24 06:29:42 +00005871 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005874
John McCalldadc5752010-08-24 06:29:42 +00005875 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005876 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005877 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005878
John McCalldadc5752010-08-24 06:29:42 +00005879 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005880 if (E->getNumArgs() == 2) {
5881 Second = getDerived().TransformExpr(E->getArg(1));
5882 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005883 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 }
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 if (!getDerived().AlwaysRebuild() &&
5887 Callee.get() == E->getCallee() &&
5888 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005889 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005890 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005891
Douglas Gregora16548e2009-08-11 05:31:07 +00005892 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5893 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005894 Callee.get(),
5895 First.get(),
5896 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005897}
Mike Stump11289f42009-09-09 15:08:12 +00005898
Douglas Gregora16548e2009-08-11 05:31:07 +00005899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005900ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005901TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5902 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005903}
Mike Stump11289f42009-09-09 15:08:12 +00005904
Douglas Gregora16548e2009-08-11 05:31:07 +00005905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005906ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005907TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005908 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5909 if (!Type)
5910 return ExprError();
5911
John McCalldadc5752010-08-24 06:29:42 +00005912 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005913 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005914 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005916
Douglas Gregora16548e2009-08-11 05:31:07 +00005917 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005918 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005919 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005920 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005923 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5925 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5926 SourceLocation FakeRParenLoc
5927 = SemaRef.PP.getLocForEndOfToken(
5928 E->getSubExpr()->getSourceRange().getEnd());
5929 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005930 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005931 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005932 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 FakeRAngleLoc,
5934 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005935 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 FakeRParenLoc);
5937}
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005940ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005941TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5942 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005943}
Mike Stump11289f42009-09-09 15:08:12 +00005944
5945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005947TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5948 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005949}
5950
Douglas Gregora16548e2009-08-11 05:31:07 +00005951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005952ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005953TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005954 CXXReinterpretCastExpr *E) {
5955 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregora16548e2009-08-11 05:31:07 +00005958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005960TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5961 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005962}
Mike Stump11289f42009-09-09 15:08:12 +00005963
Douglas Gregora16548e2009-08-11 05:31:07 +00005964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005965ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005966TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005967 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005968 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5969 if (!Type)
5970 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005971
John McCalldadc5752010-08-24 06:29:42 +00005972 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005973 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005974 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregora16548e2009-08-11 05:31:07 +00005977 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005978 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005979 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005980 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005981
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005982 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005983 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005984 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005985 E->getRParenLoc());
5986}
Mike Stump11289f42009-09-09 15:08:12 +00005987
Douglas Gregora16548e2009-08-11 05:31:07 +00005988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005989ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005990TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005992 TypeSourceInfo *TInfo
5993 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5994 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005998 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005999 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006000
Douglas Gregor9da64192010-04-26 22:37:10 +00006001 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6002 E->getLocStart(),
6003 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 E->getLocEnd());
6005 }
Mike Stump11289f42009-09-09 15:08:12 +00006006
Douglas Gregora16548e2009-08-11 05:31:07 +00006007 // We don't know whether the expression is potentially evaluated until
6008 // after we perform semantic analysis, so the expression is potentially
6009 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006010 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006011 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006012
John McCalldadc5752010-08-24 06:29:42 +00006013 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 if (!getDerived().AlwaysRebuild() &&
6018 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006019 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006020
Douglas Gregor9da64192010-04-26 22:37:10 +00006021 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6022 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006023 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 E->getLocEnd());
6025}
6026
6027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006028ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006029TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6030 if (E->isTypeOperand()) {
6031 TypeSourceInfo *TInfo
6032 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6033 if (!TInfo)
6034 return ExprError();
6035
6036 if (!getDerived().AlwaysRebuild() &&
6037 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006038 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006039
6040 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6041 E->getLocStart(),
6042 TInfo,
6043 E->getLocEnd());
6044 }
6045
6046 // We don't know whether the expression is potentially evaluated until
6047 // after we perform semantic analysis, so the expression is potentially
6048 // potentially evaluated.
6049 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6050
6051 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6052 if (SubExpr.isInvalid())
6053 return ExprError();
6054
6055 if (!getDerived().AlwaysRebuild() &&
6056 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006057 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006058
6059 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6060 E->getLocStart(),
6061 SubExpr.get(),
6062 E->getLocEnd());
6063}
6064
6065template<typename Derived>
6066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006068 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006069}
Mike Stump11289f42009-09-09 15:08:12 +00006070
Douglas Gregora16548e2009-08-11 05:31:07 +00006071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006072ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006073TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006074 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006075 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006076}
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregora16548e2009-08-11 05:31:07 +00006078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006081 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6082 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6083 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006085 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006086 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006087
Douglas Gregorb15af892010-01-07 23:12:05 +00006088 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregora16548e2009-08-11 05:31:07 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006093TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006094 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006095 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006097
Douglas Gregora16548e2009-08-11 05:31:07 +00006098 if (!getDerived().AlwaysRebuild() &&
6099 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006101
John McCallb268a282010-08-23 23:25:46 +00006102 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006103}
Mike Stump11289f42009-09-09 15:08:12 +00006104
Douglas Gregora16548e2009-08-11 05:31:07 +00006105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006107TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006108 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006109 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6110 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006111 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006112 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006113
Chandler Carruth794da4c2010-02-08 06:42:49 +00006114 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006115 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006116 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregor033f6752009-12-23 23:03:06 +00006118 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006119}
Mike Stump11289f42009-09-09 15:08:12 +00006120
Douglas Gregora16548e2009-08-11 05:31:07 +00006121template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006122ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006123TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6124 CXXScalarValueInitExpr *E) {
6125 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6126 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006127 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006128
Douglas Gregora16548e2009-08-11 05:31:07 +00006129 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006130 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006131 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregor2b88c112010-09-08 00:15:04 +00006133 return getDerived().RebuildCXXScalarValueInitExpr(T,
6134 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006135 E->getRParenLoc());
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
John McCall47f29ea2009-12-08 09:21:05 +00006140TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006141 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006142 TypeSourceInfo *AllocTypeInfo
6143 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6144 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006146
Douglas Gregora16548e2009-08-11 05:31:07 +00006147 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006148 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006149 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006150 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregora16548e2009-08-11 05:31:07 +00006152 // Transform the placement arguments (if any).
6153 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006154 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006155 if (getDerived().TransformExprs(E->getPlacementArgs(),
6156 E->getNumPlacementArgs(), true,
6157 PlacementArgs, &ArgumentChanged))
6158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006159
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006161 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006162 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6163 ConstructorArgs, &ArgumentChanged))
6164 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregord2d9da02010-02-26 00:38:10 +00006166 // Transform constructor, new operator, and delete operator.
6167 CXXConstructorDecl *Constructor = 0;
6168 if (E->getConstructor()) {
6169 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006170 getDerived().TransformDecl(E->getLocStart(),
6171 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006172 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006173 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006174 }
6175
6176 FunctionDecl *OperatorNew = 0;
6177 if (E->getOperatorNew()) {
6178 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006179 getDerived().TransformDecl(E->getLocStart(),
6180 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006181 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006182 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006183 }
6184
6185 FunctionDecl *OperatorDelete = 0;
6186 if (E->getOperatorDelete()) {
6187 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006188 getDerived().TransformDecl(E->getLocStart(),
6189 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006190 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006192 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006193
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006195 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006197 Constructor == E->getConstructor() &&
6198 OperatorNew == E->getOperatorNew() &&
6199 OperatorDelete == E->getOperatorDelete() &&
6200 !ArgumentChanged) {
6201 // Mark any declarations we need as referenced.
6202 // FIXME: instantiation-specific.
6203 if (Constructor)
6204 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6205 if (OperatorNew)
6206 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6207 if (OperatorDelete)
6208 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006209 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006210 }
Mike Stump11289f42009-09-09 15:08:12 +00006211
Douglas Gregor0744ef62010-09-07 21:49:58 +00006212 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006213 if (!ArraySize.get()) {
6214 // If no array size was specified, but the new expression was
6215 // instantiated with an array type (e.g., "new T" where T is
6216 // instantiated with "int[4]"), extract the outer bound from the
6217 // array type as our array size. We do this with constant and
6218 // dependently-sized array types.
6219 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6220 if (!ArrayT) {
6221 // Do nothing
6222 } else if (const ConstantArrayType *ConsArrayT
6223 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006224 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006225 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6226 ConsArrayT->getSize(),
6227 SemaRef.Context.getSizeType(),
6228 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006229 AllocType = ConsArrayT->getElementType();
6230 } else if (const DependentSizedArrayType *DepArrayT
6231 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6232 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006233 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006234 AllocType = DepArrayT->getElementType();
6235 }
6236 }
6237 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006238
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6240 E->isGlobalNew(),
6241 /*FIXME:*/E->getLocStart(),
6242 move_arg(PlacementArgs),
6243 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006244 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006245 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006246 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006247 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006248 /*FIXME:*/E->getLocStart(),
6249 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006250 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006251}
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006255TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006256 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregord2d9da02010-02-26 00:38:10 +00006260 // Transform the delete operator, if known.
6261 FunctionDecl *OperatorDelete = 0;
6262 if (E->getOperatorDelete()) {
6263 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006264 getDerived().TransformDecl(E->getLocStart(),
6265 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006266 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006267 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006268 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006269
Douglas Gregora16548e2009-08-11 05:31:07 +00006270 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006271 Operand.get() == E->getArgument() &&
6272 OperatorDelete == E->getOperatorDelete()) {
6273 // Mark any declarations we need as referenced.
6274 // FIXME: instantiation-specific.
6275 if (OperatorDelete)
6276 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006277
6278 if (!E->getArgument()->isTypeDependent()) {
6279 QualType Destroyed = SemaRef.Context.getBaseElementType(
6280 E->getDestroyedType());
6281 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6282 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6283 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6284 SemaRef.LookupDestructor(Record));
6285 }
6286 }
6287
John McCallc3007a22010-10-26 07:05:15 +00006288 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006289 }
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6292 E->isGlobalDelete(),
6293 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006294 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006295}
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregora16548e2009-08-11 05:31:07 +00006297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006298ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006299TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006300 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006301 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006302 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006304
John McCallba7bf592010-08-24 05:47:05 +00006305 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006306 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006307 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006308 E->getOperatorLoc(),
6309 E->isArrow()? tok::arrow : tok::period,
6310 ObjectTypePtr,
6311 MayBePseudoDestructor);
6312 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006313 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006314
John McCallba7bf592010-08-24 05:47:05 +00006315 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006316 NestedNameSpecifier *Qualifier = E->getQualifier();
6317 if (Qualifier) {
6318 Qualifier
6319 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6320 E->getQualifierRange(),
6321 ObjectType);
6322 if (!Qualifier)
6323 return ExprError();
6324 }
Mike Stump11289f42009-09-09 15:08:12 +00006325
Douglas Gregor678f90d2010-02-25 01:56:36 +00006326 PseudoDestructorTypeStorage Destroyed;
6327 if (E->getDestroyedTypeInfo()) {
6328 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006329 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6330 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006331 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006332 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006333 Destroyed = DestroyedTypeInfo;
6334 } else if (ObjectType->isDependentType()) {
6335 // We aren't likely to be able to resolve the identifier down to a type
6336 // now anyway, so just retain the identifier.
6337 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6338 E->getDestroyedTypeLoc());
6339 } else {
6340 // Look for a destructor known with the given name.
6341 CXXScopeSpec SS;
6342 if (Qualifier) {
6343 SS.setScopeRep(Qualifier);
6344 SS.setRange(E->getQualifierRange());
6345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006346
John McCallba7bf592010-08-24 05:47:05 +00006347 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006348 *E->getDestroyedTypeIdentifier(),
6349 E->getDestroyedTypeLoc(),
6350 /*Scope=*/0,
6351 SS, ObjectTypePtr,
6352 false);
6353 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006354 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006355
Douglas Gregor678f90d2010-02-25 01:56:36 +00006356 Destroyed
6357 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6358 E->getDestroyedTypeLoc());
6359 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006360
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006361 TypeSourceInfo *ScopeTypeInfo = 0;
6362 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006363 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006364 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006365 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006366 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006367
John McCallb268a282010-08-23 23:25:46 +00006368 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006369 E->getOperatorLoc(),
6370 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006371 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006372 E->getQualifierRange(),
6373 ScopeTypeInfo,
6374 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006375 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006376 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006377}
Mike Stump11289f42009-09-09 15:08:12 +00006378
Douglas Gregorad8a3362009-09-04 17:36:40 +00006379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006380ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006381TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006382 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006383 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6384
6385 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6386 Sema::LookupOrdinaryName);
6387
6388 // Transform all the decls.
6389 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6390 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006391 NamedDecl *InstD = static_cast<NamedDecl*>(
6392 getDerived().TransformDecl(Old->getNameLoc(),
6393 *I));
John McCall84d87672009-12-10 09:41:52 +00006394 if (!InstD) {
6395 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6396 // This can happen because of dependent hiding.
6397 if (isa<UsingShadowDecl>(*I))
6398 continue;
6399 else
John McCallfaf5fb42010-08-26 23:41:50 +00006400 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006401 }
John McCalle66edc12009-11-24 19:00:30 +00006402
6403 // Expand using declarations.
6404 if (isa<UsingDecl>(InstD)) {
6405 UsingDecl *UD = cast<UsingDecl>(InstD);
6406 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6407 E = UD->shadow_end(); I != E; ++I)
6408 R.addDecl(*I);
6409 continue;
6410 }
6411
6412 R.addDecl(InstD);
6413 }
6414
6415 // Resolve a kind, but don't do any further analysis. If it's
6416 // ambiguous, the callee needs to deal with it.
6417 R.resolveKind();
6418
6419 // Rebuild the nested-name qualifier, if present.
6420 CXXScopeSpec SS;
6421 NestedNameSpecifier *Qualifier = 0;
6422 if (Old->getQualifier()) {
6423 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006424 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006425 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006427
John McCalle66edc12009-11-24 19:00:30 +00006428 SS.setScopeRep(Qualifier);
6429 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006430 }
6431
Douglas Gregor9262f472010-04-27 18:19:34 +00006432 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006433 CXXRecordDecl *NamingClass
6434 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6435 Old->getNameLoc(),
6436 Old->getNamingClass()));
6437 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006438 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006439
Douglas Gregorda7be082010-04-27 16:10:10 +00006440 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006441 }
6442
6443 // If we have no template arguments, it's a normal declaration name.
6444 if (!Old->hasExplicitTemplateArgs())
6445 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6446
6447 // If we have template arguments, rebuild them, then rebuild the
6448 // templateid expression.
6449 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006450 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6451 Old->getNumTemplateArgs(),
6452 TransArgs))
6453 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006454
6455 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6456 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006457}
Mike Stump11289f42009-09-09 15:08:12 +00006458
Douglas Gregora16548e2009-08-11 05:31:07 +00006459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006460ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006461TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006462 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6463 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006465
Douglas Gregora16548e2009-08-11 05:31:07 +00006466 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006467 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006468 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006469
Mike Stump11289f42009-09-09 15:08:12 +00006470 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006471 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 T,
6473 E->getLocEnd());
6474}
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
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006478TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6479 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6480 if (!LhsT)
6481 return ExprError();
6482
6483 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6484 if (!RhsT)
6485 return ExprError();
6486
6487 if (!getDerived().AlwaysRebuild() &&
6488 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6489 return SemaRef.Owned(E);
6490
6491 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6492 E->getLocStart(),
6493 LhsT, RhsT,
6494 E->getLocEnd());
6495}
6496
6497template<typename Derived>
6498ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006499TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006500 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006501 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006502 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006503 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006506
John McCall31f82722010-11-12 08:19:04 +00006507 // TODO: If this is a conversion-function-id, verify that the
6508 // destination type name (if present) resolves the same way after
6509 // instantiation as it did in the local scope.
6510
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006511 DeclarationNameInfo NameInfo
6512 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6513 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006514 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006515
John McCalle66edc12009-11-24 19:00:30 +00006516 if (!E->hasExplicitTemplateArgs()) {
6517 if (!getDerived().AlwaysRebuild() &&
6518 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006519 // Note: it is sufficient to compare the Name component of NameInfo:
6520 // if name has not changed, DNLoc has not changed either.
6521 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006522 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006523
John McCalle66edc12009-11-24 19:00:30 +00006524 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6525 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006526 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006527 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006528 }
John McCall6b51f282009-11-23 01:53:49 +00006529
6530 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006531 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6532 E->getNumTemplateArgs(),
6533 TransArgs))
6534 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006535
John McCalle66edc12009-11-24 19:00:30 +00006536 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6537 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006538 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006539 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006540}
6541
6542template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006543ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006544TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006545 // CXXConstructExprs are always implicit, so when we have a
6546 // 1-argument construction we just transform that argument.
6547 if (E->getNumArgs() == 1 ||
6548 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6549 return getDerived().TransformExpr(E->getArg(0));
6550
Douglas Gregora16548e2009-08-11 05:31:07 +00006551 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6552
6553 QualType T = getDerived().TransformType(E->getType());
6554 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006555 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006556
6557 CXXConstructorDecl *Constructor
6558 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006559 getDerived().TransformDecl(E->getLocStart(),
6560 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006561 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregora16548e2009-08-11 05:31:07 +00006564 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006565 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006566 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6567 &ArgumentChanged))
6568 return ExprError();
6569
Douglas Gregora16548e2009-08-11 05:31:07 +00006570 if (!getDerived().AlwaysRebuild() &&
6571 T == E->getType() &&
6572 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006573 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006574 // Mark the constructor as referenced.
6575 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006576 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006577 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006578 }
Mike Stump11289f42009-09-09 15:08:12 +00006579
Douglas Gregordb121ba2009-12-14 16:27:04 +00006580 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6581 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006582 move_arg(Args),
6583 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006584 E->getConstructionKind(),
6585 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006586}
Mike Stump11289f42009-09-09 15:08:12 +00006587
Douglas Gregora16548e2009-08-11 05:31:07 +00006588/// \brief Transform a C++ temporary-binding expression.
6589///
Douglas Gregor363b1512009-12-24 18:51:59 +00006590/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6591/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006593ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006594TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006595 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006596}
Mike Stump11289f42009-09-09 15:08:12 +00006597
John McCall5d413782010-12-06 08:20:24 +00006598/// \brief Transform a C++ expression that contains cleanups that should
6599/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006600///
John McCall5d413782010-12-06 08:20:24 +00006601/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006602/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006604ExprResult
John McCall5d413782010-12-06 08:20:24 +00006605TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006606 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006607}
Mike Stump11289f42009-09-09 15:08:12 +00006608
Douglas Gregora16548e2009-08-11 05:31:07 +00006609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006610ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006611TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006612 CXXTemporaryObjectExpr *E) {
6613 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6614 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006616
Douglas Gregora16548e2009-08-11 05:31:07 +00006617 CXXConstructorDecl *Constructor
6618 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006619 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006620 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006621 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006623
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006625 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006627 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6628 &ArgumentChanged))
6629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregora16548e2009-08-11 05:31:07 +00006631 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006632 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006633 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006634 !ArgumentChanged) {
6635 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006636 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006637 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006638 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006639
6640 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6641 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006642 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 E->getLocEnd());
6644}
Mike Stump11289f42009-09-09 15:08:12 +00006645
Douglas Gregora16548e2009-08-11 05:31:07 +00006646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006647ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006648TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006649 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006650 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6651 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006653
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006655 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006656 Args.reserve(E->arg_size());
6657 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6658 &ArgumentChanged))
6659 return ExprError();
6660
Douglas Gregora16548e2009-08-11 05:31:07 +00006661 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006662 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006664 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006665
Douglas Gregora16548e2009-08-11 05:31:07 +00006666 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006667 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006668 E->getLParenLoc(),
6669 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006670 E->getRParenLoc());
6671}
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregora16548e2009-08-11 05:31:07 +00006673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006674ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006675TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006676 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006678 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006679 Expr *OldBase;
6680 QualType BaseType;
6681 QualType ObjectType;
6682 if (!E->isImplicitAccess()) {
6683 OldBase = E->getBase();
6684 Base = getDerived().TransformExpr(OldBase);
6685 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006687
John McCall2d74de92009-12-01 22:10:20 +00006688 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006689 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006690 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006691 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006692 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006693 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006694 ObjectTy,
6695 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006696 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006698
John McCallba7bf592010-08-24 05:47:05 +00006699 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006700 BaseType = ((Expr*) Base.get())->getType();
6701 } else {
6702 OldBase = 0;
6703 BaseType = getDerived().TransformType(E->getBaseType());
6704 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6705 }
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006707 // Transform the first part of the nested-name-specifier that qualifies
6708 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006709 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006710 = getDerived().TransformFirstQualifierInScope(
6711 E->getFirstQualifierFoundInScope(),
6712 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006713
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006714 NestedNameSpecifier *Qualifier = 0;
6715 if (E->getQualifier()) {
6716 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6717 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006718 ObjectType,
6719 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006720 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006721 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006722 }
Mike Stump11289f42009-09-09 15:08:12 +00006723
John McCall31f82722010-11-12 08:19:04 +00006724 // TODO: If this is a conversion-function-id, verify that the
6725 // destination type name (if present) resolves the same way after
6726 // instantiation as it did in the local scope.
6727
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006728 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006729 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006730 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006732
John McCall2d74de92009-12-01 22:10:20 +00006733 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006734 // This is a reference to a member without an explicitly-specified
6735 // template argument list. Optimize for this common case.
6736 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006737 Base.get() == OldBase &&
6738 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006739 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006740 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006741 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006742 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006743
John McCallb268a282010-08-23 23:25:46 +00006744 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006745 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006746 E->isArrow(),
6747 E->getOperatorLoc(),
6748 Qualifier,
6749 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006750 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006751 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006752 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006753 }
6754
John McCall6b51f282009-11-23 01:53:49 +00006755 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006756 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6757 E->getNumTemplateArgs(),
6758 TransArgs))
6759 return ExprError();
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 Gregora16548e2009-08-11 05:31:07 +00006763 E->isArrow(),
6764 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006765 Qualifier,
6766 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006767 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006768 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006769 &TransArgs);
6770}
6771
6772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006774TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006775 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006776 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006777 QualType BaseType;
6778 if (!Old->isImplicitAccess()) {
6779 Base = getDerived().TransformExpr(Old->getBase());
6780 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006781 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006782 BaseType = ((Expr*) Base.get())->getType();
6783 } else {
6784 BaseType = getDerived().TransformType(Old->getBaseType());
6785 }
John McCall10eae182009-11-30 22:42:35 +00006786
6787 NestedNameSpecifier *Qualifier = 0;
6788 if (Old->getQualifier()) {
6789 Qualifier
6790 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006791 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006792 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006793 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006794 }
6795
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006796 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006797 Sema::LookupOrdinaryName);
6798
6799 // Transform all the decls.
6800 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6801 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006802 NamedDecl *InstD = static_cast<NamedDecl*>(
6803 getDerived().TransformDecl(Old->getMemberLoc(),
6804 *I));
John McCall84d87672009-12-10 09:41:52 +00006805 if (!InstD) {
6806 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6807 // This can happen because of dependent hiding.
6808 if (isa<UsingShadowDecl>(*I))
6809 continue;
6810 else
John McCallfaf5fb42010-08-26 23:41:50 +00006811 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006812 }
John McCall10eae182009-11-30 22:42:35 +00006813
6814 // Expand using declarations.
6815 if (isa<UsingDecl>(InstD)) {
6816 UsingDecl *UD = cast<UsingDecl>(InstD);
6817 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6818 E = UD->shadow_end(); I != E; ++I)
6819 R.addDecl(*I);
6820 continue;
6821 }
6822
6823 R.addDecl(InstD);
6824 }
6825
6826 R.resolveKind();
6827
Douglas Gregor9262f472010-04-27 18:19:34 +00006828 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006829 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006830 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006831 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006832 Old->getMemberLoc(),
6833 Old->getNamingClass()));
6834 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006835 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006836
Douglas Gregorda7be082010-04-27 16:10:10 +00006837 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006838 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006839
John McCall10eae182009-11-30 22:42:35 +00006840 TemplateArgumentListInfo TransArgs;
6841 if (Old->hasExplicitTemplateArgs()) {
6842 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6843 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006844 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6845 Old->getNumTemplateArgs(),
6846 TransArgs))
6847 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006848 }
John McCall38836f02010-01-15 08:34:02 +00006849
6850 // FIXME: to do this check properly, we will need to preserve the
6851 // first-qualifier-in-scope here, just in case we had a dependent
6852 // base (and therefore couldn't do the check) and a
6853 // nested-name-qualifier (and therefore could do the lookup).
6854 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006855
John McCallb268a282010-08-23 23:25:46 +00006856 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006857 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006858 Old->getOperatorLoc(),
6859 Old->isArrow(),
6860 Qualifier,
6861 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006862 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006863 R,
6864 (Old->hasExplicitTemplateArgs()
6865 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006866}
6867
6868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006869ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006870TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6871 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6872 if (SubExpr.isInvalid())
6873 return ExprError();
6874
6875 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006876 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006877
6878 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6879}
6880
6881template<typename Derived>
6882ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006883TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006884 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6885 if (Pattern.isInvalid())
6886 return ExprError();
6887
6888 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6889 return SemaRef.Owned(E);
6890
Douglas Gregorb8840002011-01-14 21:20:45 +00006891 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6892 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006893}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006894
6895template<typename Derived>
6896ExprResult
6897TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6898 // If E is not value-dependent, then nothing will change when we transform it.
6899 // Note: This is an instantiation-centric view.
6900 if (!E->isValueDependent())
6901 return SemaRef.Owned(E);
6902
6903 // Note: None of the implementations of TryExpandParameterPacks can ever
6904 // produce a diagnostic when given only a single unexpanded parameter pack,
6905 // so
6906 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6907 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006908 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006909 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006910 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6911 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006912 ShouldExpand, RetainExpansion,
6913 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006914 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006915
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006916 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006917 return SemaRef.Owned(E);
6918
6919 // We now know the length of the parameter pack, so build a new expression
6920 // that stores that length.
6921 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6922 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006923 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006924}
6925
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006926template<typename Derived>
6927ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00006928TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6929 SubstNonTypeTemplateParmPackExpr *E) {
6930 // Default behavior is to do nothing with this transformation.
6931 return SemaRef.Owned(E);
6932}
6933
6934template<typename Derived>
6935ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006936TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006937 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006938}
6939
Mike Stump11289f42009-09-09 15:08:12 +00006940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006942TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006943 TypeSourceInfo *EncodedTypeInfo
6944 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6945 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006947
Douglas Gregora16548e2009-08-11 05:31:07 +00006948 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006949 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006950 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006951
6952 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006953 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006954 E->getRParenLoc());
6955}
Mike Stump11289f42009-09-09 15:08:12 +00006956
Douglas Gregora16548e2009-08-11 05:31:07 +00006957template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006959TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006960 // Transform arguments.
6961 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006962 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006963 Args.reserve(E->getNumArgs());
6964 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6965 &ArgChanged))
6966 return ExprError();
6967
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006968 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6969 // Class message: transform the receiver type.
6970 TypeSourceInfo *ReceiverTypeInfo
6971 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6972 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006973 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006974
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006975 // If nothing changed, just retain the existing message send.
6976 if (!getDerived().AlwaysRebuild() &&
6977 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006978 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006979
6980 // Build a new class message send.
6981 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6982 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006983 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006984 E->getMethodDecl(),
6985 E->getLeftLoc(),
6986 move_arg(Args),
6987 E->getRightLoc());
6988 }
6989
6990 // Instance message: transform the receiver
6991 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6992 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006993 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006994 = getDerived().TransformExpr(E->getInstanceReceiver());
6995 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006996 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006997
6998 // If nothing changed, just retain the existing message send.
6999 if (!getDerived().AlwaysRebuild() &&
7000 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007001 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007002
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007003 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007004 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007005 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007006 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007007 E->getMethodDecl(),
7008 E->getLeftLoc(),
7009 move_arg(Args),
7010 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007011}
7012
Mike Stump11289f42009-09-09 15:08:12 +00007013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007014ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007015TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007016 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007017}
7018
Mike Stump11289f42009-09-09 15:08:12 +00007019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007021TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007022 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007023}
7024
Mike Stump11289f42009-09-09 15:08:12 +00007025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007026ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007027TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007028 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007029 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007030 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007031 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007032
7033 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007034
Douglas Gregord51d90d2010-04-26 20:11:03 +00007035 // If nothing changed, just retain the existing expression.
7036 if (!getDerived().AlwaysRebuild() &&
7037 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007038 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007039
John McCallb268a282010-08-23 23:25:46 +00007040 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007041 E->getLocation(),
7042 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007043}
7044
Mike Stump11289f42009-09-09 15:08:12 +00007045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007046ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007047TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007048 // 'super' and types never change. Property never changes. Just
7049 // retain the existing expression.
7050 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007051 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007052
Douglas Gregor9faee212010-04-26 20:47:02 +00007053 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007054 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007055 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007057
Douglas Gregor9faee212010-04-26 20:47:02 +00007058 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007059
Douglas Gregor9faee212010-04-26 20:47:02 +00007060 // If nothing changed, just retain the existing expression.
7061 if (!getDerived().AlwaysRebuild() &&
7062 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007064
John McCallb7bd14f2010-12-02 01:19:52 +00007065 if (E->isExplicitProperty())
7066 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7067 E->getExplicitProperty(),
7068 E->getLocation());
7069
7070 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7071 E->getType(),
7072 E->getImplicitPropertyGetter(),
7073 E->getImplicitPropertySetter(),
7074 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007075}
7076
Mike Stump11289f42009-09-09 15:08:12 +00007077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007079TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007080 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007081 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007082 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007084
Douglas Gregord51d90d2010-04-26 20:11:03 +00007085 // If nothing changed, just retain the existing expression.
7086 if (!getDerived().AlwaysRebuild() &&
7087 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007088 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007089
John McCallb268a282010-08-23 23:25:46 +00007090 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007091 E->isArrow());
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>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007097 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007098 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007099 SubExprs.reserve(E->getNumSubExprs());
7100 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7101 SubExprs, &ArgumentChanged))
7102 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007103
Douglas Gregora16548e2009-08-11 05:31:07 +00007104 if (!getDerived().AlwaysRebuild() &&
7105 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007106 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007107
Douglas Gregora16548e2009-08-11 05:31:07 +00007108 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7109 move_arg(SubExprs),
7110 E->getRParenLoc());
7111}
7112
Mike Stump11289f42009-09-09 15:08:12 +00007113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007116 SourceLocation CaretLoc(E->getExprLoc());
7117
7118 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7119 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7120 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7121 llvm::SmallVector<ParmVarDecl*, 4> Params;
7122 llvm::SmallVector<QualType, 4> ParamTypes;
7123
7124 // Parameter substitution.
Douglas Gregor476e3022011-01-19 21:32:01 +00007125 BlockDecl *BD = E->getBlockDecl();
7126 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7127 BD->param_begin(),
7128 BD->param_size(), 0, ParamTypes,
7129 &Params))
7130 return true;
7131
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007132
7133 const FunctionType *BExprFunctionType = E->getFunctionType();
7134 QualType BExprResultType = BExprFunctionType->getResultType();
7135 if (!BExprResultType.isNull()) {
7136 if (!BExprResultType->isDependentType())
7137 CurBlock->ReturnType = BExprResultType;
7138 else if (BExprResultType != SemaRef.Context.DependentTy)
7139 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7140 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007141
7142 // If the return type has not been determined yet, leave it as a dependent
7143 // type; it'll get set when we process the body.
7144 if (CurBlock->ReturnType.isNull())
7145 CurBlock->ReturnType = getSema().Context.DependentTy;
7146
7147 // Don't allow returning a objc interface by value.
7148 if (CurBlock->ReturnType->isObjCObjectType()) {
7149 getSema().Diag(E->getLocStart(),
7150 diag::err_object_cannot_be_passed_returned_by_value)
7151 << 0 << CurBlock->ReturnType;
7152 return ExprError();
7153 }
John McCall3882ace2011-01-05 12:14:39 +00007154
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007155 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7156 CurBlock->ReturnType,
7157 ParamTypes.data(),
7158 ParamTypes.size(),
7159 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007160 0,
7161 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007162 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00007163
7164 // Set the parameters on the block decl.
7165 if (!Params.empty())
7166 CurBlock->TheDecl->setParams(Params.data(), Params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007167
7168 // If the return type wasn't explicitly set, it will have been marked as a
7169 // dependent type (DependentTy); clear out the return type setting so
7170 // we will deduce the return type when type-checking the block's body.
7171 if (CurBlock->ReturnType == getSema().Context.DependentTy)
7172 CurBlock->ReturnType = QualType();
7173
John McCall3882ace2011-01-05 12:14:39 +00007174 // Transform the body
7175 StmtResult Body = getDerived().TransformStmt(E->getBody());
7176 if (Body.isInvalid())
7177 return ExprError();
7178
John McCallb268a282010-08-23 23:25:46 +00007179 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007180}
7181
Mike Stump11289f42009-09-09 15:08:12 +00007182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007184TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007185 NestedNameSpecifier *Qualifier = 0;
7186
7187 ValueDecl *ND
7188 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7189 E->getDecl()));
7190 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007192
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007193 if (!getDerived().AlwaysRebuild() &&
7194 ND == E->getDecl()) {
7195 // Mark it referenced in the new context regardless.
7196 // FIXME: this is a bit instantiation-specific.
7197 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7198
John McCallc3007a22010-10-26 07:05:15 +00007199 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007200 }
7201
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007202 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007203 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007204 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007205}
Mike Stump11289f42009-09-09 15:08:12 +00007206
Douglas Gregora16548e2009-08-11 05:31:07 +00007207//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007208// Type reconstruction
7209//===----------------------------------------------------------------------===//
7210
Mike Stump11289f42009-09-09 15:08:12 +00007211template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007212QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7213 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007214 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007215 getDerived().getBaseEntity());
7216}
7217
Mike Stump11289f42009-09-09 15:08:12 +00007218template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007219QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7220 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007221 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007222 getDerived().getBaseEntity());
7223}
7224
Mike Stump11289f42009-09-09 15:08:12 +00007225template<typename Derived>
7226QualType
John McCall70dd5f62009-10-30 00:06:24 +00007227TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7228 bool WrittenAsLValue,
7229 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007230 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007231 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007232}
7233
7234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007235QualType
John McCall70dd5f62009-10-30 00:06:24 +00007236TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7237 QualType ClassType,
7238 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007239 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007240 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007241}
7242
7243template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007244QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007245TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7246 ArrayType::ArraySizeModifier SizeMod,
7247 const llvm::APInt *Size,
7248 Expr *SizeExpr,
7249 unsigned IndexTypeQuals,
7250 SourceRange BracketsRange) {
7251 if (SizeExpr || !Size)
7252 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7253 IndexTypeQuals, BracketsRange,
7254 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007255
7256 QualType Types[] = {
7257 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7258 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7259 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007260 };
7261 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7262 QualType SizeType;
7263 for (unsigned I = 0; I != NumTypes; ++I)
7264 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7265 SizeType = Types[I];
7266 break;
7267 }
Mike Stump11289f42009-09-09 15:08:12 +00007268
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007269 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7270 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007271 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007272 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007273 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007274}
Mike Stump11289f42009-09-09 15:08:12 +00007275
Douglas Gregord6ff3322009-08-04 16:50:30 +00007276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007277QualType
7278TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007279 ArrayType::ArraySizeModifier SizeMod,
7280 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007281 unsigned IndexTypeQuals,
7282 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007283 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007284 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007285}
7286
7287template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007288QualType
Mike Stump11289f42009-09-09 15:08:12 +00007289TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007290 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007291 unsigned IndexTypeQuals,
7292 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007293 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007294 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007295}
Mike Stump11289f42009-09-09 15:08:12 +00007296
Douglas Gregord6ff3322009-08-04 16:50:30 +00007297template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007298QualType
7299TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007300 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007301 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007302 unsigned IndexTypeQuals,
7303 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007304 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007305 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007306 IndexTypeQuals, BracketsRange);
7307}
7308
7309template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007310QualType
7311TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007312 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007313 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007314 unsigned IndexTypeQuals,
7315 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007316 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007317 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007318 IndexTypeQuals, BracketsRange);
7319}
7320
7321template<typename Derived>
7322QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007323 unsigned NumElements,
7324 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007325 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007326 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007327}
Mike Stump11289f42009-09-09 15:08:12 +00007328
Douglas Gregord6ff3322009-08-04 16:50:30 +00007329template<typename Derived>
7330QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7331 unsigned NumElements,
7332 SourceLocation AttributeLoc) {
7333 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7334 NumElements, true);
7335 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007336 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7337 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007338 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007339}
Mike Stump11289f42009-09-09 15:08:12 +00007340
Douglas Gregord6ff3322009-08-04 16:50:30 +00007341template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007342QualType
7343TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007344 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007345 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007346 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007347}
Mike Stump11289f42009-09-09 15:08:12 +00007348
Douglas Gregord6ff3322009-08-04 16:50:30 +00007349template<typename Derived>
7350QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007351 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007352 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007353 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007354 unsigned Quals,
7355 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007356 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007357 Quals,
7358 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007359 getDerived().getBaseEntity(),
7360 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007361}
Mike Stump11289f42009-09-09 15:08:12 +00007362
Douglas Gregord6ff3322009-08-04 16:50:30 +00007363template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007364QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7365 return SemaRef.Context.getFunctionNoProtoType(T);
7366}
7367
7368template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007369QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7370 assert(D && "no decl found");
7371 if (D->isInvalidDecl()) return QualType();
7372
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007373 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007374 TypeDecl *Ty;
7375 if (isa<UsingDecl>(D)) {
7376 UsingDecl *Using = cast<UsingDecl>(D);
7377 assert(Using->isTypeName() &&
7378 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7379
7380 // A valid resolved using typename decl points to exactly one type decl.
7381 assert(++Using->shadow_begin() == Using->shadow_end());
7382 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007383
John McCallb96ec562009-12-04 22:46:56 +00007384 } else {
7385 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7386 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7387 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7388 }
7389
7390 return SemaRef.Context.getTypeDeclType(Ty);
7391}
7392
7393template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007394QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7395 SourceLocation Loc) {
7396 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007397}
7398
7399template<typename Derived>
7400QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7401 return SemaRef.Context.getTypeOfType(Underlying);
7402}
7403
7404template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007405QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7406 SourceLocation Loc) {
7407 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007408}
7409
7410template<typename Derived>
7411QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007412 TemplateName Template,
7413 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007414 const TemplateArgumentListInfo &TemplateArgs) {
7415 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007416}
Mike Stump11289f42009-09-09 15:08:12 +00007417
Douglas Gregor1135c352009-08-06 05:28:30 +00007418template<typename Derived>
7419NestedNameSpecifier *
7420TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7421 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007422 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007423 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007424 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007425 CXXScopeSpec SS;
7426 // FIXME: The source location information is all wrong.
7427 SS.setRange(Range);
7428 SS.setScopeRep(Prefix);
7429 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007430 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007431 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007432 ObjectType,
7433 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007434 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007435}
7436
7437template<typename Derived>
7438NestedNameSpecifier *
7439TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7440 SourceRange Range,
7441 NamespaceDecl *NS) {
7442 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7443}
7444
7445template<typename Derived>
7446NestedNameSpecifier *
7447TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7448 SourceRange Range,
7449 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007450 QualType T) {
7451 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007452 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007453 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007454 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7455 T.getTypePtr());
7456 }
Mike Stump11289f42009-09-09 15:08:12 +00007457
Douglas Gregor1135c352009-08-06 05:28:30 +00007458 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7459 return 0;
7460}
Mike Stump11289f42009-09-09 15:08:12 +00007461
Douglas Gregor71dc5092009-08-06 06:41:21 +00007462template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007463TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007464TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7465 bool TemplateKW,
7466 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007467 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007468 Template);
7469}
7470
7471template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007472TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007473TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007474 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007475 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007476 QualType ObjectType,
7477 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007478 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007479 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007480 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007481 UnqualifiedId Name;
7482 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007483 Sema::TemplateTy Template;
7484 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7485 /*FIXME:*/getDerived().getBaseLocation(),
7486 SS,
7487 Name,
John McCallba7bf592010-08-24 05:47:05 +00007488 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007489 /*EnteringContext=*/false,
7490 Template);
John McCall31f82722010-11-12 08:19:04 +00007491 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007492}
Mike Stump11289f42009-09-09 15:08:12 +00007493
Douglas Gregora16548e2009-08-11 05:31:07 +00007494template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007495TemplateName
7496TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7497 OverloadedOperatorKind Operator,
7498 QualType ObjectType) {
7499 CXXScopeSpec SS;
7500 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7501 SS.setScopeRep(Qualifier);
7502 UnqualifiedId Name;
7503 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7504 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7505 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007506 Sema::TemplateTy Template;
7507 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007508 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007509 SS,
7510 Name,
John McCallba7bf592010-08-24 05:47:05 +00007511 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007512 /*EnteringContext=*/false,
7513 Template);
7514 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007515}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007516
Douglas Gregor71395fa2009-11-04 00:56:37 +00007517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007518ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007519TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7520 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007521 Expr *OrigCallee,
7522 Expr *First,
7523 Expr *Second) {
7524 Expr *Callee = OrigCallee->IgnoreParenCasts();
7525 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007526
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007528 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007529 if (!First->getType()->isOverloadableType() &&
7530 !Second->getType()->isOverloadableType())
7531 return getSema().CreateBuiltinArraySubscriptExpr(First,
7532 Callee->getLocStart(),
7533 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007534 } else if (Op == OO_Arrow) {
7535 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007536 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7537 } else if (Second == 0 || isPostIncDec) {
7538 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007539 // The argument is not of overloadable type, so try to create a
7540 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007541 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007542 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007543
John McCallb268a282010-08-23 23:25:46 +00007544 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007545 }
7546 } else {
John McCallb268a282010-08-23 23:25:46 +00007547 if (!First->getType()->isOverloadableType() &&
7548 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007549 // Neither of the arguments is an overloadable type, so try to
7550 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007551 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007552 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007553 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007554 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007555 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007556
Douglas Gregora16548e2009-08-11 05:31:07 +00007557 return move(Result);
7558 }
7559 }
Mike Stump11289f42009-09-09 15:08:12 +00007560
7561 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007562 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007563 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007564
John McCallb268a282010-08-23 23:25:46 +00007565 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007566 assert(ULE->requiresADL());
7567
7568 // FIXME: Do we have to check
7569 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007570 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007571 } else {
John McCallb268a282010-08-23 23:25:46 +00007572 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007573 }
Mike Stump11289f42009-09-09 15:08:12 +00007574
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007576 Expr *Args[2] = { First, Second };
7577 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007578
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 // Create the overloaded operator invocation for unary operators.
7580 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007581 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007582 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007583 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007584 }
Mike Stump11289f42009-09-09 15:08:12 +00007585
Sebastian Redladba46e2009-10-29 20:17:01 +00007586 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007587 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007588 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007589 First,
7590 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007591
Douglas Gregora16548e2009-08-11 05:31:07 +00007592 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007593 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007594 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007595 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7596 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007597 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007598
Mike Stump11289f42009-09-09 15:08:12 +00007599 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007600}
Mike Stump11289f42009-09-09 15:08:12 +00007601
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007603ExprResult
John McCallb268a282010-08-23 23:25:46 +00007604TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007605 SourceLocation OperatorLoc,
7606 bool isArrow,
7607 NestedNameSpecifier *Qualifier,
7608 SourceRange QualifierRange,
7609 TypeSourceInfo *ScopeType,
7610 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007611 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007612 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007613 CXXScopeSpec SS;
7614 if (Qualifier) {
7615 SS.setRange(QualifierRange);
7616 SS.setScopeRep(Qualifier);
7617 }
7618
John McCallb268a282010-08-23 23:25:46 +00007619 QualType BaseType = Base->getType();
7620 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007621 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007622 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007623 !BaseType->getAs<PointerType>()->getPointeeType()
7624 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007625 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007626 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007627 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007628 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007629 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007630 /*FIXME?*/true);
7631 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007632
Douglas Gregor678f90d2010-02-25 01:56:36 +00007633 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007634 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7635 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7636 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7637 NameInfo.setNamedTypeInfo(DestroyedType);
7638
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007639 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007640
John McCallb268a282010-08-23 23:25:46 +00007641 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007642 OperatorLoc, isArrow,
7643 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007644 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007645 /*TemplateArgs*/ 0);
7646}
7647
Douglas Gregord6ff3322009-08-04 16:50:30 +00007648} // end namespace clang
7649
7650#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H