blob: 04c45b8da71ce054f93efd5ec4c316ce9837ec88 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000037using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000038
Douglas Gregord6ff3322009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump11289f42009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump11289f42009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000092 /// \brief Private RAII object that helps us forget and then re-remember
93 /// the template argument corresponding to a partially-substituted parameter
94 /// pack.
95 class ForgetPartiallySubstitutedPackRAII {
96 Derived &Self;
97 TemplateArgument Old;
98
99 public:
100 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
101 Old = Self.ForgetPartiallySubstitutedPack();
102 }
103
104 ~ForgetPartiallySubstitutedPackRAII() {
105 Self.RememberPartiallySubstitutedPack(Old);
106 }
107 };
108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109protected:
110 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000111
Mike Stump11289f42009-09-09 15:08:12 +0000112public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000114 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000115
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Retrieves a reference to the derived class.
117 Derived &getDerived() { return static_cast<Derived&>(*this); }
118
119 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000120 const Derived &getDerived() const {
121 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 }
123
John McCalldadc5752010-08-24 06:29:42 +0000124 static inline ExprResult Owned(Expr *E) { return E; }
125 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000126
Douglas Gregord6ff3322009-08-04 16:50:30 +0000127 /// \brief Retrieves a reference to the semantic analysis object used for
128 /// this tree transform.
129 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000130
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 /// \brief Whether the transformation should always rebuild AST nodes, even
132 /// if none of the children have changed.
133 ///
134 /// Subclasses may override this function to specify when the transformation
135 /// should rebuild all AST nodes.
136 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000137
Douglas Gregord6ff3322009-08-04 16:50:30 +0000138 /// \brief Returns the location of the entity being transformed, if that
139 /// information was not available elsewhere in the AST.
140 ///
Mike Stump11289f42009-09-09 15:08:12 +0000141 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000142 /// provide an alternative implementation that provides better location
143 /// information.
144 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000145
Douglas Gregord6ff3322009-08-04 16:50:30 +0000146 /// \brief Returns the name of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
149 /// By default, returns an empty name. Subclasses can provide an alternative
150 /// implementation with a more precise name.
151 DeclarationName getBaseEntity() { return DeclarationName(); }
152
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 /// \brief Sets the "base" location and entity when that
154 /// information is known based on another transformation.
155 ///
156 /// By default, the source location and entity are ignored. Subclasses can
157 /// override this function to provide a customized implementation.
158 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregora16548e2009-08-11 05:31:07 +0000160 /// \brief RAII object that temporarily sets the base location and entity
161 /// used for reporting diagnostics in types.
162 class TemporaryBase {
163 TreeTransform &Self;
164 SourceLocation OldLocation;
165 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 public:
168 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000169 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 OldLocation = Self.getDerived().getBaseLocation();
171 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000172
173 if (Location.isValid())
174 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000175 }
Mike Stump11289f42009-09-09 15:08:12 +0000176
Douglas Gregora16548e2009-08-11 05:31:07 +0000177 ~TemporaryBase() {
178 Self.getDerived().setBase(OldLocation, OldEntity);
179 }
180 };
Mike Stump11289f42009-09-09 15:08:12 +0000181
182 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000183 /// transformed.
184 ///
185 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000186 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000187 /// not change. For example, template instantiation need not traverse
188 /// non-dependent types.
189 bool AlreadyTransformed(QualType T) {
190 return T.isNull();
191 }
192
Douglas Gregord196a582009-12-14 19:27:10 +0000193 /// \brief Determine whether the given call argument should be dropped, e.g.,
194 /// because it is a default argument.
195 ///
196 /// Subclasses can provide an alternative implementation of this routine to
197 /// determine which kinds of call arguments get dropped. By default,
198 /// CXXDefaultArgument nodes are dropped (prior to transformation).
199 bool DropCallArgument(Expr *E) {
200 return E->isDefaultArgument();
201 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000202
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000203 /// \brief Determine whether we should expand a pack expansion with the
204 /// given set of parameter packs into separate arguments by repeatedly
205 /// transforming the pattern.
206 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000207 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000208 /// Subclasses can override this routine to provide different behavior.
209 ///
210 /// \param EllipsisLoc The location of the ellipsis that identifies the
211 /// pack expansion.
212 ///
213 /// \param PatternRange The source range that covers the entire pattern of
214 /// the pack expansion.
215 ///
216 /// \param Unexpanded The set of unexpanded parameter packs within the
217 /// pattern.
218 ///
219 /// \param NumUnexpanded The number of unexpanded parameter packs in
220 /// \p Unexpanded.
221 ///
222 /// \param ShouldExpand Will be set to \c true if the transformer should
223 /// expand the corresponding pack expansions into separate arguments. When
224 /// set, \c NumExpansions must also be set.
225 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000226 /// \param RetainExpansion Whether the caller should add an unexpanded
227 /// pack expansion after all of the expanded arguments. This is used
228 /// when extending explicitly-specified template argument packs per
229 /// C++0x [temp.arg.explicit]p9.
230 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000232 /// the expanded form of the corresponding pack expansion. This is both an
233 /// input and an output parameter, which can be set by the caller if the
234 /// number of expansions is known a priori (e.g., due to a prior substitution)
235 /// and will be set by the callee when the number of expansions is known.
236 /// The callee must set this value when \c ShouldExpand is \c true; it may
237 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000238 ///
239 /// \returns true if an error occurred (e.g., because the parameter packs
240 /// are to be instantiated with arguments of different lengths), false
241 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
242 /// must be set.
243 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
244 SourceRange PatternRange,
245 const UnexpandedParameterPack *Unexpanded,
246 unsigned NumUnexpanded,
247 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000248 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000249 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000250 ShouldExpand = false;
251 return false;
252 }
253
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000254 /// \brief "Forget" about the partially-substituted pack template argument,
255 /// when performing an instantiation that must preserve the parameter pack
256 /// use.
257 ///
258 /// This routine is meant to be overridden by the template instantiator.
259 TemplateArgument ForgetPartiallySubstitutedPack() {
260 return TemplateArgument();
261 }
262
263 /// \brief "Remember" the partially-substituted pack template argument
264 /// after performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
269
Douglas Gregorf3010112011-01-07 16:43:16 +0000270 /// \brief Note to the derived class when a function parameter pack is
271 /// being expanded.
272 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
273
Douglas Gregord6ff3322009-08-04 16:50:30 +0000274 /// \brief Transforms the given type into another type.
275 ///
John McCall550e0c22009-10-21 00:40:46 +0000276 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000277 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000278 /// function. This is expensive, but we don't mind, because
279 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000280 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 ///
282 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000283 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000284
John McCall550e0c22009-10-21 00:40:46 +0000285 /// \brief Transforms the given type-with-location into a new
286 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 ///
John McCall550e0c22009-10-21 00:40:46 +0000288 /// By default, this routine transforms a type by delegating to the
289 /// appropriate TransformXXXType to build a new type. Subclasses
290 /// may override this function (to take over all type
291 /// transformations) or some set of the TransformXXXType functions
292 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000293 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000294
295 /// \brief Transform the given type-with-location into a new
296 /// type, collecting location information in the given builder
297 /// as necessary.
298 ///
John McCall31f82722010-11-12 08:19:04 +0000299 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000300
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000301 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000302 ///
Mike Stump11289f42009-09-09 15:08:12 +0000303 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000304 /// appropriate TransformXXXStmt function to transform a specific kind of
305 /// statement or the TransformExpr() function to transform an expression.
306 /// Subclasses may override this function to transform statements using some
307 /// other mechanism.
308 ///
309 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000310 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000311
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000312 /// \brief Transform the given expression.
313 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000314 /// By default, this routine transforms an expression by delegating to the
315 /// appropriate TransformXXXExpr function to build a new expression.
316 /// Subclasses may override this function to transform expressions using some
317 /// other mechanism.
318 ///
319 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000320 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000321
Douglas Gregora3efea12011-01-03 19:04:46 +0000322 /// \brief Transform the given list of expressions.
323 ///
324 /// This routine transforms a list of expressions by invoking
325 /// \c TransformExpr() for each subexpression. However, it also provides
326 /// support for variadic templates by expanding any pack expansions (if the
327 /// derived class permits such expansion) along the way. When pack expansions
328 /// are present, the number of outputs may not equal the number of inputs.
329 ///
330 /// \param Inputs The set of expressions to be transformed.
331 ///
332 /// \param NumInputs The number of expressions in \c Inputs.
333 ///
334 /// \param IsCall If \c true, then this transform is being performed on
335 /// function-call arguments, and any arguments that should be dropped, will
336 /// be.
337 ///
338 /// \param Outputs The transformed input expressions will be added to this
339 /// vector.
340 ///
341 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
342 /// due to transformation.
343 ///
344 /// \returns true if an error occurred, false otherwise.
345 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
346 llvm::SmallVectorImpl<Expr *> &Outputs,
347 bool *ArgChanged = 0);
348
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 /// \brief Transform the given declaration, which is referenced from a type
350 /// or expression.
351 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000352 /// By default, acts as the identity function on declarations. Subclasses
353 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000354 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000355
356 /// \brief Transform the definition of the given declaration.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000359 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000360 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
361 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000362 }
Mike Stump11289f42009-09-09 15:08:12 +0000363
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000364 /// \brief Transform the given declaration, which was the first part of a
365 /// nested-name-specifier in a member access expression.
366 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000367 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000368 /// identifier in a nested-name-specifier of a member access expression, e.g.,
369 /// the \c T in \c x->T::member
370 ///
371 /// By default, invokes TransformDecl() to transform the declaration.
372 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000373 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
374 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000375 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000376
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 /// \brief Transform the given nested-name-specifier.
378 ///
Mike Stump11289f42009-09-09 15:08:12 +0000379 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000380 /// nested-name-specifier. Subclasses may override this function to provide
381 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000383 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000384 QualType ObjectType = QualType(),
385 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000386
Douglas Gregorf816bd72009-09-03 22:13:48 +0000387 /// \brief Transform the given declaration name.
388 ///
389 /// By default, transforms the types of conversion function, constructor,
390 /// and destructor names and then (if needed) rebuilds the declaration name.
391 /// Identifiers and selectors are returned unmodified. Sublcasses may
392 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000393 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000394 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000397 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000398 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000399 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000400 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000401 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000402 QualType ObjectType = QualType(),
403 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000404
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// \brief Transform the given template argument.
406 ///
Mike Stump11289f42009-09-09 15:08:12 +0000407 /// By default, this operation transforms the type, expression, or
408 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000409 /// new template argument from the transformed result. Subclasses may
410 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000411 ///
412 /// Returns true if there was an error.
413 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
414 TemplateArgumentLoc &Output);
415
Douglas Gregor62e06f22010-12-20 17:31:10 +0000416 /// \brief Transform the given set of template arguments.
417 ///
418 /// By default, this operation transforms all of the template arguments
419 /// in the input set using \c TransformTemplateArgument(), and appends
420 /// the transformed arguments to the output list.
421 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000422 /// Note that this overload of \c TransformTemplateArguments() is merely
423 /// a convenience function. Subclasses that wish to override this behavior
424 /// should override the iterator-based member template version.
425 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000426 /// \param Inputs The set of template arguments to be transformed.
427 ///
428 /// \param NumInputs The number of template arguments in \p Inputs.
429 ///
430 /// \param Outputs The set of transformed template arguments output by this
431 /// routine.
432 ///
433 /// Returns true if an error occurred.
434 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
435 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000436 TemplateArgumentListInfo &Outputs) {
437 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
438 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000439
440 /// \brief Transform the given set of template arguments.
441 ///
442 /// By default, this operation transforms all of the template arguments
443 /// in the input set using \c TransformTemplateArgument(), and appends
444 /// the transformed arguments to the output list.
445 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000446 /// \param First An iterator to the first template argument.
447 ///
448 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000454 template<typename InputIterator>
455 bool TransformTemplateArguments(InputIterator First,
456 InputIterator Last,
457 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000458
John McCall0ad16662009-10-29 08:12:44 +0000459 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
460 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
461 TemplateArgumentLoc &ArgLoc);
462
John McCallbcd03502009-12-07 02:54:59 +0000463 /// \brief Fakes up a TypeSourceInfo for a type.
464 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
465 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000466 getDerived().getBaseLocation());
467 }
Mike Stump11289f42009-09-09 15:08:12 +0000468
John McCall550e0c22009-10-21 00:40:46 +0000469#define ABSTRACT_TYPELOC(CLASS, PARENT)
470#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000471 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000472#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000473
John McCall31f82722010-11-12 08:19:04 +0000474 QualType
475 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
476 TemplateSpecializationTypeLoc TL,
477 TemplateName Template);
478
479 QualType
480 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
481 DependentTemplateSpecializationTypeLoc TL,
482 NestedNameSpecifier *Prefix);
483
John McCall58f10c32010-03-11 09:03:00 +0000484 /// \brief Transforms the parameters of a function type into the
485 /// given vectors.
486 ///
487 /// The result vectors should be kept in sync; null entries in the
488 /// variables vector are acceptable.
489 ///
490 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000491 bool TransformFunctionTypeParams(SourceLocation Loc,
492 ParmVarDecl **Params, unsigned NumParams,
493 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000494 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000495 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000496
497 /// \brief Transforms a single function-type parameter. Return null
498 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000499 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
500 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000501
John McCall31f82722010-11-12 08:19:04 +0000502 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000503
John McCalldadc5752010-08-24 06:29:42 +0000504 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
505 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000506
Douglas Gregorebe10102009-08-20 07:17:43 +0000507#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000508 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000509#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000510 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000511#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000512#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000513
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 /// \brief Build a new pointer type given its pointee type.
515 ///
516 /// By default, performs semantic analysis when building the pointer type.
517 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000518 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000519
520 /// \brief Build a new block pointer type given its pointee type.
521 ///
Mike Stump11289f42009-09-09 15:08:12 +0000522 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000524 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525
John McCall70dd5f62009-10-30 00:06:24 +0000526 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000527 ///
John McCall70dd5f62009-10-30 00:06:24 +0000528 /// By default, performs semantic analysis when building the
529 /// reference type. Subclasses may override this routine to provide
530 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 ///
John McCall70dd5f62009-10-30 00:06:24 +0000532 /// \param LValue whether the type was written with an lvalue sigil
533 /// or an rvalue sigil.
534 QualType RebuildReferenceType(QualType ReferentType,
535 bool LValue,
536 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000537
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538 /// \brief Build a new member pointer type given the pointee type and the
539 /// class type it refers into.
540 ///
541 /// By default, performs semantic analysis when building the member pointer
542 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000543 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
544 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000545
Douglas Gregord6ff3322009-08-04 16:50:30 +0000546 /// \brief Build a new array type given the element type, size
547 /// modifier, size of the array (if known), size expression, and index type
548 /// qualifiers.
549 ///
550 /// By default, performs semantic analysis when building the array type.
551 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000552 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 QualType RebuildArrayType(QualType ElementType,
554 ArrayType::ArraySizeModifier SizeMod,
555 const llvm::APInt *Size,
556 Expr *SizeExpr,
557 unsigned IndexTypeQuals,
558 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000559
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// \brief Build a new constant array type given the element type, size
561 /// modifier, (known) size of the array, and index type qualifiers.
562 ///
563 /// By default, performs semantic analysis when building the array type.
564 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000565 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000566 ArrayType::ArraySizeModifier SizeMod,
567 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000568 unsigned IndexTypeQuals,
569 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new incomplete array type given the element type, size
572 /// modifier, and index type qualifiers.
573 ///
574 /// By default, performs semantic analysis when building the array type.
575 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000576 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000577 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000578 unsigned IndexTypeQuals,
579 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000580
Mike Stump11289f42009-09-09 15:08:12 +0000581 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 /// size modifier, size expression, and index type qualifiers.
583 ///
584 /// By default, performs semantic analysis when building the array type.
585 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000586 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000588 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000589 unsigned IndexTypeQuals,
590 SourceRange BracketsRange);
591
Mike Stump11289f42009-09-09 15:08:12 +0000592 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// size modifier, size expression, and index type qualifiers.
594 ///
595 /// By default, performs semantic analysis when building the array type.
596 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000597 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000598 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000599 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000600 unsigned IndexTypeQuals,
601 SourceRange BracketsRange);
602
603 /// \brief Build a new vector type given the element type and
604 /// number of elements.
605 ///
606 /// By default, performs semantic analysis when building the vector type.
607 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000608 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000609 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000610
Douglas Gregord6ff3322009-08-04 16:50:30 +0000611 /// \brief Build a new extended vector type given the element type and
612 /// number of elements.
613 ///
614 /// By default, performs semantic analysis when building the vector type.
615 /// Subclasses may override this routine to provide different behavior.
616 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
617 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000618
619 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 /// given the element type and number of elements.
621 ///
622 /// By default, performs semantic analysis when building the vector type.
623 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000624 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000625 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000627
Douglas Gregord6ff3322009-08-04 16:50:30 +0000628 /// \brief Build a new function type.
629 ///
630 /// By default, performs semantic analysis when building the function type.
631 /// Subclasses may override this routine to provide different behavior.
632 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000633 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000634 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000635 bool Variadic, unsigned Quals,
636 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000637
John McCall550e0c22009-10-21 00:40:46 +0000638 /// \brief Build a new unprototyped function type.
639 QualType RebuildFunctionNoProtoType(QualType ResultType);
640
John McCallb96ec562009-12-04 22:46:56 +0000641 /// \brief Rebuild an unresolved typename type, given the decl that
642 /// the UnresolvedUsingTypenameDecl was transformed to.
643 QualType RebuildUnresolvedUsingType(Decl *D);
644
Douglas Gregord6ff3322009-08-04 16:50:30 +0000645 /// \brief Build a new typedef type.
646 QualType RebuildTypedefType(TypedefDecl *Typedef) {
647 return SemaRef.Context.getTypeDeclType(Typedef);
648 }
649
650 /// \brief Build a new class/struct/union type.
651 QualType RebuildRecordType(RecordDecl *Record) {
652 return SemaRef.Context.getTypeDeclType(Record);
653 }
654
655 /// \brief Build a new Enum type.
656 QualType RebuildEnumType(EnumDecl *Enum) {
657 return SemaRef.Context.getTypeDeclType(Enum);
658 }
John McCallfcc33b02009-09-05 00:15:47 +0000659
Mike Stump11289f42009-09-09 15:08:12 +0000660 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 ///
662 /// By default, performs semantic analysis when building the typeof type.
663 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000664 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665
Mike Stump11289f42009-09-09 15:08:12 +0000666 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 ///
668 /// By default, builds a new TypeOfType with the given underlying type.
669 QualType RebuildTypeOfType(QualType Underlying);
670
Mike Stump11289f42009-09-09 15:08:12 +0000671 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672 ///
673 /// By default, performs semantic analysis when building the decltype type.
674 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000675 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000676
Douglas Gregord6ff3322009-08-04 16:50:30 +0000677 /// \brief Build a new template specialization type.
678 ///
679 /// By default, performs semantic analysis when building the template
680 /// specialization type. Subclasses may override this routine to provide
681 /// different behavior.
682 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000683 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000684 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000685
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000686 /// \brief Build a new parenthesized type.
687 ///
688 /// By default, builds a new ParenType type from the inner type.
689 /// Subclasses may override this routine to provide different behavior.
690 QualType RebuildParenType(QualType InnerType) {
691 return SemaRef.Context.getParenType(InnerType);
692 }
693
Douglas Gregord6ff3322009-08-04 16:50:30 +0000694 /// \brief Build a new qualified name type.
695 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000696 /// By default, builds a new ElaboratedType type from the keyword,
697 /// the nested-name-specifier and the named type.
698 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000699 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
700 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000701 NestedNameSpecifier *NNS, QualType Named) {
702 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000703 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000704
705 /// \brief Build a new typename type that refers to a template-id.
706 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000707 /// By default, builds a new DependentNameType type from the
708 /// nested-name-specifier and the given type. Subclasses may override
709 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000710 QualType RebuildDependentTemplateSpecializationType(
711 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000712 NestedNameSpecifier *Qualifier,
713 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000714 const IdentifierInfo *Name,
715 SourceLocation NameLoc,
716 const TemplateArgumentListInfo &Args) {
717 // Rebuild the template name.
718 // TODO: avoid TemplateName abstraction
719 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000720 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000721 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000722
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000723 if (InstName.isNull())
724 return QualType();
725
John McCallc392f372010-06-11 00:33:02 +0000726 // If it's still dependent, make a dependent specialization.
727 if (InstName.getAsDependentTemplateName())
728 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000729 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000730
731 // Otherwise, make an elaborated type wrapping a non-dependent
732 // specialization.
733 QualType T =
734 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
735 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000736
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000737 // NOTE: NNS is already recorded in template specialization type T.
738 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000739 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740
741 /// \brief Build a new typename type that refers to an identifier.
742 ///
743 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000744 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000746 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000747 NestedNameSpecifier *NNS,
748 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000749 SourceLocation KeywordLoc,
750 SourceRange NNSRange,
751 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000752 CXXScopeSpec SS;
753 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000754 SS.setRange(NNSRange);
755
Douglas Gregore677daf2010-03-31 22:19:08 +0000756 if (NNS->isDependent()) {
757 // If the name is still dependent, just build a new dependent name type.
758 if (!SemaRef.computeDeclContext(SS))
759 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
760 }
761
Abramo Bagnara6150c882010-05-11 21:36:43 +0000762 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000763 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
764 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000765
766 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
767
Abramo Bagnarad7548482010-05-19 21:37:53 +0000768 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000769 // into a non-dependent elaborated-type-specifier. Find the tag we're
770 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000771 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000772 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
773 if (!DC)
774 return QualType();
775
John McCallbf8c5192010-05-27 06:40:31 +0000776 if (SemaRef.RequireCompleteDeclContext(SS, DC))
777 return QualType();
778
Douglas Gregore677daf2010-03-31 22:19:08 +0000779 TagDecl *Tag = 0;
780 SemaRef.LookupQualifiedName(Result, DC);
781 switch (Result.getResultKind()) {
782 case LookupResult::NotFound:
783 case LookupResult::NotFoundInCurrentInstantiation:
784 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000785
Douglas Gregore677daf2010-03-31 22:19:08 +0000786 case LookupResult::Found:
787 Tag = Result.getAsSingle<TagDecl>();
788 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000789
Douglas Gregore677daf2010-03-31 22:19:08 +0000790 case LookupResult::FoundOverloaded:
791 case LookupResult::FoundUnresolvedValue:
792 llvm_unreachable("Tag lookup cannot find non-tags");
793 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000794
Douglas Gregore677daf2010-03-31 22:19:08 +0000795 case LookupResult::Ambiguous:
796 // Let the LookupResult structure handle ambiguities.
797 return QualType();
798 }
799
800 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000801 // Check where the name exists but isn't a tag type and use that to emit
802 // better diagnostics.
803 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
804 SemaRef.LookupQualifiedName(Result, DC);
805 switch (Result.getResultKind()) {
806 case LookupResult::Found:
807 case LookupResult::FoundOverloaded:
808 case LookupResult::FoundUnresolvedValue: {
809 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
810 unsigned Kind = 0;
811 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
812 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
813 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
814 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
815 break;
816 }
817 default:
818 // FIXME: Would be nice to highlight just the source range.
819 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
820 << Kind << Id << DC;
821 break;
822 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000823 return QualType();
824 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000825
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
827 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000828 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
829 return QualType();
830 }
831
832 // Build the elaborated-type-specifier type.
833 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000834 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000835 }
Mike Stump11289f42009-09-09 15:08:12 +0000836
Douglas Gregor822d0302011-01-12 17:07:58 +0000837 /// \brief Build a new pack expansion type.
838 ///
839 /// By default, builds a new PackExpansionType type from the given pattern.
840 /// Subclasses may override this routine to provide different behavior.
841 QualType RebuildPackExpansionType(QualType Pattern,
842 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000843 SourceLocation EllipsisLoc,
844 llvm::Optional<unsigned> NumExpansions) {
845 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
846 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000847 }
848
Douglas Gregor1135c352009-08-06 05:28:30 +0000849 /// \brief Build a new nested-name-specifier given the prefix and an
850 /// identifier that names the next step in the nested-name-specifier.
851 ///
852 /// By default, performs semantic analysis when building the new
853 /// nested-name-specifier. Subclasses may override this routine to provide
854 /// different behavior.
855 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
856 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000857 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000858 QualType ObjectType,
859 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000860
861 /// \brief Build a new nested-name-specifier given the prefix and the
862 /// namespace named in the next step in the nested-name-specifier.
863 ///
864 /// By default, performs semantic analysis when building the new
865 /// nested-name-specifier. Subclasses may override this routine to provide
866 /// different behavior.
867 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
868 SourceRange Range,
869 NamespaceDecl *NS);
870
871 /// \brief Build a new nested-name-specifier given the prefix and the
872 /// type named in the next step in the nested-name-specifier.
873 ///
874 /// By default, performs semantic analysis when building the new
875 /// nested-name-specifier. Subclasses may override this routine to provide
876 /// different behavior.
877 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
878 SourceRange Range,
879 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000880 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000881
882 /// \brief Build a new template name given a nested name specifier, a flag
883 /// indicating whether the "template" keyword was provided, and the template
884 /// that the template name refers to.
885 ///
886 /// By default, builds the new template name directly. Subclasses may override
887 /// this routine to provide different behavior.
888 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
889 bool TemplateKW,
890 TemplateDecl *Template);
891
Douglas Gregor71dc5092009-08-06 06:41:21 +0000892 /// \brief Build a new template name given a nested name specifier and the
893 /// name that is referred to as a template.
894 ///
895 /// By default, performs semantic analysis to determine whether the name can
896 /// be resolved to a specific template, then builds the appropriate kind of
897 /// template name. Subclasses may override this routine to provide different
898 /// behavior.
899 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000900 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000901 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000902 QualType ObjectType,
903 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000904
Douglas Gregor71395fa2009-11-04 00:56:37 +0000905 /// \brief Build a new template name given a nested name specifier and the
906 /// overloaded operator name that is referred to as a template.
907 ///
908 /// By default, performs semantic analysis to determine whether the name can
909 /// be resolved to a specific template, then builds the appropriate kind of
910 /// template name. Subclasses may override this routine to provide different
911 /// behavior.
912 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
913 OverloadedOperatorKind Operator,
914 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000915
916 /// \brief Build a new template name given a template template parameter pack
917 /// and the
918 ///
919 /// By default, performs semantic analysis to determine whether the name can
920 /// be resolved to a specific template, then builds the appropriate kind of
921 /// template name. Subclasses may override this routine to provide different
922 /// behavior.
923 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
924 const TemplateArgument &ArgPack) {
925 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
926 }
927
Douglas Gregorebe10102009-08-20 07:17:43 +0000928 /// \brief Build a new compound statement.
929 ///
930 /// By default, performs semantic analysis to build the new statement.
931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000932 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000933 MultiStmtArg Statements,
934 SourceLocation RBraceLoc,
935 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000936 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000937 IsStmtExpr);
938 }
939
940 /// \brief Build a new case statement.
941 ///
942 /// By default, performs semantic analysis to build the new statement.
943 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000944 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000945 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000946 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000947 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000948 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000949 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000950 ColonLoc);
951 }
Mike Stump11289f42009-09-09 15:08:12 +0000952
Douglas Gregorebe10102009-08-20 07:17:43 +0000953 /// \brief Attach the body to a new case statement.
954 ///
955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000957 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000958 getSema().ActOnCaseStmtBody(S, Body);
959 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 }
Mike Stump11289f42009-09-09 15:08:12 +0000961
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 /// \brief Build a new default statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000966 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000967 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000968 Stmt *SubStmt) {
969 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000970 /*CurScope=*/0);
971 }
Mike Stump11289f42009-09-09 15:08:12 +0000972
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 /// \brief Build a new label statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000977 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000978 IdentifierInfo *Id,
979 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000980 Stmt *SubStmt, bool HasUnusedAttr) {
981 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
982 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 }
Mike Stump11289f42009-09-09 15:08:12 +0000984
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 /// \brief Build a new "if" statement.
986 ///
987 /// By default, performs semantic analysis to build the new statement.
988 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000989 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000990 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000991 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000992 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 }
Mike Stump11289f42009-09-09 15:08:12 +0000994
Douglas Gregorebe10102009-08-20 07:17:43 +0000995 /// \brief Start building a new switch statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000999 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +00001000 Expr *Cond, VarDecl *CondVar) {
1001 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001002 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Douglas Gregorebe10102009-08-20 07:17:43 +00001005 /// \brief Attach the body to the switch statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001009 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +00001010 Stmt *Switch, Stmt *Body) {
1011 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 }
1013
1014 /// \brief Build a new while statement.
1015 ///
1016 /// By default, performs semantic analysis to build the new statement.
1017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001018 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00001019 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001020 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +00001021 Stmt *Body) {
1022 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregorebe10102009-08-20 07:17:43 +00001025 /// \brief Build a new do-while statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001029 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 SourceLocation WhileLoc,
1031 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001032 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +00001033 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001034 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1035 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new for statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001042 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001043 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001044 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001045 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +00001046 SourceLocation RParenLoc, Stmt *Body) {
1047 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +00001048 CondVar,
John McCallb268a282010-08-23 23:25:46 +00001049 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 }
Mike Stump11289f42009-09-09 15:08:12 +00001051
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 /// \brief Build a new goto statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001056 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001057 SourceLocation LabelLoc,
1058 LabelStmt *Label) {
1059 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1060 }
1061
1062 /// \brief Build a new indirect goto statement.
1063 ///
1064 /// By default, performs semantic analysis to build the new statement.
1065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001066 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001067 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +00001068 Expr *Target) {
1069 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Build a new return statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +00001077 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +00001078
John McCallb268a282010-08-23 23:25:46 +00001079 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregorebe10102009-08-20 07:17:43 +00001082 /// \brief Build a new declaration statement.
1083 ///
1084 /// By default, performs semantic analysis to build the new statement.
1085 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001086 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001087 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 SourceLocation EndLoc) {
1089 return getSema().Owned(
1090 new (getSema().Context) DeclStmt(
1091 DeclGroupRef::Create(getSema().Context,
1092 Decls, NumDecls),
1093 StartLoc, EndLoc));
1094 }
Mike Stump11289f42009-09-09 15:08:12 +00001095
Anders Carlssonaaeef072010-01-24 05:50:09 +00001096 /// \brief Build a new inline asm statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001101 bool IsSimple,
1102 bool IsVolatile,
1103 unsigned NumOutputs,
1104 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001105 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001106 MultiExprArg Constraints,
1107 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001108 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001109 MultiExprArg Clobbers,
1110 SourceLocation RParenLoc,
1111 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001112 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001114 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001115 RParenLoc, MSAsm);
1116 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001117
1118 /// \brief Build a new Objective-C @try statement.
1119 ///
1120 /// By default, performs semantic analysis to build the new statement.
1121 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001122 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001123 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001124 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001125 Stmt *Finally) {
1126 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1127 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001128 }
1129
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001130 /// \brief Rebuild an Objective-C exception declaration.
1131 ///
1132 /// By default, performs semantic analysis to build the new declaration.
1133 /// Subclasses may override this routine to provide different behavior.
1134 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1135 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001136 return getSema().BuildObjCExceptionDecl(TInfo, T,
1137 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001138 ExceptionDecl->getLocation());
1139 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001140
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001141 /// \brief Build a new Objective-C @catch statement.
1142 ///
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 RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001146 SourceLocation RParenLoc,
1147 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001148 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001149 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001150 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001151 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001152
Douglas Gregor306de2f2010-04-22 23:59:56 +00001153 /// \brief Build a new Objective-C @finally statement.
1154 ///
1155 /// By default, performs semantic analysis to build the new statement.
1156 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001157 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001158 Stmt *Body) {
1159 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001160 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001161
Douglas Gregor6148de72010-04-22 22:01:21 +00001162 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001166 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001167 Expr *Operand) {
1168 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001169 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001170
Douglas Gregor6148de72010-04-22 22:01:21 +00001171 /// \brief Build a new Objective-C @synchronized statement.
1172 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001173 /// By default, performs semantic analysis to build the new statement.
1174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001175 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001176 Expr *Object,
1177 Stmt *Body) {
1178 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1179 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001180 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001181
1182 /// \brief Build a new Objective-C fast enumeration statement.
1183 ///
1184 /// By default, performs semantic analysis to build the new statement.
1185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001186 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001187 SourceLocation LParenLoc,
1188 Stmt *Element,
1189 Expr *Collection,
1190 SourceLocation RParenLoc,
1191 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001192 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001193 Element,
1194 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001195 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001196 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001197 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001198
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 /// \brief Build a new C++ exception declaration.
1200 ///
1201 /// By default, performs semantic analysis to build the new decaration.
1202 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001203 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001204 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001205 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001206 SourceLocation Loc) {
1207 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 }
1209
1210 /// \brief Build a new C++ catch statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001215 VarDecl *ExceptionDecl,
1216 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001217 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1218 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new C++ try statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 Stmt *TryBlock,
1227 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001228 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 }
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 /// \brief Build a new expression that references a declaration.
1232 ///
1233 /// By default, performs semantic analysis to build the new expression.
1234 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001235 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001236 LookupResult &R,
1237 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001238 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1239 }
1240
1241
1242 /// \brief Build a new expression that references a declaration.
1243 ///
1244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001247 SourceRange QualifierRange,
1248 ValueDecl *VD,
1249 const DeclarationNameInfo &NameInfo,
1250 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001251 CXXScopeSpec SS;
1252 SS.setScopeRep(Qualifier);
1253 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001254
1255 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001256
1257 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001261 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001264 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001266 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 }
1268
Douglas Gregorad8a3362009-09-04 17:36:40 +00001269 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001270 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001271 /// By default, performs semantic analysis to build the new expression.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001274 SourceLocation OperatorLoc,
1275 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001276 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001277 SourceRange QualifierRange,
1278 TypeSourceInfo *ScopeType,
1279 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001280 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001281 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001284 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001287 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001288 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001289 Expr *SubExpr) {
1290 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 }
Mike Stump11289f42009-09-09 15:08:12 +00001292
Douglas Gregor882211c2010-04-28 22:16:22 +00001293 /// \brief Build a new builtin offsetof expression.
1294 ///
1295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001297 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001298 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001299 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001300 unsigned NumComponents,
1301 SourceLocation RParenLoc) {
1302 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1303 NumComponents, RParenLoc);
1304 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001305
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001307 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001310 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001311 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001313 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 }
1315
Mike Stump11289f42009-09-09 15:08:12 +00001316 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001318 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// By default, performs semantic analysis to build the new expression.
1320 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001321 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001323 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001324 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001326 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 return move(Result);
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001332 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001337 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001339 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1340 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 RBracketLoc);
1342 }
1343
1344 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001345 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001348 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001351 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001352 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 }
1354
1355 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001356 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 /// By default, performs semantic analysis to build the new expression.
1358 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001359 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001360 bool isArrow,
1361 NestedNameSpecifier *Qualifier,
1362 SourceRange QualifierRange,
1363 const DeclarationNameInfo &MemberNameInfo,
1364 ValueDecl *Member,
1365 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001366 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001367 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001368 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001369 // We have a reference to an unnamed field. This is always the
1370 // base of an anonymous struct/union member access, i.e. the
1371 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001372 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001373 assert(Member->getType()->isRecordType() &&
1374 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001375
John McCallb268a282010-08-23 23:25:46 +00001376 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001377 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001378 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001379
John McCall7decc9e2010-11-18 06:31:45 +00001380 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001381 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001382 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001383 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001384 cast<FieldDecl>(Member)->getType(),
1385 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001386 return getSema().Owned(ME);
1387 }
Mike Stump11289f42009-09-09 15:08:12 +00001388
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001389 CXXScopeSpec SS;
1390 if (Qualifier) {
1391 SS.setRange(QualifierRange);
1392 SS.setScopeRep(Qualifier);
1393 }
1394
John McCallb268a282010-08-23 23:25:46 +00001395 getSema().DefaultFunctionArrayConversion(Base);
1396 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001397
John McCall16df1e52010-03-30 21:47:33 +00001398 // FIXME: this involves duplicating earlier analysis in a lot of
1399 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001400 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001401 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001402 R.resolveKind();
1403
John McCallb268a282010-08-23 23:25:46 +00001404 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001405 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001406 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 }
Mike Stump11289f42009-09-09 15:08:12 +00001408
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001410 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 /// By default, performs semantic analysis to build the new expression.
1412 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001413 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001414 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001415 Expr *LHS, Expr *RHS) {
1416 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 }
1418
1419 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001420 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001423 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001425 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001427 Expr *RHS) {
1428 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1429 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 }
1431
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001433 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001436 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001437 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001439 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001440 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001441 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 }
Mike Stump11289f42009-09-09 15:08:12 +00001443
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001445 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001448 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001449 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001452 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001453 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 }
Mike Stump11289f42009-09-09 15:08:12 +00001455
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001457 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001460 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 SourceLocation OpLoc,
1462 SourceLocation AccessorLoc,
1463 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001464
John McCall10eae182009-11-30 22:42:35 +00001465 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001466 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001467 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001468 OpLoc, /*IsArrow*/ false,
1469 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001470 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001471 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 }
Mike Stump11289f42009-09-09 15:08:12 +00001473
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001475 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001480 SourceLocation RBraceLoc,
1481 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001482 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001483 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1484 if (Result.isInvalid() || ResultTy->isDependentType())
1485 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001486
Douglas Gregord3d93062009-11-09 17:16:50 +00001487 // Patch in the result type we were given, which may have been computed
1488 // when the initial InitListExpr was built.
1489 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1490 ILE->setType(ResultTy);
1491 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 }
Mike Stump11289f42009-09-09 15:08:12 +00001493
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001495 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001498 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 MultiExprArg ArrayExprs,
1500 SourceLocation EqualOrColonLoc,
1501 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001502 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001503 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001505 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001508
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 ArrayExprs.release();
1510 return move(Result);
1511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, builds the implicit value initialization without performing
1516 /// any semantic analysis. Subclasses may override this routine to provide
1517 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001518 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1520 }
Mike Stump11289f42009-09-09 15:08:12 +00001521
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001523 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 /// By default, performs semantic analysis to build the new expression.
1525 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001526 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001527 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001528 SourceLocation RParenLoc) {
1529 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001530 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001531 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 }
1533
1534 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001535 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001538 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 MultiExprArg SubExprs,
1540 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001541 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001542 move(SubExprs));
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 address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001546 ///
1547 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// rather than attempting to map the label statement itself.
1549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001550 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 SourceLocation LabelLoc,
1552 LabelStmt *Label) {
1553 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1554 }
Mike Stump11289f42009-09-09 15:08:12 +00001555
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001557 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001560 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001561 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001563 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 }
Mike Stump11289f42009-09-09 15:08:12 +00001565
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 /// \brief Build a new __builtin_choose_expr expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001570 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001571 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 SourceLocation RParenLoc) {
1573 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001574 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 RParenLoc);
1576 }
Mike Stump11289f42009-09-09 15:08:12 +00001577
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// \brief Build a new overloaded operator call expression.
1579 ///
1580 /// By default, performs semantic analysis to build the new expression.
1581 /// The semantic analysis provides the behavior of template instantiation,
1582 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001583 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 /// argument-dependent lookup, etc. Subclasses may override this routine to
1585 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001586 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001588 Expr *Callee,
1589 Expr *First,
1590 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001591
1592 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 /// reinterpret_cast.
1594 ///
1595 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001596 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001598 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 Stmt::StmtClass Class,
1600 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001601 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 SourceLocation RAngleLoc,
1603 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001604 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 SourceLocation RParenLoc) {
1606 switch (Class) {
1607 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001608 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001609 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001610 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001611
1612 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001613 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001614 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001615 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001618 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001619 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001620 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001624 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001625 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001626 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 default:
1629 assert(false && "Invalid C++ named cast");
1630 break;
1631 }
Mike Stump11289f42009-09-09 15:08:12 +00001632
John McCallfaf5fb42010-08-26 23:41:50 +00001633 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
Mike Stump11289f42009-09-09 15:08:12 +00001635
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 /// \brief Build a new C++ static_cast expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001640 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001642 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceLocation RAngleLoc,
1644 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001645 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001647 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001648 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001649 SourceRange(LAngleLoc, RAngleLoc),
1650 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001651 }
1652
1653 /// \brief Build a new C++ dynamic_cast expression.
1654 ///
1655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001657 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001659 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 SourceLocation RAngleLoc,
1661 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001662 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001664 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001665 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001666 SourceRange(LAngleLoc, RAngleLoc),
1667 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 }
1669
1670 /// \brief Build a new C++ reinterpret_cast expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001674 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001676 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 SourceLocation RAngleLoc,
1678 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001679 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001681 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001682 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001683 SourceRange(LAngleLoc, RAngleLoc),
1684 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001685 }
1686
1687 /// \brief Build a new C++ const_cast expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001691 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001693 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 SourceLocation RAngleLoc,
1695 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001698 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001699 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001700 SourceRange(LAngleLoc, RAngleLoc),
1701 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 /// \brief Build a new C++ functional-style cast expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001708 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1709 SourceLocation LParenLoc,
1710 Expr *Sub,
1711 SourceLocation RParenLoc) {
1712 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001713 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 RParenLoc);
1715 }
Mike Stump11289f42009-09-09 15:08:12 +00001716
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 /// \brief Build a new C++ typeid(type) expression.
1718 ///
1719 /// By default, performs semantic analysis to build the new expression.
1720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001721 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001722 SourceLocation TypeidLoc,
1723 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001725 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001726 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 }
Mike Stump11289f42009-09-09 15:08:12 +00001728
Francois Pichet9f4f2072010-09-08 12:20:18 +00001729
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 /// \brief Build a new C++ typeid(expr) expression.
1731 ///
1732 /// By default, performs semantic analysis to build the new expression.
1733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001734 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001735 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001736 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001738 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001739 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001740 }
1741
Francois Pichet9f4f2072010-09-08 12:20:18 +00001742 /// \brief Build a new C++ __uuidof(type) expression.
1743 ///
1744 /// By default, performs semantic analysis to build the new expression.
1745 /// Subclasses may override this routine to provide different behavior.
1746 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1747 SourceLocation TypeidLoc,
1748 TypeSourceInfo *Operand,
1749 SourceLocation RParenLoc) {
1750 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1751 RParenLoc);
1752 }
1753
1754 /// \brief Build a new C++ __uuidof(expr) expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
1758 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1759 SourceLocation TypeidLoc,
1760 Expr *Operand,
1761 SourceLocation RParenLoc) {
1762 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1763 RParenLoc);
1764 }
1765
Douglas Gregora16548e2009-08-11 05:31:07 +00001766 /// \brief Build a new C++ "this" expression.
1767 ///
1768 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001769 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001771 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001772 QualType ThisType,
1773 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001775 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1776 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 }
1778
1779 /// \brief Build a new C++ throw expression.
1780 ///
1781 /// By default, performs semantic analysis to build the new expression.
1782 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001783 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001784 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 }
1786
1787 /// \brief Build a new C++ default-argument expression.
1788 ///
1789 /// By default, builds a new default-argument expression, which does not
1790 /// require any semantic analysis. Subclasses may override this routine to
1791 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001793 ParmVarDecl *Param) {
1794 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1795 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 }
1797
1798 /// \brief Build a new C++ zero-initialization expression.
1799 ///
1800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001802 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1803 SourceLocation LParenLoc,
1804 SourceLocation RParenLoc) {
1805 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001806 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001807 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregora16548e2009-08-11 05:31:07 +00001810 /// \brief Build a new C++ "new" expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001814 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001815 bool UseGlobal,
1816 SourceLocation PlacementLParen,
1817 MultiExprArg PlacementArgs,
1818 SourceLocation PlacementRParen,
1819 SourceRange TypeIdParens,
1820 QualType AllocatedType,
1821 TypeSourceInfo *AllocatedTypeInfo,
1822 Expr *ArraySize,
1823 SourceLocation ConstructorLParen,
1824 MultiExprArg ConstructorArgs,
1825 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001826 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001827 PlacementLParen,
1828 move(PlacementArgs),
1829 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001830 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001831 AllocatedType,
1832 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001833 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 ConstructorLParen,
1835 move(ConstructorArgs),
1836 ConstructorRParen);
1837 }
Mike Stump11289f42009-09-09 15:08:12 +00001838
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 /// \brief Build a new C++ "delete" expression.
1840 ///
1841 /// By default, performs semantic analysis to build the new expression.
1842 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001843 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 bool IsGlobalDelete,
1845 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001846 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001848 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 }
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregora16548e2009-08-11 05:31:07 +00001851 /// \brief Build a new unary type trait expression.
1852 ///
1853 /// By default, performs semantic analysis to build the new expression.
1854 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001855 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001856 SourceLocation StartLoc,
1857 TypeSourceInfo *T,
1858 SourceLocation RParenLoc) {
1859 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 }
1861
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001862 /// \brief Build a new binary type trait expression.
1863 ///
1864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
1866 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1867 SourceLocation StartLoc,
1868 TypeSourceInfo *LhsT,
1869 TypeSourceInfo *RhsT,
1870 SourceLocation RParenLoc) {
1871 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1872 }
1873
Mike Stump11289f42009-09-09 15:08:12 +00001874 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// expression.
1876 ///
1877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001879 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001881 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001882 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 CXXScopeSpec SS;
1884 SS.setRange(QualifierRange);
1885 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001886
1887 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001888 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001889 *TemplateArgs);
1890
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001891 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 }
1893
1894 /// \brief Build a new template-id expression.
1895 ///
1896 /// By default, performs semantic analysis to build the new expression.
1897 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001898 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001899 LookupResult &R,
1900 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001901 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001902 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001903 }
1904
1905 /// \brief Build a new object-construction expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001909 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001910 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 CXXConstructorDecl *Constructor,
1912 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001913 MultiExprArg Args,
1914 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001915 CXXConstructExpr::ConstructionKind ConstructKind,
1916 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001917 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001918 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001919 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001920 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001921
Douglas Gregordb121ba2009-12-14 16:27:04 +00001922 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001923 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001924 RequiresZeroInit, ConstructKind,
1925 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 }
1927
1928 /// \brief Build a new object-construction expression.
1929 ///
1930 /// By default, performs semantic analysis to build the new expression.
1931 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001932 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1933 SourceLocation LParenLoc,
1934 MultiExprArg Args,
1935 SourceLocation RParenLoc) {
1936 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 LParenLoc,
1938 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001939 RParenLoc);
1940 }
1941
1942 /// \brief Build a new object-construction expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001946 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1947 SourceLocation LParenLoc,
1948 MultiExprArg Args,
1949 SourceLocation RParenLoc) {
1950 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 LParenLoc,
1952 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 RParenLoc);
1954 }
Mike Stump11289f42009-09-09 15:08:12 +00001955
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 /// \brief Build a new member reference expression.
1957 ///
1958 /// By default, performs semantic analysis to build the new expression.
1959 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001960 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001961 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 bool IsArrow,
1963 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001964 NestedNameSpecifier *Qualifier,
1965 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001966 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001967 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001968 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001969 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001970 SS.setRange(QualifierRange);
1971 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001972
John McCallb268a282010-08-23 23:25:46 +00001973 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001974 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001975 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001976 MemberNameInfo,
1977 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 }
1979
John McCall10eae182009-11-30 22:42:35 +00001980 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001981 ///
1982 /// By default, performs semantic analysis to build the new expression.
1983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001984 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001985 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001986 SourceLocation OperatorLoc,
1987 bool IsArrow,
1988 NestedNameSpecifier *Qualifier,
1989 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001990 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001991 LookupResult &R,
1992 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001993 CXXScopeSpec SS;
1994 SS.setRange(QualifierRange);
1995 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001996
John McCallb268a282010-08-23 23:25:46 +00001997 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001998 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001999 SS, FirstQualifierInScope,
2000 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002001 }
Mike Stump11289f42009-09-09 15:08:12 +00002002
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002003 /// \brief Build a new noexcept expression.
2004 ///
2005 /// By default, performs semantic analysis to build the new expression.
2006 /// Subclasses may override this routine to provide different behavior.
2007 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2008 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2009 }
2010
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002011 /// \brief Build a new expression to compute the length of a parameter pack.
2012 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2013 SourceLocation PackLoc,
2014 SourceLocation RParenLoc,
2015 unsigned Length) {
2016 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2017 OperatorLoc, Pack, PackLoc,
2018 RParenLoc, Length);
2019 }
2020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// \brief Build a new Objective-C @encode expression.
2022 ///
2023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002026 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002028 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002030 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002031
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002032 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002033 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002034 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002035 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002036 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002037 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002038 MultiExprArg Args,
2039 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002040 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2041 ReceiverTypeInfo->getType(),
2042 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002043 Sel, Method, LBracLoc, SelectorLoc,
2044 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 }
2046
2047 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002048 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002050 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002051 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002052 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002053 MultiExprArg Args,
2054 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002055 return SemaRef.BuildInstanceMessage(Receiver,
2056 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002057 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002058 Sel, Method, LBracLoc, SelectorLoc,
2059 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002060 }
2061
Douglas Gregord51d90d2010-04-26 20:11:03 +00002062 /// \brief Build a new Objective-C ivar reference expression.
2063 ///
2064 /// By default, performs semantic analysis to build the new expression.
2065 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002066 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002067 SourceLocation IvarLoc,
2068 bool IsArrow, bool IsFreeIvar) {
2069 // FIXME: We lose track of the IsFreeIvar bit.
2070 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002071 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002072 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2073 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002075 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002076 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002077 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002078 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002079 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002080
Douglas Gregord51d90d2010-04-26 20:11:03 +00002081 if (Result.get())
2082 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002083
John McCallb268a282010-08-23 23:25:46 +00002084 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002085 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002086 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002087 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002088 /*TemplateArgs=*/0);
2089 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002090
2091 /// \brief Build a new Objective-C property reference expression.
2092 ///
2093 /// By default, performs semantic analysis to build the new expression.
2094 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002095 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002096 ObjCPropertyDecl *Property,
2097 SourceLocation PropertyLoc) {
2098 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002099 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002100 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2101 Sema::LookupMemberName);
2102 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002104 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002105 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002106 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002107 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002108
Douglas Gregor9faee212010-04-26 20:47:02 +00002109 if (Result.get())
2110 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002111
John McCallb268a282010-08-23 23:25:46 +00002112 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113 /*FIXME:*/PropertyLoc, IsArrow,
2114 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002115 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002116 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002117 /*TemplateArgs=*/0);
2118 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002119
John McCallb7bd14f2010-12-02 01:19:52 +00002120 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002121 ///
2122 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002123 /// Subclasses may override this routine to provide different behavior.
2124 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2125 ObjCMethodDecl *Getter,
2126 ObjCMethodDecl *Setter,
2127 SourceLocation PropertyLoc) {
2128 // Since these expressions can only be value-dependent, we do not
2129 // need to perform semantic analysis again.
2130 return Owned(
2131 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2132 VK_LValue, OK_ObjCProperty,
2133 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002134 }
2135
Douglas Gregord51d90d2010-04-26 20:11:03 +00002136 /// \brief Build a new Objective-C "isa" expression.
2137 ///
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 bool IsArrow) {
2142 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002143 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2145 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002146 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002147 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002148 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002150 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002151
Douglas Gregord51d90d2010-04-26 20:11:03 +00002152 if (Result.get())
2153 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002154
John McCallb268a282010-08-23 23:25:46 +00002155 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002156 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002157 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002158 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002159 /*TemplateArgs=*/0);
2160 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002161
Douglas Gregora16548e2009-08-11 05:31:07 +00002162 /// \brief Build a new shuffle vector expression.
2163 ///
2164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002167 MultiExprArg SubExprs,
2168 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002170 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2172 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2173 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2174 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002175
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 // Build a reference to the __builtin_shufflevector builtin
2177 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002178 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002180 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002182
2183 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 unsigned NumSubExprs = SubExprs.size();
2185 Expr **Subs = (Expr **)SubExprs.release();
2186 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2187 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002188 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002189 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002192
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002194 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002197
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002199 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 }
John McCall31f82722010-11-12 08:19:04 +00002201
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002202 /// \brief Build a new template argument pack expansion.
2203 ///
2204 /// By default, performs semantic analysis to build a new pack expansion
2205 /// for a template argument. Subclasses may override this routine to provide
2206 /// different behavior.
2207 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002208 SourceLocation EllipsisLoc,
2209 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002210 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002211 case TemplateArgument::Expression: {
2212 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002213 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2214 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002215 if (Result.isInvalid())
2216 return TemplateArgumentLoc();
2217
2218 return TemplateArgumentLoc(Result.get(), Result.get());
2219 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002220
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002221 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002222 return TemplateArgumentLoc(TemplateArgument(
2223 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002224 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002225 Pattern.getTemplateQualifierRange(),
2226 Pattern.getTemplateNameLoc(),
2227 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002228
2229 case TemplateArgument::Null:
2230 case TemplateArgument::Integral:
2231 case TemplateArgument::Declaration:
2232 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002233 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002234 llvm_unreachable("Pack expansion pattern has no parameter packs");
2235
2236 case TemplateArgument::Type:
2237 if (TypeSourceInfo *Expansion
2238 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002239 EllipsisLoc,
2240 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002241 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2242 Expansion);
2243 break;
2244 }
2245
2246 return TemplateArgumentLoc();
2247 }
2248
Douglas Gregor968f23a2011-01-03 19:31:53 +00002249 /// \brief Build a new expression pack expansion.
2250 ///
2251 /// By default, performs semantic analysis to build a new pack expansion
2252 /// for an expression. Subclasses may override this routine to provide
2253 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002254 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2255 llvm::Optional<unsigned> NumExpansions) {
2256 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002257 }
2258
John McCall31f82722010-11-12 08:19:04 +00002259private:
2260 QualType TransformTypeInObjectScope(QualType T,
2261 QualType ObjectType,
2262 NamedDecl *FirstQualifierInScope,
2263 NestedNameSpecifier *Prefix);
2264
2265 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2266 QualType ObjectType,
2267 NamedDecl *FirstQualifierInScope,
2268 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002269};
Douglas Gregora16548e2009-08-11 05:31:07 +00002270
Douglas Gregorebe10102009-08-20 07:17:43 +00002271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002272StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002273 if (!S)
2274 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregorebe10102009-08-20 07:17:43 +00002276 switch (S->getStmtClass()) {
2277 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002278
Douglas Gregorebe10102009-08-20 07:17:43 +00002279 // Transform individual statement nodes
2280#define STMT(Node, Parent) \
2281 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2282#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002283#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregorebe10102009-08-20 07:17:43 +00002285 // Transform expressions by calling TransformExpr.
2286#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002287#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002288#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002289#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002290 {
John McCalldadc5752010-08-24 06:29:42 +00002291 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002292 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002293 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002294
John McCallb268a282010-08-23 23:25:46 +00002295 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002296 }
Mike Stump11289f42009-09-09 15:08:12 +00002297 }
2298
John McCallc3007a22010-10-26 07:05:15 +00002299 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002300}
Mike Stump11289f42009-09-09 15:08:12 +00002301
2302
Douglas Gregore922c772009-08-04 22:27:00 +00002303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002304ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 if (!E)
2306 return SemaRef.Owned(E);
2307
2308 switch (E->getStmtClass()) {
2309 case Stmt::NoStmtClass: break;
2310#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002311#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002312#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002313 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002314#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002315 }
2316
John McCallc3007a22010-10-26 07:05:15 +00002317 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002318}
2319
2320template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002321bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2322 unsigned NumInputs,
2323 bool IsCall,
2324 llvm::SmallVectorImpl<Expr *> &Outputs,
2325 bool *ArgChanged) {
2326 for (unsigned I = 0; I != NumInputs; ++I) {
2327 // If requested, drop call arguments that need to be dropped.
2328 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2329 if (ArgChanged)
2330 *ArgChanged = true;
2331
2332 break;
2333 }
2334
Douglas Gregor968f23a2011-01-03 19:31:53 +00002335 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2336 Expr *Pattern = Expansion->getPattern();
2337
2338 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2339 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2340 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2341
2342 // Determine whether the set of unexpanded parameter packs can and should
2343 // be expanded.
2344 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002345 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002346 llvm::Optional<unsigned> OrigNumExpansions
2347 = Expansion->getNumExpansions();
2348 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002349 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2350 Pattern->getSourceRange(),
2351 Unexpanded.data(),
2352 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002353 Expand, RetainExpansion,
2354 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002355 return true;
2356
2357 if (!Expand) {
2358 // The transform has determined that we should perform a simple
2359 // transformation on the pack expansion, producing another pack
2360 // expansion.
2361 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2362 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2363 if (OutPattern.isInvalid())
2364 return true;
2365
2366 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002367 Expansion->getEllipsisLoc(),
2368 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002369 if (Out.isInvalid())
2370 return true;
2371
2372 if (ArgChanged)
2373 *ArgChanged = true;
2374 Outputs.push_back(Out.get());
2375 continue;
2376 }
2377
2378 // The transform has determined that we should perform an elementwise
2379 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002380 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002381 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2382 ExprResult Out = getDerived().TransformExpr(Pattern);
2383 if (Out.isInvalid())
2384 return true;
2385
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002386 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002387 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2388 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002389 if (Out.isInvalid())
2390 return true;
2391 }
2392
Douglas Gregor968f23a2011-01-03 19:31:53 +00002393 if (ArgChanged)
2394 *ArgChanged = true;
2395 Outputs.push_back(Out.get());
2396 }
2397
2398 continue;
2399 }
2400
Douglas Gregora3efea12011-01-03 19:04:46 +00002401 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2402 if (Result.isInvalid())
2403 return true;
2404
2405 if (Result.get() != Inputs[I] && ArgChanged)
2406 *ArgChanged = true;
2407
2408 Outputs.push_back(Result.get());
2409 }
2410
2411 return false;
2412}
2413
2414template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002415NestedNameSpecifier *
2416TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002417 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002418 QualType ObjectType,
2419 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002420 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002421
Douglas Gregorebe10102009-08-20 07:17:43 +00002422 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002423 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002424 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002425 ObjectType,
2426 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002427 if (!Prefix)
2428 return 0;
2429 }
Mike Stump11289f42009-09-09 15:08:12 +00002430
Douglas Gregor1135c352009-08-06 05:28:30 +00002431 switch (NNS->getKind()) {
2432 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002433 if (Prefix) {
2434 // The object type and qualifier-in-scope really apply to the
2435 // leftmost entity.
2436 ObjectType = QualType();
2437 FirstQualifierInScope = 0;
2438 }
2439
Mike Stump11289f42009-09-09 15:08:12 +00002440 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002441 "Identifier nested-name-specifier with no prefix or object type");
2442 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2443 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002444 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002445
2446 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002447 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002448 ObjectType,
2449 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002450
Douglas Gregor1135c352009-08-06 05:28:30 +00002451 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002452 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002453 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002454 getDerived().TransformDecl(Range.getBegin(),
2455 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002456 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002457 Prefix == NNS->getPrefix() &&
2458 NS == NNS->getAsNamespace())
2459 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002460
Douglas Gregor1135c352009-08-06 05:28:30 +00002461 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2462 }
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregor1135c352009-08-06 05:28:30 +00002464 case NestedNameSpecifier::Global:
2465 // There is no meaningful transformation that one could perform on the
2466 // global scope.
2467 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002468
Douglas Gregor1135c352009-08-06 05:28:30 +00002469 case NestedNameSpecifier::TypeSpecWithTemplate:
2470 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002471 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002472 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2473 ObjectType,
2474 FirstQualifierInScope,
2475 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002476 if (T.isNull())
2477 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002478
Douglas Gregor1135c352009-08-06 05:28:30 +00002479 if (!getDerived().AlwaysRebuild() &&
2480 Prefix == NNS->getPrefix() &&
2481 T == QualType(NNS->getAsType(), 0))
2482 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002483
2484 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2485 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002486 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002487 }
2488 }
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregor1135c352009-08-06 05:28:30 +00002490 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002491 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002492}
2493
2494template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002495DeclarationNameInfo
2496TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002497::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002498 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002499 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002500 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002501
2502 switch (Name.getNameKind()) {
2503 case DeclarationName::Identifier:
2504 case DeclarationName::ObjCZeroArgSelector:
2505 case DeclarationName::ObjCOneArgSelector:
2506 case DeclarationName::ObjCMultiArgSelector:
2507 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002508 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002509 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002510 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002511
Douglas Gregorf816bd72009-09-03 22:13:48 +00002512 case DeclarationName::CXXConstructorName:
2513 case DeclarationName::CXXDestructorName:
2514 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002515 TypeSourceInfo *NewTInfo;
2516 CanQualType NewCanTy;
2517 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002518 NewTInfo = getDerived().TransformType(OldTInfo);
2519 if (!NewTInfo)
2520 return DeclarationNameInfo();
2521 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002522 }
2523 else {
2524 NewTInfo = 0;
2525 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002526 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002527 if (NewT.isNull())
2528 return DeclarationNameInfo();
2529 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2530 }
Mike Stump11289f42009-09-09 15:08:12 +00002531
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002532 DeclarationName NewName
2533 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2534 NewCanTy);
2535 DeclarationNameInfo NewNameInfo(NameInfo);
2536 NewNameInfo.setName(NewName);
2537 NewNameInfo.setNamedTypeInfo(NewTInfo);
2538 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002539 }
Mike Stump11289f42009-09-09 15:08:12 +00002540 }
2541
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002542 assert(0 && "Unknown name kind.");
2543 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002544}
2545
2546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002547TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002548TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002549 QualType ObjectType,
2550 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002551 SourceLocation Loc = getDerived().getBaseLocation();
2552
Douglas Gregor71dc5092009-08-06 06:41:21 +00002553 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002554 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002555 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002556 /*FIXME*/ SourceRange(Loc),
2557 ObjectType,
2558 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002559 if (!NNS)
2560 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002561
Douglas Gregor71dc5092009-08-06 06:41:21 +00002562 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002563 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002564 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002565 if (!TransTemplate)
2566 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregor71dc5092009-08-06 06:41:21 +00002568 if (!getDerived().AlwaysRebuild() &&
2569 NNS == QTN->getQualifier() &&
2570 TransTemplate == Template)
2571 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002572
Douglas Gregor71dc5092009-08-06 06:41:21 +00002573 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2574 TransTemplate);
2575 }
Mike Stump11289f42009-09-09 15:08:12 +00002576
John McCalle66edc12009-11-24 19:00:30 +00002577 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002578 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002579 }
Mike Stump11289f42009-09-09 15:08:12 +00002580
Douglas Gregor71dc5092009-08-06 06:41:21 +00002581 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002582 NestedNameSpecifier *NNS = DTN->getQualifier();
2583 if (NNS) {
2584 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2585 /*FIXME:*/SourceRange(Loc),
2586 ObjectType,
2587 FirstQualifierInScope);
2588 if (!NNS) return TemplateName();
2589
2590 // These apply to the scope specifier, not the template.
2591 ObjectType = QualType();
2592 FirstQualifierInScope = 0;
2593 }
Mike Stump11289f42009-09-09 15:08:12 +00002594
Douglas Gregor71dc5092009-08-06 06:41:21 +00002595 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002596 NNS == DTN->getQualifier() &&
2597 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002598 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002599
Douglas Gregora5614c52010-09-08 23:56:00 +00002600 if (DTN->isIdentifier()) {
2601 // FIXME: Bad range
2602 SourceRange QualifierRange(getDerived().getBaseLocation());
2603 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2604 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002605 ObjectType,
2606 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002607 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002608
2609 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002610 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002611 }
Mike Stump11289f42009-09-09 15:08:12 +00002612
Douglas Gregor71dc5092009-08-06 06:41:21 +00002613 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002614 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002615 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002616 if (!TransTemplate)
2617 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002618
Douglas Gregor71dc5092009-08-06 06:41:21 +00002619 if (!getDerived().AlwaysRebuild() &&
2620 TransTemplate == Template)
2621 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002622
Douglas Gregor71dc5092009-08-06 06:41:21 +00002623 return TemplateName(TransTemplate);
2624 }
Mike Stump11289f42009-09-09 15:08:12 +00002625
Douglas Gregor5590be02011-01-15 06:45:20 +00002626 if (SubstTemplateTemplateParmPackStorage *SubstPack
2627 = Name.getAsSubstTemplateTemplateParmPack()) {
2628 TemplateTemplateParmDecl *TransParam
2629 = cast_or_null<TemplateTemplateParmDecl>(
2630 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2631 if (!TransParam)
2632 return TemplateName();
2633
2634 if (!getDerived().AlwaysRebuild() &&
2635 TransParam == SubstPack->getParameterPack())
2636 return Name;
2637
2638 return getDerived().RebuildTemplateName(TransParam,
2639 SubstPack->getArgumentPack());
2640 }
2641
John McCalle66edc12009-11-24 19:00:30 +00002642 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002643 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002644 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002645}
2646
2647template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002648void TreeTransform<Derived>::InventTemplateArgumentLoc(
2649 const TemplateArgument &Arg,
2650 TemplateArgumentLoc &Output) {
2651 SourceLocation Loc = getDerived().getBaseLocation();
2652 switch (Arg.getKind()) {
2653 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002654 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002655 break;
2656
2657 case TemplateArgument::Type:
2658 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002659 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002660
John McCall0ad16662009-10-29 08:12:44 +00002661 break;
2662
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002663 case TemplateArgument::Template:
2664 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2665 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002666
2667 case TemplateArgument::TemplateExpansion:
2668 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2669 break;
2670
John McCall0ad16662009-10-29 08:12:44 +00002671 case TemplateArgument::Expression:
2672 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2673 break;
2674
2675 case TemplateArgument::Declaration:
2676 case TemplateArgument::Integral:
2677 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002678 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002679 break;
2680 }
2681}
2682
2683template<typename Derived>
2684bool TreeTransform<Derived>::TransformTemplateArgument(
2685 const TemplateArgumentLoc &Input,
2686 TemplateArgumentLoc &Output) {
2687 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002688 switch (Arg.getKind()) {
2689 case TemplateArgument::Null:
2690 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002691 Output = Input;
2692 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002693
Douglas Gregore922c772009-08-04 22:27:00 +00002694 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002695 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002696 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002697 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002698
2699 DI = getDerived().TransformType(DI);
2700 if (!DI) return true;
2701
2702 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2703 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002704 }
Mike Stump11289f42009-09-09 15:08:12 +00002705
Douglas Gregore922c772009-08-04 22:27:00 +00002706 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002707 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002708 DeclarationName Name;
2709 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2710 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002711 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002712 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002713 if (!D) return true;
2714
John McCall0d07eb32009-10-29 18:45:58 +00002715 Expr *SourceExpr = Input.getSourceDeclExpression();
2716 if (SourceExpr) {
2717 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002718 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002719 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002720 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002721 }
2722
2723 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002724 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002725 }
Mike Stump11289f42009-09-09 15:08:12 +00002726
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002727 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002728 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002729 TemplateName Template
2730 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2731 if (Template.isNull())
2732 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002733
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002734 Output = TemplateArgumentLoc(TemplateArgument(Template),
2735 Input.getTemplateQualifierRange(),
2736 Input.getTemplateNameLoc());
2737 return false;
2738 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002739
2740 case TemplateArgument::TemplateExpansion:
2741 llvm_unreachable("Caller should expand pack expansions");
2742
Douglas Gregore922c772009-08-04 22:27:00 +00002743 case TemplateArgument::Expression: {
2744 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002745 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002746 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002747
John McCall0ad16662009-10-29 08:12:44 +00002748 Expr *InputExpr = Input.getSourceExpression();
2749 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2750
John McCalldadc5752010-08-24 06:29:42 +00002751 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002752 = getDerived().TransformExpr(InputExpr);
2753 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002754 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002755 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002756 }
Mike Stump11289f42009-09-09 15:08:12 +00002757
Douglas Gregore922c772009-08-04 22:27:00 +00002758 case TemplateArgument::Pack: {
2759 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2760 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002761 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002762 AEnd = Arg.pack_end();
2763 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002764
John McCall0ad16662009-10-29 08:12:44 +00002765 // FIXME: preserve source information here when we start
2766 // caring about parameter packs.
2767
John McCall0d07eb32009-10-29 18:45:58 +00002768 TemplateArgumentLoc InputArg;
2769 TemplateArgumentLoc OutputArg;
2770 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2771 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002772 return true;
2773
John McCall0d07eb32009-10-29 18:45:58 +00002774 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002775 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002776
2777 TemplateArgument *TransformedArgsPtr
2778 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2779 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2780 TransformedArgsPtr);
2781 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2782 TransformedArgs.size()),
2783 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002784 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002785 }
2786 }
Mike Stump11289f42009-09-09 15:08:12 +00002787
Douglas Gregore922c772009-08-04 22:27:00 +00002788 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002789 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002790}
2791
Douglas Gregorfe921a72010-12-20 23:36:19 +00002792/// \brief Iterator adaptor that invents template argument location information
2793/// for each of the template arguments in its underlying iterator.
2794template<typename Derived, typename InputIterator>
2795class TemplateArgumentLocInventIterator {
2796 TreeTransform<Derived> &Self;
2797 InputIterator Iter;
2798
2799public:
2800 typedef TemplateArgumentLoc value_type;
2801 typedef TemplateArgumentLoc reference;
2802 typedef typename std::iterator_traits<InputIterator>::difference_type
2803 difference_type;
2804 typedef std::input_iterator_tag iterator_category;
2805
2806 class pointer {
2807 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002808
Douglas Gregorfe921a72010-12-20 23:36:19 +00002809 public:
2810 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2811
2812 const TemplateArgumentLoc *operator->() const { return &Arg; }
2813 };
2814
2815 TemplateArgumentLocInventIterator() { }
2816
2817 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2818 InputIterator Iter)
2819 : Self(Self), Iter(Iter) { }
2820
2821 TemplateArgumentLocInventIterator &operator++() {
2822 ++Iter;
2823 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002824 }
2825
Douglas Gregorfe921a72010-12-20 23:36:19 +00002826 TemplateArgumentLocInventIterator operator++(int) {
2827 TemplateArgumentLocInventIterator Old(*this);
2828 ++(*this);
2829 return Old;
2830 }
2831
2832 reference operator*() const {
2833 TemplateArgumentLoc Result;
2834 Self.InventTemplateArgumentLoc(*Iter, Result);
2835 return Result;
2836 }
2837
2838 pointer operator->() const { return pointer(**this); }
2839
2840 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2841 const TemplateArgumentLocInventIterator &Y) {
2842 return X.Iter == Y.Iter;
2843 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002844
Douglas Gregorfe921a72010-12-20 23:36:19 +00002845 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2846 const TemplateArgumentLocInventIterator &Y) {
2847 return X.Iter != Y.Iter;
2848 }
2849};
2850
Douglas Gregor42cafa82010-12-20 17:42:22 +00002851template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002852template<typename InputIterator>
2853bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2854 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002855 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002856 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002857 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002858 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002859
2860 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2861 // Unpack argument packs, which we translate them into separate
2862 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002863 // FIXME: We could do much better if we could guarantee that the
2864 // TemplateArgumentLocInfo for the pack expansion would be usable for
2865 // all of the template arguments in the argument pack.
2866 typedef TemplateArgumentLocInventIterator<Derived,
2867 TemplateArgument::pack_iterator>
2868 PackLocIterator;
2869 if (TransformTemplateArguments(PackLocIterator(*this,
2870 In.getArgument().pack_begin()),
2871 PackLocIterator(*this,
2872 In.getArgument().pack_end()),
2873 Outputs))
2874 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002875
2876 continue;
2877 }
2878
2879 if (In.getArgument().isPackExpansion()) {
2880 // We have a pack expansion, for which we will be substituting into
2881 // the pattern.
2882 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002883 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002884 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002885 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2886 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002887
2888 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2889 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2890 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2891
2892 // Determine whether the set of unexpanded parameter packs can and should
2893 // be expanded.
2894 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002895 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002896 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002897 if (getDerived().TryExpandParameterPacks(Ellipsis,
2898 Pattern.getSourceRange(),
2899 Unexpanded.data(),
2900 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002901 Expand,
2902 RetainExpansion,
2903 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002904 return true;
2905
2906 if (!Expand) {
2907 // The transform has determined that we should perform a simple
2908 // transformation on the pack expansion, producing another pack
2909 // expansion.
2910 TemplateArgumentLoc OutPattern;
2911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2912 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2913 return true;
2914
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002915 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2916 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002917 if (Out.getArgument().isNull())
2918 return true;
2919
2920 Outputs.addArgument(Out);
2921 continue;
2922 }
2923
2924 // The transform has determined that we should perform an elementwise
2925 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002926 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002927 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2928
2929 if (getDerived().TransformTemplateArgument(Pattern, Out))
2930 return true;
2931
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002932 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002933 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2934 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002935 if (Out.getArgument().isNull())
2936 return true;
2937 }
2938
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002939 Outputs.addArgument(Out);
2940 }
2941
Douglas Gregor48d24112011-01-10 20:53:55 +00002942 // If we're supposed to retain a pack expansion, do so by temporarily
2943 // forgetting the partially-substituted parameter pack.
2944 if (RetainExpansion) {
2945 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2946
2947 if (getDerived().TransformTemplateArgument(Pattern, Out))
2948 return true;
2949
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002950 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2951 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002952 if (Out.getArgument().isNull())
2953 return true;
2954
2955 Outputs.addArgument(Out);
2956 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002957
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002958 continue;
2959 }
2960
2961 // The simple case:
2962 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002963 return true;
2964
2965 Outputs.addArgument(Out);
2966 }
2967
2968 return false;
2969
2970}
2971
Douglas Gregord6ff3322009-08-04 16:50:30 +00002972//===----------------------------------------------------------------------===//
2973// Type transformation
2974//===----------------------------------------------------------------------===//
2975
2976template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002977QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002978 if (getDerived().AlreadyTransformed(T))
2979 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002980
John McCall550e0c22009-10-21 00:40:46 +00002981 // Temporary workaround. All of these transformations should
2982 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002983 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2984 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002985
John McCall31f82722010-11-12 08:19:04 +00002986 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002987
John McCall550e0c22009-10-21 00:40:46 +00002988 if (!NewDI)
2989 return QualType();
2990
2991 return NewDI->getType();
2992}
2993
2994template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002995TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002996 if (getDerived().AlreadyTransformed(DI->getType()))
2997 return DI;
2998
2999 TypeLocBuilder TLB;
3000
3001 TypeLoc TL = DI->getTypeLoc();
3002 TLB.reserve(TL.getFullDataSize());
3003
John McCall31f82722010-11-12 08:19:04 +00003004 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003005 if (Result.isNull())
3006 return 0;
3007
John McCallbcd03502009-12-07 02:54:59 +00003008 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003009}
3010
3011template<typename Derived>
3012QualType
John McCall31f82722010-11-12 08:19:04 +00003013TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003014 switch (T.getTypeLocClass()) {
3015#define ABSTRACT_TYPELOC(CLASS, PARENT)
3016#define TYPELOC(CLASS, PARENT) \
3017 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003018 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003019#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020 }
Mike Stump11289f42009-09-09 15:08:12 +00003021
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003022 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003023 return QualType();
3024}
3025
3026/// FIXME: By default, this routine adds type qualifiers only to types
3027/// that can have qualifiers, and silently suppresses those qualifiers
3028/// that are not permitted (e.g., qualifiers on reference or function
3029/// types). This is the right thing for template instantiation, but
3030/// probably not for other clients.
3031template<typename Derived>
3032QualType
3033TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003034 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003035 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003036
John McCall31f82722010-11-12 08:19:04 +00003037 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003038 if (Result.isNull())
3039 return QualType();
3040
3041 // Silently suppress qualifiers if the result type can't be qualified.
3042 // FIXME: this is the right thing for template instantiation, but
3043 // probably not for other clients.
3044 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003045 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003046
John McCallcb0f89a2010-06-05 06:41:15 +00003047 if (!Quals.empty()) {
3048 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3049 TLB.push<QualifiedTypeLoc>(Result);
3050 // No location information to preserve.
3051 }
John McCall550e0c22009-10-21 00:40:46 +00003052
3053 return Result;
3054}
3055
John McCall31f82722010-11-12 08:19:04 +00003056/// \brief Transforms a type that was written in a scope specifier,
3057/// given an object type, the results of unqualified lookup, and
3058/// an already-instantiated prefix.
3059///
3060/// The object type is provided iff the scope specifier qualifies the
3061/// member of a dependent member-access expression. The prefix is
3062/// provided iff the the scope specifier in which this appears has a
3063/// prefix.
3064///
3065/// This is private to TreeTransform.
3066template<typename Derived>
3067QualType
3068TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3069 QualType ObjectType,
3070 NamedDecl *UnqualLookup,
3071 NestedNameSpecifier *Prefix) {
3072 if (getDerived().AlreadyTransformed(T))
3073 return T;
3074
3075 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003076 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003077
3078 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3079 UnqualLookup, Prefix);
3080 if (!TSI) return QualType();
3081 return TSI->getType();
3082}
3083
3084template<typename Derived>
3085TypeSourceInfo *
3086TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3087 QualType ObjectType,
3088 NamedDecl *UnqualLookup,
3089 NestedNameSpecifier *Prefix) {
3090 // TODO: in some cases, we might be some verification to do here.
3091 if (ObjectType.isNull())
3092 return getDerived().TransformType(TSI);
3093
3094 QualType T = TSI->getType();
3095 if (getDerived().AlreadyTransformed(T))
3096 return TSI;
3097
3098 TypeLocBuilder TLB;
3099 QualType Result;
3100
3101 if (isa<TemplateSpecializationType>(T)) {
3102 TemplateSpecializationTypeLoc TL
3103 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3104
3105 TemplateName Template =
3106 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3107 ObjectType, UnqualLookup);
3108 if (Template.isNull()) return 0;
3109
3110 Result = getDerived()
3111 .TransformTemplateSpecializationType(TLB, TL, Template);
3112 } else if (isa<DependentTemplateSpecializationType>(T)) {
3113 DependentTemplateSpecializationTypeLoc TL
3114 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3115
3116 Result = getDerived()
3117 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3118 } else {
3119 // Nothing special needs to be done for these.
3120 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3121 }
3122
3123 if (Result.isNull()) return 0;
3124 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3125}
3126
John McCall550e0c22009-10-21 00:40:46 +00003127template <class TyLoc> static inline
3128QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3129 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3130 NewT.setNameLoc(T.getNameLoc());
3131 return T.getType();
3132}
3133
John McCall550e0c22009-10-21 00:40:46 +00003134template<typename Derived>
3135QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003136 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003137 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3138 NewT.setBuiltinLoc(T.getBuiltinLoc());
3139 if (T.needsExtraLocalData())
3140 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3141 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142}
Mike Stump11289f42009-09-09 15:08:12 +00003143
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003145QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003146 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003147 // FIXME: recurse?
3148 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149}
Mike Stump11289f42009-09-09 15:08:12 +00003150
Douglas Gregord6ff3322009-08-04 16:50:30 +00003151template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003152QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003153 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003154 QualType PointeeType
3155 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003156 if (PointeeType.isNull())
3157 return QualType();
3158
3159 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003160 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003161 // A dependent pointer type 'T *' has is being transformed such
3162 // that an Objective-C class type is being replaced for 'T'. The
3163 // resulting pointer type is an ObjCObjectPointerType, not a
3164 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003165 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003166
John McCall8b07ec22010-05-15 11:32:37 +00003167 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3168 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003169 return Result;
3170 }
John McCall31f82722010-11-12 08:19:04 +00003171
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003172 if (getDerived().AlwaysRebuild() ||
3173 PointeeType != TL.getPointeeLoc().getType()) {
3174 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3175 if (Result.isNull())
3176 return QualType();
3177 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003178
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003179 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3180 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003181 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003182}
Mike Stump11289f42009-09-09 15:08:12 +00003183
3184template<typename Derived>
3185QualType
John McCall550e0c22009-10-21 00:40:46 +00003186TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003187 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003188 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003189 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3190 if (PointeeType.isNull())
3191 return QualType();
3192
3193 QualType Result = TL.getType();
3194 if (getDerived().AlwaysRebuild() ||
3195 PointeeType != TL.getPointeeLoc().getType()) {
3196 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003197 TL.getSigilLoc());
3198 if (Result.isNull())
3199 return QualType();
3200 }
3201
Douglas Gregor049211a2010-04-22 16:50:51 +00003202 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003203 NewT.setSigilLoc(TL.getSigilLoc());
3204 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003205}
3206
John McCall70dd5f62009-10-30 00:06:24 +00003207/// Transforms a reference type. Note that somewhat paradoxically we
3208/// don't care whether the type itself is an l-value type or an r-value
3209/// type; we only care if the type was *written* as an l-value type
3210/// or an r-value type.
3211template<typename Derived>
3212QualType
3213TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003214 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003215 const ReferenceType *T = TL.getTypePtr();
3216
3217 // Note that this works with the pointee-as-written.
3218 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3219 if (PointeeType.isNull())
3220 return QualType();
3221
3222 QualType Result = TL.getType();
3223 if (getDerived().AlwaysRebuild() ||
3224 PointeeType != T->getPointeeTypeAsWritten()) {
3225 Result = getDerived().RebuildReferenceType(PointeeType,
3226 T->isSpelledAsLValue(),
3227 TL.getSigilLoc());
3228 if (Result.isNull())
3229 return QualType();
3230 }
3231
3232 // r-value references can be rebuilt as l-value references.
3233 ReferenceTypeLoc NewTL;
3234 if (isa<LValueReferenceType>(Result))
3235 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3236 else
3237 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3238 NewTL.setSigilLoc(TL.getSigilLoc());
3239
3240 return Result;
3241}
3242
Mike Stump11289f42009-09-09 15:08:12 +00003243template<typename Derived>
3244QualType
John McCall550e0c22009-10-21 00:40:46 +00003245TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003246 LValueReferenceTypeLoc TL) {
3247 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248}
3249
Mike Stump11289f42009-09-09 15:08:12 +00003250template<typename Derived>
3251QualType
John McCall550e0c22009-10-21 00:40:46 +00003252TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003253 RValueReferenceTypeLoc TL) {
3254 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255}
Mike Stump11289f42009-09-09 15:08:12 +00003256
Douglas Gregord6ff3322009-08-04 16:50:30 +00003257template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003258QualType
John McCall550e0c22009-10-21 00:40:46 +00003259TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003260 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003261 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003262
3263 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003264 if (PointeeType.isNull())
3265 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003266
John McCall550e0c22009-10-21 00:40:46 +00003267 // TODO: preserve source information for this.
3268 QualType ClassType
3269 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003270 if (ClassType.isNull())
3271 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003272
John McCall550e0c22009-10-21 00:40:46 +00003273 QualType Result = TL.getType();
3274 if (getDerived().AlwaysRebuild() ||
3275 PointeeType != T->getPointeeType() ||
3276 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003277 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3278 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003279 if (Result.isNull())
3280 return QualType();
3281 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282
John McCall550e0c22009-10-21 00:40:46 +00003283 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3284 NewTL.setSigilLoc(TL.getSigilLoc());
3285
3286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003287}
3288
Mike Stump11289f42009-09-09 15:08:12 +00003289template<typename Derived>
3290QualType
John McCall550e0c22009-10-21 00:40:46 +00003291TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003292 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003293 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003294 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003295 if (ElementType.isNull())
3296 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003297
John McCall550e0c22009-10-21 00:40:46 +00003298 QualType Result = TL.getType();
3299 if (getDerived().AlwaysRebuild() ||
3300 ElementType != T->getElementType()) {
3301 Result = getDerived().RebuildConstantArrayType(ElementType,
3302 T->getSizeModifier(),
3303 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003304 T->getIndexTypeCVRQualifiers(),
3305 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003306 if (Result.isNull())
3307 return QualType();
3308 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003309
John McCall550e0c22009-10-21 00:40:46 +00003310 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3311 NewTL.setLBracketLoc(TL.getLBracketLoc());
3312 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003313
John McCall550e0c22009-10-21 00:40:46 +00003314 Expr *Size = TL.getSizeExpr();
3315 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003316 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003317 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3318 }
3319 NewTL.setSizeExpr(Size);
3320
3321 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322}
Mike Stump11289f42009-09-09 15:08:12 +00003323
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003326 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003327 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003328 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003329 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003330 if (ElementType.isNull())
3331 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003332
John McCall550e0c22009-10-21 00:40:46 +00003333 QualType Result = TL.getType();
3334 if (getDerived().AlwaysRebuild() ||
3335 ElementType != T->getElementType()) {
3336 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003337 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003338 T->getIndexTypeCVRQualifiers(),
3339 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003340 if (Result.isNull())
3341 return QualType();
3342 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003343
John McCall550e0c22009-10-21 00:40:46 +00003344 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3345 NewTL.setLBracketLoc(TL.getLBracketLoc());
3346 NewTL.setRBracketLoc(TL.getRBracketLoc());
3347 NewTL.setSizeExpr(0);
3348
3349 return Result;
3350}
3351
3352template<typename Derived>
3353QualType
3354TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003355 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003356 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003357 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3358 if (ElementType.isNull())
3359 return QualType();
3360
3361 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003362 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003363
John McCalldadc5752010-08-24 06:29:42 +00003364 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003365 = getDerived().TransformExpr(T->getSizeExpr());
3366 if (SizeResult.isInvalid())
3367 return QualType();
3368
John McCallb268a282010-08-23 23:25:46 +00003369 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003370
3371 QualType Result = TL.getType();
3372 if (getDerived().AlwaysRebuild() ||
3373 ElementType != T->getElementType() ||
3374 Size != T->getSizeExpr()) {
3375 Result = getDerived().RebuildVariableArrayType(ElementType,
3376 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003377 Size,
John McCall550e0c22009-10-21 00:40:46 +00003378 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003379 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003380 if (Result.isNull())
3381 return QualType();
3382 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003383
John McCall550e0c22009-10-21 00:40:46 +00003384 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3385 NewTL.setLBracketLoc(TL.getLBracketLoc());
3386 NewTL.setRBracketLoc(TL.getRBracketLoc());
3387 NewTL.setSizeExpr(Size);
3388
3389 return Result;
3390}
3391
3392template<typename Derived>
3393QualType
3394TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003395 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003396 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003397 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3398 if (ElementType.isNull())
3399 return QualType();
3400
3401 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003402 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003403
John McCall33ddac02011-01-19 10:06:00 +00003404 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3405 Expr *origSize = TL.getSizeExpr();
3406 if (!origSize) origSize = T->getSizeExpr();
3407
3408 ExprResult sizeResult
3409 = getDerived().TransformExpr(origSize);
3410 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003411 return QualType();
3412
John McCall33ddac02011-01-19 10:06:00 +00003413 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003414
3415 QualType Result = TL.getType();
3416 if (getDerived().AlwaysRebuild() ||
3417 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003418 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003419 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3420 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003421 size,
John McCall550e0c22009-10-21 00:40:46 +00003422 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003423 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003424 if (Result.isNull())
3425 return QualType();
3426 }
John McCall550e0c22009-10-21 00:40:46 +00003427
3428 // We might have any sort of array type now, but fortunately they
3429 // all have the same location layout.
3430 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3431 NewTL.setLBracketLoc(TL.getLBracketLoc());
3432 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003433 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003434
3435 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003436}
Mike Stump11289f42009-09-09 15:08:12 +00003437
3438template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003439QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003440 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003441 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003442 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003443
3444 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003445 QualType ElementType = getDerived().TransformType(T->getElementType());
3446 if (ElementType.isNull())
3447 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregore922c772009-08-04 22:27:00 +00003449 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003450 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003451
John McCalldadc5752010-08-24 06:29:42 +00003452 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453 if (Size.isInvalid())
3454 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003455
John McCall550e0c22009-10-21 00:40:46 +00003456 QualType Result = TL.getType();
3457 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003458 ElementType != T->getElementType() ||
3459 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003460 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003461 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003462 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003463 if (Result.isNull())
3464 return QualType();
3465 }
John McCall550e0c22009-10-21 00:40:46 +00003466
3467 // Result might be dependent or not.
3468 if (isa<DependentSizedExtVectorType>(Result)) {
3469 DependentSizedExtVectorTypeLoc NewTL
3470 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3471 NewTL.setNameLoc(TL.getNameLoc());
3472 } else {
3473 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3474 NewTL.setNameLoc(TL.getNameLoc());
3475 }
3476
3477 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003478}
Mike Stump11289f42009-09-09 15:08:12 +00003479
3480template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003481QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003482 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003483 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003484 QualType ElementType = getDerived().TransformType(T->getElementType());
3485 if (ElementType.isNull())
3486 return QualType();
3487
John McCall550e0c22009-10-21 00:40:46 +00003488 QualType Result = TL.getType();
3489 if (getDerived().AlwaysRebuild() ||
3490 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003491 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003492 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003493 if (Result.isNull())
3494 return QualType();
3495 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003496
John McCall550e0c22009-10-21 00:40:46 +00003497 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3498 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003499
John McCall550e0c22009-10-21 00:40:46 +00003500 return Result;
3501}
3502
3503template<typename Derived>
3504QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003505 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003506 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003507 QualType ElementType = getDerived().TransformType(T->getElementType());
3508 if (ElementType.isNull())
3509 return QualType();
3510
3511 QualType Result = TL.getType();
3512 if (getDerived().AlwaysRebuild() ||
3513 ElementType != T->getElementType()) {
3514 Result = getDerived().RebuildExtVectorType(ElementType,
3515 T->getNumElements(),
3516 /*FIXME*/ SourceLocation());
3517 if (Result.isNull())
3518 return QualType();
3519 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003520
John McCall550e0c22009-10-21 00:40:46 +00003521 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3522 NewTL.setNameLoc(TL.getNameLoc());
3523
3524 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003525}
Mike Stump11289f42009-09-09 15:08:12 +00003526
3527template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003528ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003529TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3530 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003531 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003532 TypeSourceInfo *NewDI = 0;
3533
3534 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3535 // If we're substituting into a pack expansion type and we know the
3536 TypeLoc OldTL = OldDI->getTypeLoc();
3537 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3538
3539 TypeLocBuilder TLB;
3540 TypeLoc NewTL = OldDI->getTypeLoc();
3541 TLB.reserve(NewTL.getFullDataSize());
3542
3543 QualType Result = getDerived().TransformType(TLB,
3544 OldExpansionTL.getPatternLoc());
3545 if (Result.isNull())
3546 return 0;
3547
3548 Result = RebuildPackExpansionType(Result,
3549 OldExpansionTL.getPatternLoc().getSourceRange(),
3550 OldExpansionTL.getEllipsisLoc(),
3551 NumExpansions);
3552 if (Result.isNull())
3553 return 0;
3554
3555 PackExpansionTypeLoc NewExpansionTL
3556 = TLB.push<PackExpansionTypeLoc>(Result);
3557 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3558 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3559 } else
3560 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003561 if (!NewDI)
3562 return 0;
3563
3564 if (NewDI == OldDI)
3565 return OldParm;
3566 else
3567 return ParmVarDecl::Create(SemaRef.Context,
3568 OldParm->getDeclContext(),
3569 OldParm->getLocation(),
3570 OldParm->getIdentifier(),
3571 NewDI->getType(),
3572 NewDI,
3573 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003574 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003575 /* DefArg */ NULL);
3576}
3577
3578template<typename Derived>
3579bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003580 TransformFunctionTypeParams(SourceLocation Loc,
3581 ParmVarDecl **Params, unsigned NumParams,
3582 const QualType *ParamTypes,
3583 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3584 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3585 for (unsigned i = 0; i != NumParams; ++i) {
3586 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003587 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003588 if (OldParm->isParameterPack()) {
3589 // We have a function parameter pack that may need to be expanded.
3590 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003591
Douglas Gregor5499af42011-01-05 23:12:31 +00003592 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003593 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3594 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3595 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3596 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003597
3598 // Determine whether we should expand the parameter packs.
3599 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003600 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003601 llvm::Optional<unsigned> OrigNumExpansions
3602 = ExpansionTL.getTypePtr()->getNumExpansions();
3603 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003604 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3605 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003606 Unexpanded.data(),
3607 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003608 ShouldExpand,
3609 RetainExpansion,
3610 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003611 return true;
3612 }
3613
3614 if (ShouldExpand) {
3615 // Expand the function parameter pack into multiple, separate
3616 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003617 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003618 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003619 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3620 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003621 = getDerived().TransformFunctionTypeParam(OldParm,
3622 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003623 if (!NewParm)
3624 return true;
3625
Douglas Gregordd472162011-01-07 00:20:55 +00003626 OutParamTypes.push_back(NewParm->getType());
3627 if (PVars)
3628 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003629 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003630
3631 // If we're supposed to retain a pack expansion, do so by temporarily
3632 // forgetting the partially-substituted parameter pack.
3633 if (RetainExpansion) {
3634 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3635 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003636 = getDerived().TransformFunctionTypeParam(OldParm,
3637 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003638 if (!NewParm)
3639 return true;
3640
3641 OutParamTypes.push_back(NewParm->getType());
3642 if (PVars)
3643 PVars->push_back(NewParm);
3644 }
3645
Douglas Gregor5499af42011-01-05 23:12:31 +00003646 // We're done with the pack expansion.
3647 continue;
3648 }
3649
3650 // We'll substitute the parameter now without expanding the pack
3651 // expansion.
3652 }
3653
3654 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003655 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3656 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003657 if (!NewParm)
3658 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003659
Douglas Gregordd472162011-01-07 00:20:55 +00003660 OutParamTypes.push_back(NewParm->getType());
3661 if (PVars)
3662 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003663 continue;
3664 }
John McCall58f10c32010-03-11 09:03:00 +00003665
3666 // Deal with the possibility that we don't have a parameter
3667 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003668 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003669 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003670 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003671 if (const PackExpansionType *Expansion
3672 = dyn_cast<PackExpansionType>(OldType)) {
3673 // We have a function parameter pack that may need to be expanded.
3674 QualType Pattern = Expansion->getPattern();
3675 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3676 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3677
3678 // Determine whether we should expand the parameter packs.
3679 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003680 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003681 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003682 Unexpanded.data(),
3683 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003684 ShouldExpand,
3685 RetainExpansion,
3686 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003687 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003688 }
3689
3690 if (ShouldExpand) {
3691 // Expand the function parameter pack into multiple, separate
3692 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003693 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003694 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3695 QualType NewType = getDerived().TransformType(Pattern);
3696 if (NewType.isNull())
3697 return true;
John McCall58f10c32010-03-11 09:03:00 +00003698
Douglas Gregordd472162011-01-07 00:20:55 +00003699 OutParamTypes.push_back(NewType);
3700 if (PVars)
3701 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003702 }
3703
3704 // We're done with the pack expansion.
3705 continue;
3706 }
3707
Douglas Gregor48d24112011-01-10 20:53:55 +00003708 // If we're supposed to retain a pack expansion, do so by temporarily
3709 // forgetting the partially-substituted parameter pack.
3710 if (RetainExpansion) {
3711 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3712 QualType NewType = getDerived().TransformType(Pattern);
3713 if (NewType.isNull())
3714 return true;
3715
3716 OutParamTypes.push_back(NewType);
3717 if (PVars)
3718 PVars->push_back(0);
3719 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003720
Douglas Gregor5499af42011-01-05 23:12:31 +00003721 // We'll substitute the parameter now without expanding the pack
3722 // expansion.
3723 OldType = Expansion->getPattern();
3724 IsPackExpansion = true;
3725 }
3726
3727 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3728 QualType NewType = getDerived().TransformType(OldType);
3729 if (NewType.isNull())
3730 return true;
3731
3732 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003733 NewType = getSema().Context.getPackExpansionType(NewType,
3734 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003735
Douglas Gregordd472162011-01-07 00:20:55 +00003736 OutParamTypes.push_back(NewType);
3737 if (PVars)
3738 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003739 }
3740
3741 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003742 }
John McCall58f10c32010-03-11 09:03:00 +00003743
3744template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003745QualType
John McCall550e0c22009-10-21 00:40:46 +00003746TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003747 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003748 // Transform the parameters and return type.
3749 //
3750 // We instantiate in source order, with the return type first followed by
3751 // the parameters, because users tend to expect this (even if they shouldn't
3752 // rely on it!).
3753 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003754 // When the function has a trailing return type, we instantiate the
3755 // parameters before the return type, since the return type can then refer
3756 // to the parameters themselves (via decltype, sizeof, etc.).
3757 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003758 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003759 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003760 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003761
Douglas Gregor7fb25412010-10-01 18:44:50 +00003762 QualType ResultType;
3763
3764 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003765 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3766 TL.getParmArray(),
3767 TL.getNumArgs(),
3768 TL.getTypePtr()->arg_type_begin(),
3769 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003770 return QualType();
3771
3772 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3773 if (ResultType.isNull())
3774 return QualType();
3775 }
3776 else {
3777 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3778 if (ResultType.isNull())
3779 return QualType();
3780
Douglas Gregordd472162011-01-07 00:20:55 +00003781 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3782 TL.getParmArray(),
3783 TL.getNumArgs(),
3784 TL.getTypePtr()->arg_type_begin(),
3785 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003786 return QualType();
3787 }
3788
John McCall550e0c22009-10-21 00:40:46 +00003789 QualType Result = TL.getType();
3790 if (getDerived().AlwaysRebuild() ||
3791 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003792 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003793 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3794 Result = getDerived().RebuildFunctionProtoType(ResultType,
3795 ParamTypes.data(),
3796 ParamTypes.size(),
3797 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003798 T->getTypeQuals(),
3799 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003800 if (Result.isNull())
3801 return QualType();
3802 }
Mike Stump11289f42009-09-09 15:08:12 +00003803
John McCall550e0c22009-10-21 00:40:46 +00003804 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3805 NewTL.setLParenLoc(TL.getLParenLoc());
3806 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003807 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003808 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3809 NewTL.setArg(i, ParamDecls[i]);
3810
3811 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812}
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregord6ff3322009-08-04 16:50:30 +00003814template<typename Derived>
3815QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003816 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003817 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003818 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003819 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3820 if (ResultType.isNull())
3821 return QualType();
3822
3823 QualType Result = TL.getType();
3824 if (getDerived().AlwaysRebuild() ||
3825 ResultType != T->getResultType())
3826 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3827
3828 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3829 NewTL.setLParenLoc(TL.getLParenLoc());
3830 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003831 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003832
3833 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003834}
Mike Stump11289f42009-09-09 15:08:12 +00003835
John McCallb96ec562009-12-04 22:46:56 +00003836template<typename Derived> QualType
3837TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003838 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003839 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003840 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003841 if (!D)
3842 return QualType();
3843
3844 QualType Result = TL.getType();
3845 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3846 Result = getDerived().RebuildUnresolvedUsingType(D);
3847 if (Result.isNull())
3848 return QualType();
3849 }
3850
3851 // We might get an arbitrary type spec type back. We should at
3852 // least always get a type spec type, though.
3853 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3854 NewTL.setNameLoc(TL.getNameLoc());
3855
3856 return Result;
3857}
3858
Douglas Gregord6ff3322009-08-04 16:50:30 +00003859template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003860QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003861 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003862 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003863 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003864 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3865 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003866 if (!Typedef)
3867 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003868
John McCall550e0c22009-10-21 00:40:46 +00003869 QualType Result = TL.getType();
3870 if (getDerived().AlwaysRebuild() ||
3871 Typedef != T->getDecl()) {
3872 Result = getDerived().RebuildTypedefType(Typedef);
3873 if (Result.isNull())
3874 return QualType();
3875 }
Mike Stump11289f42009-09-09 15:08:12 +00003876
John McCall550e0c22009-10-21 00:40:46 +00003877 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3878 NewTL.setNameLoc(TL.getNameLoc());
3879
3880 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003881}
Mike Stump11289f42009-09-09 15:08:12 +00003882
Douglas Gregord6ff3322009-08-04 16:50:30 +00003883template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003884QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003885 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003886 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003887 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003888
John McCalldadc5752010-08-24 06:29:42 +00003889 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003890 if (E.isInvalid())
3891 return QualType();
3892
John McCall550e0c22009-10-21 00:40:46 +00003893 QualType Result = TL.getType();
3894 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003895 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003896 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003897 if (Result.isNull())
3898 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003899 }
John McCall550e0c22009-10-21 00:40:46 +00003900 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003901
John McCall550e0c22009-10-21 00:40:46 +00003902 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003903 NewTL.setTypeofLoc(TL.getTypeofLoc());
3904 NewTL.setLParenLoc(TL.getLParenLoc());
3905 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003906
3907 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003908}
Mike Stump11289f42009-09-09 15:08:12 +00003909
3910template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003911QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003912 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003913 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3914 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3915 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003916 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003917
John McCall550e0c22009-10-21 00:40:46 +00003918 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003919 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3920 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003921 if (Result.isNull())
3922 return QualType();
3923 }
Mike Stump11289f42009-09-09 15:08:12 +00003924
John McCall550e0c22009-10-21 00:40:46 +00003925 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003926 NewTL.setTypeofLoc(TL.getTypeofLoc());
3927 NewTL.setLParenLoc(TL.getLParenLoc());
3928 NewTL.setRParenLoc(TL.getRParenLoc());
3929 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003930
3931 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003932}
Mike Stump11289f42009-09-09 15:08:12 +00003933
3934template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003935QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003936 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003937 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003938
Douglas Gregore922c772009-08-04 22:27:00 +00003939 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003940 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003941
John McCalldadc5752010-08-24 06:29:42 +00003942 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003943 if (E.isInvalid())
3944 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003945
John McCall550e0c22009-10-21 00:40:46 +00003946 QualType Result = TL.getType();
3947 if (getDerived().AlwaysRebuild() ||
3948 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003949 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003950 if (Result.isNull())
3951 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003952 }
John McCall550e0c22009-10-21 00:40:46 +00003953 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003954
John McCall550e0c22009-10-21 00:40:46 +00003955 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3956 NewTL.setNameLoc(TL.getNameLoc());
3957
3958 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003959}
3960
3961template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003962QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003963 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003964 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003965 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003966 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3967 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003968 if (!Record)
3969 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003970
John McCall550e0c22009-10-21 00:40:46 +00003971 QualType Result = TL.getType();
3972 if (getDerived().AlwaysRebuild() ||
3973 Record != T->getDecl()) {
3974 Result = getDerived().RebuildRecordType(Record);
3975 if (Result.isNull())
3976 return QualType();
3977 }
Mike Stump11289f42009-09-09 15:08:12 +00003978
John McCall550e0c22009-10-21 00:40:46 +00003979 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3980 NewTL.setNameLoc(TL.getNameLoc());
3981
3982 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003983}
Mike Stump11289f42009-09-09 15:08:12 +00003984
3985template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003986QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003987 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003988 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003990 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3991 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003992 if (!Enum)
3993 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003994
John McCall550e0c22009-10-21 00:40:46 +00003995 QualType Result = TL.getType();
3996 if (getDerived().AlwaysRebuild() ||
3997 Enum != T->getDecl()) {
3998 Result = getDerived().RebuildEnumType(Enum);
3999 if (Result.isNull())
4000 return QualType();
4001 }
Mike Stump11289f42009-09-09 15:08:12 +00004002
John McCall550e0c22009-10-21 00:40:46 +00004003 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4004 NewTL.setNameLoc(TL.getNameLoc());
4005
4006 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007}
John McCallfcc33b02009-09-05 00:15:47 +00004008
John McCalle78aac42010-03-10 03:28:59 +00004009template<typename Derived>
4010QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4011 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004012 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004013 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4014 TL.getTypePtr()->getDecl());
4015 if (!D) return QualType();
4016
4017 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4018 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4019 return T;
4020}
4021
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022template<typename Derived>
4023QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004024 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004025 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004026 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004027}
4028
Mike Stump11289f42009-09-09 15:08:12 +00004029template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004030QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004031 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004032 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004033 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004034}
4035
4036template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004037QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4038 TypeLocBuilder &TLB,
4039 SubstTemplateTypeParmPackTypeLoc TL) {
4040 return TransformTypeSpecType(TLB, TL);
4041}
4042
4043template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004044QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004045 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004046 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004047 const TemplateSpecializationType *T = TL.getTypePtr();
4048
Mike Stump11289f42009-09-09 15:08:12 +00004049 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004050 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004051 if (Template.isNull())
4052 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004053
John McCall31f82722010-11-12 08:19:04 +00004054 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4055}
4056
Douglas Gregorfe921a72010-12-20 23:36:19 +00004057namespace {
4058 /// \brief Simple iterator that traverses the template arguments in a
4059 /// container that provides a \c getArgLoc() member function.
4060 ///
4061 /// This iterator is intended to be used with the iterator form of
4062 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4063 template<typename ArgLocContainer>
4064 class TemplateArgumentLocContainerIterator {
4065 ArgLocContainer *Container;
4066 unsigned Index;
4067
4068 public:
4069 typedef TemplateArgumentLoc value_type;
4070 typedef TemplateArgumentLoc reference;
4071 typedef int difference_type;
4072 typedef std::input_iterator_tag iterator_category;
4073
4074 class pointer {
4075 TemplateArgumentLoc Arg;
4076
4077 public:
4078 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4079
4080 const TemplateArgumentLoc *operator->() const {
4081 return &Arg;
4082 }
4083 };
4084
4085
4086 TemplateArgumentLocContainerIterator() {}
4087
4088 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4089 unsigned Index)
4090 : Container(&Container), Index(Index) { }
4091
4092 TemplateArgumentLocContainerIterator &operator++() {
4093 ++Index;
4094 return *this;
4095 }
4096
4097 TemplateArgumentLocContainerIterator operator++(int) {
4098 TemplateArgumentLocContainerIterator Old(*this);
4099 ++(*this);
4100 return Old;
4101 }
4102
4103 TemplateArgumentLoc operator*() const {
4104 return Container->getArgLoc(Index);
4105 }
4106
4107 pointer operator->() const {
4108 return pointer(Container->getArgLoc(Index));
4109 }
4110
4111 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004112 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004113 return X.Container == Y.Container && X.Index == Y.Index;
4114 }
4115
4116 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004117 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004118 return !(X == Y);
4119 }
4120 };
4121}
4122
4123
John McCall31f82722010-11-12 08:19:04 +00004124template <typename Derived>
4125QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4126 TypeLocBuilder &TLB,
4127 TemplateSpecializationTypeLoc TL,
4128 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004129 TemplateArgumentListInfo NewTemplateArgs;
4130 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4131 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004132 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4133 ArgIterator;
4134 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4135 ArgIterator(TL, TL.getNumArgs()),
4136 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004138
John McCall0ad16662009-10-29 08:12:44 +00004139 // FIXME: maybe don't rebuild if all the template arguments are the same.
4140
4141 QualType Result =
4142 getDerived().RebuildTemplateSpecializationType(Template,
4143 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004144 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004145
4146 if (!Result.isNull()) {
4147 TemplateSpecializationTypeLoc NewTL
4148 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4149 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4150 NewTL.setLAngleLoc(TL.getLAngleLoc());
4151 NewTL.setRAngleLoc(TL.getRAngleLoc());
4152 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4153 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004154 }
Mike Stump11289f42009-09-09 15:08:12 +00004155
John McCall0ad16662009-10-29 08:12:44 +00004156 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004157}
Mike Stump11289f42009-09-09 15:08:12 +00004158
4159template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004160QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004161TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004162 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004163 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004164
4165 NestedNameSpecifier *NNS = 0;
4166 // NOTE: the qualifier in an ElaboratedType is optional.
4167 if (T->getQualifier() != 0) {
4168 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004169 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004170 if (!NNS)
4171 return QualType();
4172 }
Mike Stump11289f42009-09-09 15:08:12 +00004173
John McCall31f82722010-11-12 08:19:04 +00004174 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4175 if (NamedT.isNull())
4176 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004177
John McCall550e0c22009-10-21 00:40:46 +00004178 QualType Result = TL.getType();
4179 if (getDerived().AlwaysRebuild() ||
4180 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004181 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004182 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4183 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004184 if (Result.isNull())
4185 return QualType();
4186 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004187
Abramo Bagnara6150c882010-05-11 21:36:43 +00004188 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004189 NewTL.setKeywordLoc(TL.getKeywordLoc());
4190 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004191
4192 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004193}
Mike Stump11289f42009-09-09 15:08:12 +00004194
4195template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004196QualType TreeTransform<Derived>::TransformAttributedType(
4197 TypeLocBuilder &TLB,
4198 AttributedTypeLoc TL) {
4199 const AttributedType *oldType = TL.getTypePtr();
4200 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4201 if (modifiedType.isNull())
4202 return QualType();
4203
4204 QualType result = TL.getType();
4205
4206 // FIXME: dependent operand expressions?
4207 if (getDerived().AlwaysRebuild() ||
4208 modifiedType != oldType->getModifiedType()) {
4209 // TODO: this is really lame; we should really be rebuilding the
4210 // equivalent type from first principles.
4211 QualType equivalentType
4212 = getDerived().TransformType(oldType->getEquivalentType());
4213 if (equivalentType.isNull())
4214 return QualType();
4215 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4216 modifiedType,
4217 equivalentType);
4218 }
4219
4220 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4221 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4222 if (TL.hasAttrOperand())
4223 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4224 if (TL.hasAttrExprOperand())
4225 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4226 else if (TL.hasAttrEnumOperand())
4227 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4228
4229 return result;
4230}
4231
4232template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004233QualType
4234TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4235 ParenTypeLoc TL) {
4236 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4237 if (Inner.isNull())
4238 return QualType();
4239
4240 QualType Result = TL.getType();
4241 if (getDerived().AlwaysRebuild() ||
4242 Inner != TL.getInnerLoc().getType()) {
4243 Result = getDerived().RebuildParenType(Inner);
4244 if (Result.isNull())
4245 return QualType();
4246 }
4247
4248 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4249 NewTL.setLParenLoc(TL.getLParenLoc());
4250 NewTL.setRParenLoc(TL.getRParenLoc());
4251 return Result;
4252}
4253
4254template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004255QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004256 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004257 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004258
Douglas Gregord6ff3322009-08-04 16:50:30 +00004259 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004260 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004261 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004262 if (!NNS)
4263 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004264
John McCallc392f372010-06-11 00:33:02 +00004265 QualType Result
4266 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4267 T->getIdentifier(),
4268 TL.getKeywordLoc(),
4269 TL.getQualifierRange(),
4270 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004271 if (Result.isNull())
4272 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004273
Abramo Bagnarad7548482010-05-19 21:37:53 +00004274 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4275 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004276 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4277
Abramo Bagnarad7548482010-05-19 21:37:53 +00004278 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4279 NewTL.setKeywordLoc(TL.getKeywordLoc());
4280 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004281 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004282 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4283 NewTL.setKeywordLoc(TL.getKeywordLoc());
4284 NewTL.setQualifierRange(TL.getQualifierRange());
4285 NewTL.setNameLoc(TL.getNameLoc());
4286 }
John McCall550e0c22009-10-21 00:40:46 +00004287 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004288}
Mike Stump11289f42009-09-09 15:08:12 +00004289
Douglas Gregord6ff3322009-08-04 16:50:30 +00004290template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004291QualType TreeTransform<Derived>::
4292 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004293 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004294 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004295
4296 NestedNameSpecifier *NNS
4297 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004298 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004299 if (!NNS)
4300 return QualType();
4301
John McCall31f82722010-11-12 08:19:04 +00004302 return getDerived()
4303 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4304}
4305
4306template<typename Derived>
4307QualType TreeTransform<Derived>::
4308 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4309 DependentTemplateSpecializationTypeLoc TL,
4310 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004311 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004312
John McCallc392f372010-06-11 00:33:02 +00004313 TemplateArgumentListInfo NewTemplateArgs;
4314 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4315 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004316
4317 typedef TemplateArgumentLocContainerIterator<
4318 DependentTemplateSpecializationTypeLoc> ArgIterator;
4319 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4320 ArgIterator(TL, TL.getNumArgs()),
4321 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004322 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004323
Douglas Gregora5614c52010-09-08 23:56:00 +00004324 QualType Result
4325 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4326 NNS,
4327 TL.getQualifierRange(),
4328 T->getIdentifier(),
4329 TL.getNameLoc(),
4330 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004331 if (Result.isNull())
4332 return QualType();
4333
4334 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4335 QualType NamedT = ElabT->getNamedType();
4336
4337 // Copy information relevant to the template specialization.
4338 TemplateSpecializationTypeLoc NamedTL
4339 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4340 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4341 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4342 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4343 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4344
4345 // Copy information relevant to the elaborated type.
4346 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4347 NewTL.setKeywordLoc(TL.getKeywordLoc());
4348 NewTL.setQualifierRange(TL.getQualifierRange());
4349 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004350 TypeLoc NewTL(Result, TL.getOpaqueData());
4351 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004352 }
4353 return Result;
4354}
4355
4356template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004357QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4358 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004359 QualType Pattern
4360 = getDerived().TransformType(TLB, TL.getPatternLoc());
4361 if (Pattern.isNull())
4362 return QualType();
4363
4364 QualType Result = TL.getType();
4365 if (getDerived().AlwaysRebuild() ||
4366 Pattern != TL.getPatternLoc().getType()) {
4367 Result = getDerived().RebuildPackExpansionType(Pattern,
4368 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004369 TL.getEllipsisLoc(),
4370 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004371 if (Result.isNull())
4372 return QualType();
4373 }
4374
4375 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4376 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4377 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004378}
4379
4380template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004381QualType
4382TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004383 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004384 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004385 TLB.pushFullCopy(TL);
4386 return TL.getType();
4387}
4388
4389template<typename Derived>
4390QualType
4391TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004392 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004393 // ObjCObjectType is never dependent.
4394 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004395 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004396}
Mike Stump11289f42009-09-09 15:08:12 +00004397
4398template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004399QualType
4400TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004401 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004402 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004403 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004404 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004405}
4406
Douglas Gregord6ff3322009-08-04 16:50:30 +00004407//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004408// Statement transformation
4409//===----------------------------------------------------------------------===//
4410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004411StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004412TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004413 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004414}
4415
4416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004417StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004418TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4419 return getDerived().TransformCompoundStmt(S, false);
4420}
4421
4422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004423StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004424TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004425 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004426 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004427 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004428 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004429 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4430 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004431 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004432 if (Result.isInvalid()) {
4433 // Immediately fail if this was a DeclStmt, since it's very
4434 // likely that this will cause problems for future statements.
4435 if (isa<DeclStmt>(*B))
4436 return StmtError();
4437
4438 // Otherwise, just keep processing substatements and fail later.
4439 SubStmtInvalid = true;
4440 continue;
4441 }
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregorebe10102009-08-20 07:17:43 +00004443 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4444 Statements.push_back(Result.takeAs<Stmt>());
4445 }
Mike Stump11289f42009-09-09 15:08:12 +00004446
John McCall1ababa62010-08-27 19:56:05 +00004447 if (SubStmtInvalid)
4448 return StmtError();
4449
Douglas Gregorebe10102009-08-20 07:17:43 +00004450 if (!getDerived().AlwaysRebuild() &&
4451 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004452 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004453
4454 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4455 move_arg(Statements),
4456 S->getRBracLoc(),
4457 IsStmtExpr);
4458}
Mike Stump11289f42009-09-09 15:08:12 +00004459
Douglas Gregorebe10102009-08-20 07:17:43 +00004460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004461StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004462TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004463 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004464 {
4465 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004466 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004467
Eli Friedman06577382009-11-19 03:14:00 +00004468 // Transform the left-hand case value.
4469 LHS = getDerived().TransformExpr(S->getLHS());
4470 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004471 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004472
Eli Friedman06577382009-11-19 03:14:00 +00004473 // Transform the right-hand case value (for the GNU case-range extension).
4474 RHS = getDerived().TransformExpr(S->getRHS());
4475 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004476 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004477 }
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregorebe10102009-08-20 07:17:43 +00004479 // Build the case statement.
4480 // Case statements are always rebuilt so that they will attached to their
4481 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004482 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004483 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004484 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004485 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004486 S->getColonLoc());
4487 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004488 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregorebe10102009-08-20 07:17:43 +00004490 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004491 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004492 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004493 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregorebe10102009-08-20 07:17:43 +00004495 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004496 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004497}
4498
4499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004500StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004501TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004502 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004503 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004504 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004505 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004506
Douglas Gregorebe10102009-08-20 07:17:43 +00004507 // Default statements are always rebuilt
4508 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004509 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004510}
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregorebe10102009-08-20 07:17:43 +00004512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004513StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004514TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004515 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004516 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004517 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregorebe10102009-08-20 07:17:43 +00004519 // FIXME: Pass the real colon location in.
4520 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4521 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004522 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004523}
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregorebe10102009-08-20 07:17:43 +00004525template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004526StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004527TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004528 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004529 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004530 VarDecl *ConditionVar = 0;
4531 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004532 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004533 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004534 getDerived().TransformDefinition(
4535 S->getConditionVariable()->getLocation(),
4536 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004537 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004538 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004539 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004540 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004541
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004542 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004543 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004544
4545 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004546 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004547 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4548 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004549 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004550 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004551
John McCallb268a282010-08-23 23:25:46 +00004552 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004553 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004554 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004555
John McCallb268a282010-08-23 23:25:46 +00004556 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4557 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004558 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004559
Douglas Gregorebe10102009-08-20 07:17:43 +00004560 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004561 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004562 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004563 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregorebe10102009-08-20 07:17:43 +00004565 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004566 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004567 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregorebe10102009-08-20 07:17:43 +00004570 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004571 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004572 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004573 Then.get() == S->getThen() &&
4574 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004575 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004576
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004577 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004578 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004579 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004580}
4581
4582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004583StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004584TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004585 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004586 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004587 VarDecl *ConditionVar = 0;
4588 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004589 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004590 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004591 getDerived().TransformDefinition(
4592 S->getConditionVariable()->getLocation(),
4593 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004594 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004595 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004596 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004597 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004598
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004599 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004600 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004601 }
Mike Stump11289f42009-09-09 15:08:12 +00004602
Douglas Gregorebe10102009-08-20 07:17:43 +00004603 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004604 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004605 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004606 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004607 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004608 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004609
Douglas Gregorebe10102009-08-20 07:17:43 +00004610 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004611 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004612 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004613 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004614
Douglas Gregorebe10102009-08-20 07:17:43 +00004615 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004616 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4617 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregorebe10102009-08-20 07:17:43 +00004620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004621StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004622TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004623 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004624 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004625 VarDecl *ConditionVar = 0;
4626 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004627 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004628 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004629 getDerived().TransformDefinition(
4630 S->getConditionVariable()->getLocation(),
4631 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004632 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004633 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004634 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004635 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004636
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004637 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004638 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004639
4640 if (S->getCond()) {
4641 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004642 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4643 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004644 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004645 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004646 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004647 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004648 }
Mike Stump11289f42009-09-09 15:08:12 +00004649
John McCallb268a282010-08-23 23:25:46 +00004650 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4651 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004652 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004653
Douglas Gregorebe10102009-08-20 07:17:43 +00004654 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004655 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004656 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004657 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004658
Douglas Gregorebe10102009-08-20 07:17:43 +00004659 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004660 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004661 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004662 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004663 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004665 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004666 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregorebe10102009-08-20 07:17:43 +00004669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004670StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004671TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004672 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004673 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004674 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004675 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004677 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004678 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004679 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004680 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004681
Douglas Gregorebe10102009-08-20 07:17:43 +00004682 if (!getDerived().AlwaysRebuild() &&
4683 Cond.get() == S->getCond() &&
4684 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004685 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004686
John McCallb268a282010-08-23 23:25:46 +00004687 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4688 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004689 S->getRParenLoc());
4690}
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregorebe10102009-08-20 07:17:43 +00004692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004693StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004694TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004695 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004696 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004697 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004698 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregorebe10102009-08-20 07:17:43 +00004700 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004701 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004702 VarDecl *ConditionVar = 0;
4703 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004704 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004705 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004706 getDerived().TransformDefinition(
4707 S->getConditionVariable()->getLocation(),
4708 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004709 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004710 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004711 } else {
4712 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004713
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004714 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004715 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004716
4717 if (S->getCond()) {
4718 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004719 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4720 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004721 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004722 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004723
John McCallb268a282010-08-23 23:25:46 +00004724 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004725 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004726 }
Mike Stump11289f42009-09-09 15:08:12 +00004727
John McCallb268a282010-08-23 23:25:46 +00004728 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4729 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004730 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004731
Douglas Gregorebe10102009-08-20 07:17:43 +00004732 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004733 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004734 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004735 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004736
John McCallb268a282010-08-23 23:25:46 +00004737 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4738 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004739 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004740
Douglas Gregorebe10102009-08-20 07:17:43 +00004741 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004742 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004743 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004744 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004745
Douglas Gregorebe10102009-08-20 07:17:43 +00004746 if (!getDerived().AlwaysRebuild() &&
4747 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004748 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004749 Inc.get() == S->getInc() &&
4750 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004751 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004752
Douglas Gregorebe10102009-08-20 07:17:43 +00004753 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004754 Init.get(), FullCond, ConditionVar,
4755 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004756}
4757
4758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004759StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004760TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004761 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004762 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004763 S->getLabel());
4764}
4765
4766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004767StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004768TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004769 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004770 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004771 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 if (!getDerived().AlwaysRebuild() &&
4774 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004775 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004776
4777 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004778 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004779}
4780
4781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004782StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004783TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004784 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004785}
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregorebe10102009-08-20 07:17:43 +00004787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004788StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004789TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004790 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004791}
Mike Stump11289f42009-09-09 15:08:12 +00004792
Douglas Gregorebe10102009-08-20 07:17:43 +00004793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004794StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004795TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004796 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004797 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004798 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004799
Mike Stump11289f42009-09-09 15:08:12 +00004800 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004801 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004802 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004803}
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregorebe10102009-08-20 07:17:43 +00004805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004806StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004807TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004808 bool DeclChanged = false;
4809 llvm::SmallVector<Decl *, 4> Decls;
4810 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4811 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004812 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4813 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004814 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004815 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregorebe10102009-08-20 07:17:43 +00004817 if (Transformed != *D)
4818 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 Decls.push_back(Transformed);
4821 }
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004824 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004825
4826 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004827 S->getStartLoc(), S->getEndLoc());
4828}
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregorebe10102009-08-20 07:17:43 +00004830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004831StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004832TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004833 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004834 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004835}
4836
4837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004838StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004839TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004840
John McCall37ad5512010-08-23 06:44:23 +00004841 ASTOwningVector<Expr*> Constraints(getSema());
4842 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004843 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004844
John McCalldadc5752010-08-24 06:29:42 +00004845 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004846 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004847
4848 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004849
Anders Carlssonaaeef072010-01-24 05:50:09 +00004850 // Go through the outputs.
4851 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004852 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004853
Anders Carlssonaaeef072010-01-24 05:50:09 +00004854 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004855 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004856
Anders Carlssonaaeef072010-01-24 05:50:09 +00004857 // Transform the output expr.
4858 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004859 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004860 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004861 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004862
Anders Carlssonaaeef072010-01-24 05:50:09 +00004863 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004864
John McCallb268a282010-08-23 23:25:46 +00004865 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004866 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004867
Anders Carlssonaaeef072010-01-24 05:50:09 +00004868 // Go through the inputs.
4869 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004870 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004871
Anders Carlssonaaeef072010-01-24 05:50:09 +00004872 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004873 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004874
Anders Carlssonaaeef072010-01-24 05:50:09 +00004875 // Transform the input expr.
4876 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004877 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004878 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004879 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004880
Anders Carlssonaaeef072010-01-24 05:50:09 +00004881 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004882
John McCallb268a282010-08-23 23:25:46 +00004883 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004884 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004885
Anders Carlssonaaeef072010-01-24 05:50:09 +00004886 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004887 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004888
4889 // Go through the clobbers.
4890 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004891 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004892
4893 // No need to transform the asm string literal.
4894 AsmString = SemaRef.Owned(S->getAsmString());
4895
4896 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4897 S->isSimple(),
4898 S->isVolatile(),
4899 S->getNumOutputs(),
4900 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004901 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004902 move_arg(Constraints),
4903 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004904 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004905 move_arg(Clobbers),
4906 S->getRParenLoc(),
4907 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004908}
4909
4910
4911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004912StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004913TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004914 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004915 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004916 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004917 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004918
Douglas Gregor96c79492010-04-23 22:50:49 +00004919 // Transform the @catch statements (if present).
4920 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004921 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004922 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004923 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004924 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004925 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004926 if (Catch.get() != S->getCatchStmt(I))
4927 AnyCatchChanged = true;
4928 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004929 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004930
Douglas Gregor306de2f2010-04-22 23:59:56 +00004931 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004932 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004933 if (S->getFinallyStmt()) {
4934 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4935 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004936 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004937 }
4938
4939 // If nothing changed, just retain this statement.
4940 if (!getDerived().AlwaysRebuild() &&
4941 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004942 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004943 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004944 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004945
Douglas Gregor306de2f2010-04-22 23:59:56 +00004946 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004947 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4948 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004949}
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregorebe10102009-08-20 07:17:43 +00004951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004952StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004953TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004954 // Transform the @catch parameter, if there is one.
4955 VarDecl *Var = 0;
4956 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4957 TypeSourceInfo *TSInfo = 0;
4958 if (FromVar->getTypeSourceInfo()) {
4959 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4960 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004961 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004962 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004963
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004964 QualType T;
4965 if (TSInfo)
4966 T = TSInfo->getType();
4967 else {
4968 T = getDerived().TransformType(FromVar->getType());
4969 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004970 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004971 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004972
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004973 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4974 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004975 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004976 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004977
John McCalldadc5752010-08-24 06:29:42 +00004978 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004979 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004980 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004981
4982 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004983 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004984 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004985}
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorebe10102009-08-20 07:17:43 +00004987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004988StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004989TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004990 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004991 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004992 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004993 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004994
Douglas Gregor306de2f2010-04-22 23:59:56 +00004995 // If nothing changed, just retain this statement.
4996 if (!getDerived().AlwaysRebuild() &&
4997 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004998 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004999
5000 // Build a new statement.
5001 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005002 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregorebe10102009-08-20 07:17:43 +00005005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005006StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005007TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005008 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005009 if (S->getThrowExpr()) {
5010 Operand = getDerived().TransformExpr(S->getThrowExpr());
5011 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005012 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005013 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005014
Douglas Gregor2900c162010-04-22 21:44:01 +00005015 if (!getDerived().AlwaysRebuild() &&
5016 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005017 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005018
John McCallb268a282010-08-23 23:25:46 +00005019 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005020}
Mike Stump11289f42009-09-09 15:08:12 +00005021
Douglas Gregorebe10102009-08-20 07:17:43 +00005022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005023StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005024TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005025 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005026 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005027 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005028 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005029 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005030
Douglas Gregor6148de72010-04-22 22:01:21 +00005031 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005032 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005033 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005034 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005035
Douglas Gregor6148de72010-04-22 22:01:21 +00005036 // If nothing change, just retain the current statement.
5037 if (!getDerived().AlwaysRebuild() &&
5038 Object.get() == S->getSynchExpr() &&
5039 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005040 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005041
5042 // Build a new statement.
5043 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005044 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005045}
5046
5047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005048StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005049TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005050 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005051 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005052 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005053 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005055
Douglas Gregorf68a5082010-04-22 23:10:45 +00005056 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005057 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005058 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005059 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005060
Douglas Gregorf68a5082010-04-22 23:10:45 +00005061 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005062 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005063 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005064 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005065
Douglas Gregorf68a5082010-04-22 23:10:45 +00005066 // If nothing changed, just retain this statement.
5067 if (!getDerived().AlwaysRebuild() &&
5068 Element.get() == S->getElement() &&
5069 Collection.get() == S->getCollection() &&
5070 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005071 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005072
Douglas Gregorf68a5082010-04-22 23:10:45 +00005073 // Build a new statement.
5074 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5075 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005076 Element.get(),
5077 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005078 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005079 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005080}
5081
5082
5083template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005084StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005085TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5086 // Transform the exception declaration, if any.
5087 VarDecl *Var = 0;
5088 if (S->getExceptionDecl()) {
5089 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005090 TypeSourceInfo *T = getDerived().TransformType(
5091 ExceptionDecl->getTypeSourceInfo());
5092 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005093 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005094
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005095 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005097 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005098 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005099 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005100 }
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregorebe10102009-08-20 07:17:43 +00005102 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005103 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005104 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005105 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregorebe10102009-08-20 07:17:43 +00005107 if (!getDerived().AlwaysRebuild() &&
5108 !Var &&
5109 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005110 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005111
5112 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5113 Var,
John McCallb268a282010-08-23 23:25:46 +00005114 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005115}
Mike Stump11289f42009-09-09 15:08:12 +00005116
Douglas Gregorebe10102009-08-20 07:17:43 +00005117template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005118StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005119TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5120 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005121 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005122 = getDerived().TransformCompoundStmt(S->getTryBlock());
5123 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005125
Douglas Gregorebe10102009-08-20 07:17:43 +00005126 // Transform the handlers.
5127 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005128 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005129 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005130 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005131 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5132 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005133 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregorebe10102009-08-20 07:17:43 +00005135 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5136 Handlers.push_back(Handler.takeAs<Stmt>());
5137 }
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregorebe10102009-08-20 07:17:43 +00005139 if (!getDerived().AlwaysRebuild() &&
5140 TryBlock.get() == S->getTryBlock() &&
5141 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005142 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005143
John McCallb268a282010-08-23 23:25:46 +00005144 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005145 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005146}
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregorebe10102009-08-20 07:17:43 +00005148//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005149// Expression transformation
5150//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005151template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005152ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005153TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005154 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005155}
Mike Stump11289f42009-09-09 15:08:12 +00005156
5157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005159TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005160 NestedNameSpecifier *Qualifier = 0;
5161 if (E->getQualifier()) {
5162 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005163 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005164 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005165 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005166 }
John McCallce546572009-12-08 09:08:17 +00005167
5168 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005169 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5170 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005171 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005173
John McCall815039a2010-08-17 21:27:17 +00005174 DeclarationNameInfo NameInfo = E->getNameInfo();
5175 if (NameInfo.getName()) {
5176 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5177 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005178 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005179 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005180
5181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005182 Qualifier == E->getQualifier() &&
5183 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005184 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005185 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005186
5187 // Mark it referenced in the new context regardless.
5188 // FIXME: this is a bit instantiation-specific.
5189 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5190
John McCallc3007a22010-10-26 07:05:15 +00005191 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005192 }
John McCallce546572009-12-08 09:08:17 +00005193
5194 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005195 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005196 TemplateArgs = &TransArgs;
5197 TransArgs.setLAngleLoc(E->getLAngleLoc());
5198 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005199 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5200 E->getNumTemplateArgs(),
5201 TransArgs))
5202 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005203 }
5204
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005205 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005206 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
Douglas Gregora16548e2009-08-11 05:31:07 +00005209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005211TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005212 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005213}
Mike Stump11289f42009-09-09 15:08:12 +00005214
Douglas Gregora16548e2009-08-11 05:31:07 +00005215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005218 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregora16548e2009-08-11 05:31:07 +00005221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005223TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005224 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005225}
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregora16548e2009-08-11 05:31:07 +00005227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005230 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005231}
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregora16548e2009-08-11 05:31:07 +00005233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005235TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005236 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005237}
5238
5239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005241TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005242 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005247 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005248
John McCallb268a282010-08-23 23:25:46 +00005249 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 E->getRParen());
5251}
5252
Mike Stump11289f42009-09-09 15:08:12 +00005253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005255TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005256 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregora16548e2009-08-11 05:31:07 +00005260 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005261 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005262
Douglas Gregora16548e2009-08-11 05:31:07 +00005263 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5264 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005265 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005266}
Mike Stump11289f42009-09-09 15:08:12 +00005267
Douglas Gregora16548e2009-08-11 05:31:07 +00005268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005269ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005270TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5271 // Transform the type.
5272 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5273 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005274 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005275
Douglas Gregor882211c2010-04-28 22:16:22 +00005276 // Transform all of the components into components similar to what the
5277 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005278 // FIXME: It would be slightly more efficient in the non-dependent case to
5279 // just map FieldDecls, rather than requiring the rebuilder to look for
5280 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005281 // template code that we don't care.
5282 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005283 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005284 typedef OffsetOfExpr::OffsetOfNode Node;
5285 llvm::SmallVector<Component, 4> Components;
5286 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5287 const Node &ON = E->getComponent(I);
5288 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005289 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005290 Comp.LocStart = ON.getRange().getBegin();
5291 Comp.LocEnd = ON.getRange().getEnd();
5292 switch (ON.getKind()) {
5293 case Node::Array: {
5294 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005295 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005296 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005297 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005298
Douglas Gregor882211c2010-04-28 22:16:22 +00005299 ExprChanged = ExprChanged || Index.get() != FromIndex;
5300 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005301 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005302 break;
5303 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005304
Douglas Gregor882211c2010-04-28 22:16:22 +00005305 case Node::Field:
5306 case Node::Identifier:
5307 Comp.isBrackets = false;
5308 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005309 if (!Comp.U.IdentInfo)
5310 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005311
Douglas Gregor882211c2010-04-28 22:16:22 +00005312 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005313
Douglas Gregord1702062010-04-29 00:18:15 +00005314 case Node::Base:
5315 // Will be recomputed during the rebuild.
5316 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005317 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005318
Douglas Gregor882211c2010-04-28 22:16:22 +00005319 Components.push_back(Comp);
5320 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005321
Douglas Gregor882211c2010-04-28 22:16:22 +00005322 // If nothing changed, retain the existing expression.
5323 if (!getDerived().AlwaysRebuild() &&
5324 Type == E->getTypeSourceInfo() &&
5325 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005326 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005327
Douglas Gregor882211c2010-04-28 22:16:22 +00005328 // Build a new offsetof expression.
5329 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5330 Components.data(), Components.size(),
5331 E->getRParenLoc());
5332}
5333
5334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005335ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005336TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5337 assert(getDerived().AlreadyTransformed(E->getType()) &&
5338 "opaque value expression requires transformation");
5339 return SemaRef.Owned(E);
5340}
5341
5342template<typename Derived>
5343ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005344TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005345 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005346 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005347
John McCallbcd03502009-12-07 02:54:59 +00005348 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005349 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005351
John McCall4c98fd82009-11-04 07:28:41 +00005352 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005353 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005354
John McCall4c98fd82009-11-04 07:28:41 +00005355 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005356 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005357 E->getSourceRange());
5358 }
Mike Stump11289f42009-09-09 15:08:12 +00005359
John McCalldadc5752010-08-24 06:29:42 +00005360 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005361 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005362 // C++0x [expr.sizeof]p1:
5363 // The operand is either an expression, which is an unevaluated operand
5364 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005365 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5368 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005369 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005372 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005373 }
Mike Stump11289f42009-09-09 15:08:12 +00005374
John McCallb268a282010-08-23 23:25:46 +00005375 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005376 E->isSizeOf(),
5377 E->getSourceRange());
5378}
Mike Stump11289f42009-09-09 15:08:12 +00005379
Douglas Gregora16548e2009-08-11 05:31:07 +00005380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005382TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005383 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005384 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005386
John McCalldadc5752010-08-24 06:29:42 +00005387 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005388 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005390
5391
Douglas Gregora16548e2009-08-11 05:31:07 +00005392 if (!getDerived().AlwaysRebuild() &&
5393 LHS.get() == E->getLHS() &&
5394 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005395 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005396
John McCallb268a282010-08-23 23:25:46 +00005397 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005399 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005400 E->getRBracketLoc());
5401}
Mike Stump11289f42009-09-09 15:08:12 +00005402
5403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005405TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005407 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005409 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005410
5411 // Transform arguments.
5412 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005413 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005414 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5415 &ArgChanged))
5416 return ExprError();
5417
Douglas Gregora16548e2009-08-11 05:31:07 +00005418 if (!getDerived().AlwaysRebuild() &&
5419 Callee.get() == E->getCallee() &&
5420 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005421 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005424 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005425 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005426 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005427 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 E->getRParenLoc());
5429}
Mike Stump11289f42009-09-09 15:08:12 +00005430
5431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005433TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005434 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005437
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005438 NestedNameSpecifier *Qualifier = 0;
5439 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005440 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005441 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005442 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005443 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005444 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005445 }
Mike Stump11289f42009-09-09 15:08:12 +00005446
Eli Friedman2cfcef62009-12-04 06:40:45 +00005447 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005448 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5449 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
John McCall16df1e52010-03-30 21:47:33 +00005453 NamedDecl *FoundDecl = E->getFoundDecl();
5454 if (FoundDecl == E->getMemberDecl()) {
5455 FoundDecl = Member;
5456 } else {
5457 FoundDecl = cast_or_null<NamedDecl>(
5458 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5459 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005460 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005461 }
5462
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 if (!getDerived().AlwaysRebuild() &&
5464 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005465 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005466 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005467 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005468 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005469
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005470 // Mark it referenced in the new context regardless.
5471 // FIXME: this is a bit instantiation-specific.
5472 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005473 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005474 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005475
John McCall6b51f282009-11-23 01:53:49 +00005476 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005477 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005478 TransArgs.setLAngleLoc(E->getLAngleLoc());
5479 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005480 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5481 E->getNumTemplateArgs(),
5482 TransArgs))
5483 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005484 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005485
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 // FIXME: Bogus source location for the operator
5487 SourceLocation FakeOperatorLoc
5488 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5489
John McCall38836f02010-01-15 08:34:02 +00005490 // FIXME: to do this check properly, we will need to preserve the
5491 // first-qualifier-in-scope here, just in case we had a dependent
5492 // base (and therefore couldn't do the check) and a
5493 // nested-name-qualifier (and therefore could do the lookup).
5494 NamedDecl *FirstQualifierInScope = 0;
5495
John McCallb268a282010-08-23 23:25:46 +00005496 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005497 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005498 Qualifier,
5499 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005500 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005501 Member,
John McCall16df1e52010-03-30 21:47:33 +00005502 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005503 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005504 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005505 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005506}
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregora16548e2009-08-11 05:31:07 +00005508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005509ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005510TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005511 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005514
John McCalldadc5752010-08-24 06:29:42 +00005515 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005518
Douglas Gregora16548e2009-08-11 05:31:07 +00005519 if (!getDerived().AlwaysRebuild() &&
5520 LHS.get() == E->getLHS() &&
5521 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005522 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005525 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005526}
5527
Mike Stump11289f42009-09-09 15:08:12 +00005528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005529ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005530TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005531 CompoundAssignOperator *E) {
5532 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005533}
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregora16548e2009-08-11 05:31:07 +00005535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005537TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005538 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005540 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005541
John McCalldadc5752010-08-24 06:29:42 +00005542 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005543 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005545
John McCalldadc5752010-08-24 06:29:42 +00005546 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005547 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005548 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005549
Douglas Gregora16548e2009-08-11 05:31:07 +00005550 if (!getDerived().AlwaysRebuild() &&
5551 Cond.get() == E->getCond() &&
5552 LHS.get() == E->getLHS() &&
5553 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005554 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005555
John McCallb268a282010-08-23 23:25:46 +00005556 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005557 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005558 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005559 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005560 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005561}
Mike Stump11289f42009-09-09 15:08:12 +00005562
5563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005565TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005566 // Implicit casts are eliminated during transformation, since they
5567 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005568 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005569}
Mike Stump11289f42009-09-09 15:08:12 +00005570
Douglas Gregora16548e2009-08-11 05:31:07 +00005571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005573TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005574 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5575 if (!Type)
5576 return ExprError();
5577
John McCalldadc5752010-08-24 06:29:42 +00005578 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005579 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005580 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005584 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005586 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005587
John McCall97513962010-01-15 18:39:57 +00005588 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005589 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005590 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005591 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregora16548e2009-08-11 05:31:07 +00005594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005596TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005597 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5598 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5599 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
John McCalldadc5752010-08-24 06:29:42 +00005602 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 if (Init.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() &&
John McCalle15bbff2010-01-18 19:35:47 +00005607 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005608 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005609 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005610
John McCall5d7aa7f2010-01-19 22:33:45 +00005611 // Note: the expression type doesn't necessarily match the
5612 // type-as-written, but that's okay, because it should always be
5613 // derivable from the initializer.
5614
John McCalle15bbff2010-01-18 19:35:47 +00005615 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005616 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005617 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005618}
Mike Stump11289f42009-09-09 15:08:12 +00005619
Douglas Gregora16548e2009-08-11 05:31:07 +00005620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005621ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005622TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005623 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 if (!getDerived().AlwaysRebuild() &&
5628 Base.get() == E->getBase())
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 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005632 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005634 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 E->getAccessorLoc(),
5636 E->getAccessor());
5637}
Mike Stump11289f42009-09-09 15:08:12 +00005638
Douglas Gregora16548e2009-08-11 05:31:07 +00005639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005641TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005643
John McCall37ad5512010-08-23 06:44:23 +00005644 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005645 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5646 Inits, &InitChanged))
5647 return ExprError();
5648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005650 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005651
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005653 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005654}
Mike Stump11289f42009-09-09 15:08:12 +00005655
Douglas Gregora16548e2009-08-11 05:31:07 +00005656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005658TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregorebe10102009-08-20 07:17:43 +00005661 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005662 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005664 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005665
Douglas Gregorebe10102009-08-20 07:17:43 +00005666 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005667 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 bool ExprChanged = false;
5669 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5670 DEnd = E->designators_end();
5671 D != DEnd; ++D) {
5672 if (D->isFieldDesignator()) {
5673 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5674 D->getDotLoc(),
5675 D->getFieldLoc()));
5676 continue;
5677 }
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005680 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005682 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
5684 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5688 ArrayExprs.push_back(Index.release());
5689 continue;
5690 }
Mike Stump11289f42009-09-09 15:08:12 +00005691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005693 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005694 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5695 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005697
John McCalldadc5752010-08-24 06:29:42 +00005698 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005701
5702 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 End.get(),
5704 D->getLBracketLoc(),
5705 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5708 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 ArrayExprs.push_back(Start.release());
5711 ArrayExprs.push_back(End.release());
5712 }
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 if (!getDerived().AlwaysRebuild() &&
5715 Init.get() == E->getInit() &&
5716 !ExprChanged)
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().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5720 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005721 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005722}
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregora16548e2009-08-11 05:31:07 +00005724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005725ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005726TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005727 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005728 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005729
Douglas Gregor3da3c062009-10-28 00:29:27 +00005730 // FIXME: Will we ever have proper type location here? Will we actually
5731 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 QualType T = getDerived().TransformType(E->getType());
5733 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 if (!getDerived().AlwaysRebuild() &&
5737 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005738 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005739
Douglas Gregora16548e2009-08-11 05:31:07 +00005740 return getDerived().RebuildImplicitValueInitExpr(T);
5741}
Mike Stump11289f42009-09-09 15:08:12 +00005742
Douglas Gregora16548e2009-08-11 05:31:07 +00005743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005745TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005746 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5747 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005749
John McCalldadc5752010-08-24 06:29:42 +00005750 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005753
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005755 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005756 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005757 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005758
John McCallb268a282010-08-23 23:25:46 +00005759 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005760 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005761}
5762
5763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005765TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005766 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005767 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005768 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5769 &ArgumentChanged))
5770 return ExprError();
5771
Douglas Gregora16548e2009-08-11 05:31:07 +00005772 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5773 move_arg(Inits),
5774 E->getRParenLoc());
5775}
Mike Stump11289f42009-09-09 15:08:12 +00005776
Douglas Gregora16548e2009-08-11 05:31:07 +00005777/// \brief Transform an address-of-label expression.
5778///
5779/// By default, the transformation of an address-of-label expression always
5780/// rebuilds the expression, so that the label identifier can be resolved to
5781/// the corresponding label statement by semantic analysis.
5782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005784TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5786 E->getLabel());
5787}
Mike Stump11289f42009-09-09 15:08:12 +00005788
5789template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005790ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005791TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005792 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5794 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797 if (!getDerived().AlwaysRebuild() &&
5798 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005799 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005800
5801 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005802 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005803 E->getRParenLoc());
5804}
Mike Stump11289f42009-09-09 15:08:12 +00005805
Douglas Gregora16548e2009-08-11 05:31:07 +00005806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005808TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005809 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005811 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005812
John McCalldadc5752010-08-24 06:29:42 +00005813 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005814 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005816
John McCalldadc5752010-08-24 06:29:42 +00005817 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005818 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005819 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005820
Douglas Gregora16548e2009-08-11 05:31:07 +00005821 if (!getDerived().AlwaysRebuild() &&
5822 Cond.get() == E->getCond() &&
5823 LHS.get() == E->getLHS() &&
5824 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005825 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005828 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005829 E->getRParenLoc());
5830}
Mike Stump11289f42009-09-09 15:08:12 +00005831
Douglas Gregora16548e2009-08-11 05:31:07 +00005832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005833ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005834TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005835 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005836}
5837
5838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005839ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005840TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005841 switch (E->getOperator()) {
5842 case OO_New:
5843 case OO_Delete:
5844 case OO_Array_New:
5845 case OO_Array_Delete:
5846 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005847 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005848
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005849 case OO_Call: {
5850 // This is a call to an object's operator().
5851 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5852
5853 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005854 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005855 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005856 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005857
5858 // FIXME: Poor location information
5859 SourceLocation FakeLParenLoc
5860 = SemaRef.PP.getLocForEndOfToken(
5861 static_cast<Expr *>(Object.get())->getLocEnd());
5862
5863 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005864 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005865 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5866 Args))
5867 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005868
John McCallb268a282010-08-23 23:25:46 +00005869 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005870 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005871 E->getLocEnd());
5872 }
5873
5874#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5875 case OO_##Name:
5876#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5877#include "clang/Basic/OperatorKinds.def"
5878 case OO_Subscript:
5879 // Handled below.
5880 break;
5881
5882 case OO_Conditional:
5883 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005884 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005885
5886 case OO_None:
5887 case NUM_OVERLOADED_OPERATORS:
5888 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005889 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005890 }
5891
John McCalldadc5752010-08-24 06:29:42 +00005892 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005895
John McCalldadc5752010-08-24 06:29:42 +00005896 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005899
John McCalldadc5752010-08-24 06:29:42 +00005900 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005901 if (E->getNumArgs() == 2) {
5902 Second = getDerived().TransformExpr(E->getArg(1));
5903 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005904 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 }
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregora16548e2009-08-11 05:31:07 +00005907 if (!getDerived().AlwaysRebuild() &&
5908 Callee.get() == E->getCallee() &&
5909 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005910 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005911 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5914 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005915 Callee.get(),
5916 First.get(),
5917 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005918}
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregora16548e2009-08-11 05:31:07 +00005920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5923 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005924}
Mike Stump11289f42009-09-09 15:08:12 +00005925
Douglas Gregora16548e2009-08-11 05:31:07 +00005926template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005927ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005928TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005929 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5930 if (!Type)
5931 return ExprError();
5932
John McCalldadc5752010-08-24 06:29:42 +00005933 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005934 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005935 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005937
Douglas Gregora16548e2009-08-11 05:31:07 +00005938 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005939 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005941 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregora16548e2009-08-11 05:31:07 +00005943 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005944 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005945 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5946 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5947 SourceLocation FakeRParenLoc
5948 = SemaRef.PP.getLocForEndOfToken(
5949 E->getSubExpr()->getSourceRange().getEnd());
5950 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005951 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005953 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005954 FakeRAngleLoc,
5955 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005956 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 FakeRParenLoc);
5958}
Mike Stump11289f42009-09-09 15:08:12 +00005959
Douglas Gregora16548e2009-08-11 05:31:07 +00005960template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005962TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5963 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005964}
Mike Stump11289f42009-09-09 15:08:12 +00005965
5966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005967ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005968TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5969 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005970}
5971
Douglas Gregora16548e2009-08-11 05:31:07 +00005972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005973ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005974TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005975 CXXReinterpretCastExpr *E) {
5976 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005977}
Mike Stump11289f42009-09-09 15:08:12 +00005978
Douglas Gregora16548e2009-08-11 05:31:07 +00005979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5982 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005983}
Mike Stump11289f42009-09-09 15:08:12 +00005984
Douglas Gregora16548e2009-08-11 05:31:07 +00005985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005986ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005987TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005988 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005989 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5990 if (!Type)
5991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005992
John McCalldadc5752010-08-24 06:29:42 +00005993 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005994 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005995 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005999 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006001 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006003 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006005 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006006 E->getRParenLoc());
6007}
Mike Stump11289f42009-09-09 15:08:12 +00006008
Douglas Gregora16548e2009-08-11 05:31:07 +00006009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006013 TypeSourceInfo *TInfo
6014 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6015 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006016 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006017
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006019 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006020 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006021
Douglas Gregor9da64192010-04-26 22:37:10 +00006022 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6023 E->getLocStart(),
6024 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006025 E->getLocEnd());
6026 }
Mike Stump11289f42009-09-09 15:08:12 +00006027
Douglas Gregora16548e2009-08-11 05:31:07 +00006028 // We don't know whether the expression is potentially evaluated until
6029 // after we perform semantic analysis, so the expression is potentially
6030 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006031 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006032 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006033
John McCalldadc5752010-08-24 06:29:42 +00006034 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006037
Douglas Gregora16548e2009-08-11 05:31:07 +00006038 if (!getDerived().AlwaysRebuild() &&
6039 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006040 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregor9da64192010-04-26 22:37:10 +00006042 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6043 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006044 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 E->getLocEnd());
6046}
6047
6048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006049ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006050TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6051 if (E->isTypeOperand()) {
6052 TypeSourceInfo *TInfo
6053 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6054 if (!TInfo)
6055 return ExprError();
6056
6057 if (!getDerived().AlwaysRebuild() &&
6058 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006059 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006060
6061 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6062 E->getLocStart(),
6063 TInfo,
6064 E->getLocEnd());
6065 }
6066
6067 // We don't know whether the expression is potentially evaluated until
6068 // after we perform semantic analysis, so the expression is potentially
6069 // potentially evaluated.
6070 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6071
6072 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6073 if (SubExpr.isInvalid())
6074 return ExprError();
6075
6076 if (!getDerived().AlwaysRebuild() &&
6077 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006078 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006079
6080 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6081 E->getLocStart(),
6082 SubExpr.get(),
6083 E->getLocEnd());
6084}
6085
6086template<typename Derived>
6087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006088TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006089 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006090}
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregora16548e2009-08-11 05:31:07 +00006092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006093ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006094TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006095 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006096 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006097}
Mike Stump11289f42009-09-09 15:08:12 +00006098
Douglas Gregora16548e2009-08-11 05:31:07 +00006099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006101TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006102 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6103 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6104 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006105
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006106 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006107 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006108
Douglas Gregorb15af892010-01-07 23:12:05 +00006109 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregora16548e2009-08-11 05:31:07 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006115 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006118
Douglas Gregora16548e2009-08-11 05:31:07 +00006119 if (!getDerived().AlwaysRebuild() &&
6120 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006121 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006122
John McCallb268a282010-08-23 23:25:46 +00006123 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006124}
Mike Stump11289f42009-09-09 15:08:12 +00006125
Douglas Gregora16548e2009-08-11 05:31:07 +00006126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006128TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006129 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006130 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6131 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006134
Chandler Carruth794da4c2010-02-08 06:42:49 +00006135 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006137 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006138
Douglas Gregor033f6752009-12-23 23:03:06 +00006139 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006140}
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregora16548e2009-08-11 05:31:07 +00006142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006143ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006144TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6145 CXXScalarValueInitExpr *E) {
6146 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6147 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006148 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006149
Douglas Gregora16548e2009-08-11 05:31:07 +00006150 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006151 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006152 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006153
Douglas Gregor2b88c112010-09-08 00:15:04 +00006154 return getDerived().RebuildCXXScalarValueInitExpr(T,
6155 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006156 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006157}
Mike Stump11289f42009-09-09 15:08:12 +00006158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006162 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006163 TypeSourceInfo *AllocTypeInfo
6164 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6165 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006169 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006170 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
Douglas Gregora16548e2009-08-11 05:31:07 +00006173 // Transform the placement arguments (if any).
6174 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006175 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006176 if (getDerived().TransformExprs(E->getPlacementArgs(),
6177 E->getNumPlacementArgs(), true,
6178 PlacementArgs, &ArgumentChanged))
6179 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregorebe10102009-08-20 07:17:43 +00006181 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006182 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006183 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6184 ConstructorArgs, &ArgumentChanged))
6185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006186
Douglas Gregord2d9da02010-02-26 00:38:10 +00006187 // Transform constructor, new operator, and delete operator.
6188 CXXConstructorDecl *Constructor = 0;
6189 if (E->getConstructor()) {
6190 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006191 getDerived().TransformDecl(E->getLocStart(),
6192 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006193 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006194 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006195 }
6196
6197 FunctionDecl *OperatorNew = 0;
6198 if (E->getOperatorNew()) {
6199 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006200 getDerived().TransformDecl(E->getLocStart(),
6201 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006202 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006204 }
6205
6206 FunctionDecl *OperatorDelete = 0;
6207 if (E->getOperatorDelete()) {
6208 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006209 getDerived().TransformDecl(E->getLocStart(),
6210 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006211 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006213 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006216 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006217 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006218 Constructor == E->getConstructor() &&
6219 OperatorNew == E->getOperatorNew() &&
6220 OperatorDelete == E->getOperatorDelete() &&
6221 !ArgumentChanged) {
6222 // Mark any declarations we need as referenced.
6223 // FIXME: instantiation-specific.
6224 if (Constructor)
6225 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6226 if (OperatorNew)
6227 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6228 if (OperatorDelete)
6229 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006230 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006231 }
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregor0744ef62010-09-07 21:49:58 +00006233 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006234 if (!ArraySize.get()) {
6235 // If no array size was specified, but the new expression was
6236 // instantiated with an array type (e.g., "new T" where T is
6237 // instantiated with "int[4]"), extract the outer bound from the
6238 // array type as our array size. We do this with constant and
6239 // dependently-sized array types.
6240 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6241 if (!ArrayT) {
6242 // Do nothing
6243 } else if (const ConstantArrayType *ConsArrayT
6244 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006245 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006246 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6247 ConsArrayT->getSize(),
6248 SemaRef.Context.getSizeType(),
6249 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006250 AllocType = ConsArrayT->getElementType();
6251 } else if (const DependentSizedArrayType *DepArrayT
6252 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6253 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006254 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006255 AllocType = DepArrayT->getElementType();
6256 }
6257 }
6258 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6261 E->isGlobalNew(),
6262 /*FIXME:*/E->getLocStart(),
6263 move_arg(PlacementArgs),
6264 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006265 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006266 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006267 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006268 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 /*FIXME:*/E->getLocStart(),
6270 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006271 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006272}
Mike Stump11289f42009-09-09 15:08:12 +00006273
Douglas Gregora16548e2009-08-11 05:31:07 +00006274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006275ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006276TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006277 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006280
Douglas Gregord2d9da02010-02-26 00:38:10 +00006281 // Transform the delete operator, if known.
6282 FunctionDecl *OperatorDelete = 0;
6283 if (E->getOperatorDelete()) {
6284 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006285 getDerived().TransformDecl(E->getLocStart(),
6286 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006287 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006288 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006289 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006290
Douglas Gregora16548e2009-08-11 05:31:07 +00006291 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006292 Operand.get() == E->getArgument() &&
6293 OperatorDelete == E->getOperatorDelete()) {
6294 // Mark any declarations we need as referenced.
6295 // FIXME: instantiation-specific.
6296 if (OperatorDelete)
6297 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006298
6299 if (!E->getArgument()->isTypeDependent()) {
6300 QualType Destroyed = SemaRef.Context.getBaseElementType(
6301 E->getDestroyedType());
6302 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6303 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6304 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6305 SemaRef.LookupDestructor(Record));
6306 }
6307 }
6308
John McCallc3007a22010-10-26 07:05:15 +00006309 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006310 }
Mike Stump11289f42009-09-09 15:08:12 +00006311
Douglas Gregora16548e2009-08-11 05:31:07 +00006312 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6313 E->isGlobalDelete(),
6314 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006315 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006316}
Mike Stump11289f42009-09-09 15:08:12 +00006317
Douglas Gregora16548e2009-08-11 05:31:07 +00006318template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006319ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006320TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006321 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006322 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006323 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006325
John McCallba7bf592010-08-24 05:47:05 +00006326 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006327 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006328 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006329 E->getOperatorLoc(),
6330 E->isArrow()? tok::arrow : tok::period,
6331 ObjectTypePtr,
6332 MayBePseudoDestructor);
6333 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006334 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006335
John McCallba7bf592010-08-24 05:47:05 +00006336 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006337 NestedNameSpecifier *Qualifier = E->getQualifier();
6338 if (Qualifier) {
6339 Qualifier
6340 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6341 E->getQualifierRange(),
6342 ObjectType);
6343 if (!Qualifier)
6344 return ExprError();
6345 }
Mike Stump11289f42009-09-09 15:08:12 +00006346
Douglas Gregor678f90d2010-02-25 01:56:36 +00006347 PseudoDestructorTypeStorage Destroyed;
6348 if (E->getDestroyedTypeInfo()) {
6349 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006350 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6351 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006352 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006353 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006354 Destroyed = DestroyedTypeInfo;
6355 } else if (ObjectType->isDependentType()) {
6356 // We aren't likely to be able to resolve the identifier down to a type
6357 // now anyway, so just retain the identifier.
6358 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6359 E->getDestroyedTypeLoc());
6360 } else {
6361 // Look for a destructor known with the given name.
6362 CXXScopeSpec SS;
6363 if (Qualifier) {
6364 SS.setScopeRep(Qualifier);
6365 SS.setRange(E->getQualifierRange());
6366 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006367
John McCallba7bf592010-08-24 05:47:05 +00006368 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006369 *E->getDestroyedTypeIdentifier(),
6370 E->getDestroyedTypeLoc(),
6371 /*Scope=*/0,
6372 SS, ObjectTypePtr,
6373 false);
6374 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006375 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006376
Douglas Gregor678f90d2010-02-25 01:56:36 +00006377 Destroyed
6378 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6379 E->getDestroyedTypeLoc());
6380 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006381
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006382 TypeSourceInfo *ScopeTypeInfo = 0;
6383 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006384 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006385 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006386 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006387 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006388
John McCallb268a282010-08-23 23:25:46 +00006389 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006390 E->getOperatorLoc(),
6391 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006392 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006393 E->getQualifierRange(),
6394 ScopeTypeInfo,
6395 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006396 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006397 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006398}
Mike Stump11289f42009-09-09 15:08:12 +00006399
Douglas Gregorad8a3362009-09-04 17:36:40 +00006400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006401ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006402TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006403 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006404 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6405
6406 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6407 Sema::LookupOrdinaryName);
6408
6409 // Transform all the decls.
6410 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6411 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006412 NamedDecl *InstD = static_cast<NamedDecl*>(
6413 getDerived().TransformDecl(Old->getNameLoc(),
6414 *I));
John McCall84d87672009-12-10 09:41:52 +00006415 if (!InstD) {
6416 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6417 // This can happen because of dependent hiding.
6418 if (isa<UsingShadowDecl>(*I))
6419 continue;
6420 else
John McCallfaf5fb42010-08-26 23:41:50 +00006421 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006422 }
John McCalle66edc12009-11-24 19:00:30 +00006423
6424 // Expand using declarations.
6425 if (isa<UsingDecl>(InstD)) {
6426 UsingDecl *UD = cast<UsingDecl>(InstD);
6427 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6428 E = UD->shadow_end(); I != E; ++I)
6429 R.addDecl(*I);
6430 continue;
6431 }
6432
6433 R.addDecl(InstD);
6434 }
6435
6436 // Resolve a kind, but don't do any further analysis. If it's
6437 // ambiguous, the callee needs to deal with it.
6438 R.resolveKind();
6439
6440 // Rebuild the nested-name qualifier, if present.
6441 CXXScopeSpec SS;
6442 NestedNameSpecifier *Qualifier = 0;
6443 if (Old->getQualifier()) {
6444 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006445 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006446 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006447 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006448
John McCalle66edc12009-11-24 19:00:30 +00006449 SS.setScopeRep(Qualifier);
6450 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006451 }
6452
Douglas Gregor9262f472010-04-27 18:19:34 +00006453 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006454 CXXRecordDecl *NamingClass
6455 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6456 Old->getNameLoc(),
6457 Old->getNamingClass()));
6458 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006459 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006460
Douglas Gregorda7be082010-04-27 16:10:10 +00006461 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006462 }
6463
6464 // If we have no template arguments, it's a normal declaration name.
6465 if (!Old->hasExplicitTemplateArgs())
6466 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6467
6468 // If we have template arguments, rebuild them, then rebuild the
6469 // templateid expression.
6470 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006471 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6472 Old->getNumTemplateArgs(),
6473 TransArgs))
6474 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006475
6476 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6477 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006478}
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregora16548e2009-08-11 05:31:07 +00006480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006482TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006483 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6484 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006486
Douglas Gregora16548e2009-08-11 05:31:07 +00006487 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006488 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006489 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006490
Mike Stump11289f42009-09-09 15:08:12 +00006491 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006493 T,
6494 E->getLocEnd());
6495}
Mike Stump11289f42009-09-09 15:08:12 +00006496
Douglas Gregora16548e2009-08-11 05:31:07 +00006497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006498ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006499TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6500 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6501 if (!LhsT)
6502 return ExprError();
6503
6504 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6505 if (!RhsT)
6506 return ExprError();
6507
6508 if (!getDerived().AlwaysRebuild() &&
6509 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6510 return SemaRef.Owned(E);
6511
6512 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6513 E->getLocStart(),
6514 LhsT, RhsT,
6515 E->getLocEnd());
6516}
6517
6518template<typename Derived>
6519ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006520TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006521 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006522 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006523 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006524 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006527
John McCall31f82722010-11-12 08:19:04 +00006528 // TODO: If this is a conversion-function-id, verify that the
6529 // destination type name (if present) resolves the same way after
6530 // instantiation as it did in the local scope.
6531
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006532 DeclarationNameInfo NameInfo
6533 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6534 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006535 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006536
John McCalle66edc12009-11-24 19:00:30 +00006537 if (!E->hasExplicitTemplateArgs()) {
6538 if (!getDerived().AlwaysRebuild() &&
6539 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006540 // Note: it is sufficient to compare the Name component of NameInfo:
6541 // if name has not changed, DNLoc has not changed either.
6542 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006543 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006544
John McCalle66edc12009-11-24 19:00:30 +00006545 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6546 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006547 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006548 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006549 }
John McCall6b51f282009-11-23 01:53:49 +00006550
6551 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006552 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6553 E->getNumTemplateArgs(),
6554 TransArgs))
6555 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006556
John McCalle66edc12009-11-24 19:00:30 +00006557 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6558 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006559 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006560 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006561}
6562
6563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006565TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006566 // CXXConstructExprs are always implicit, so when we have a
6567 // 1-argument construction we just transform that argument.
6568 if (E->getNumArgs() == 1 ||
6569 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6570 return getDerived().TransformExpr(E->getArg(0));
6571
Douglas Gregora16548e2009-08-11 05:31:07 +00006572 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6573
6574 QualType T = getDerived().TransformType(E->getType());
6575 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006577
6578 CXXConstructorDecl *Constructor
6579 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006580 getDerived().TransformDecl(E->getLocStart(),
6581 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006583 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006584
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006586 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006587 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6588 &ArgumentChanged))
6589 return ExprError();
6590
Douglas Gregora16548e2009-08-11 05:31:07 +00006591 if (!getDerived().AlwaysRebuild() &&
6592 T == E->getType() &&
6593 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006594 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006595 // Mark the constructor as referenced.
6596 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006597 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006598 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006599 }
Mike Stump11289f42009-09-09 15:08:12 +00006600
Douglas Gregordb121ba2009-12-14 16:27:04 +00006601 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6602 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006603 move_arg(Args),
6604 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006605 E->getConstructionKind(),
6606 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006607}
Mike Stump11289f42009-09-09 15:08:12 +00006608
Douglas Gregora16548e2009-08-11 05:31:07 +00006609/// \brief Transform a C++ temporary-binding expression.
6610///
Douglas Gregor363b1512009-12-24 18:51:59 +00006611/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6612/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006614ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006615TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006616 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006617}
Mike Stump11289f42009-09-09 15:08:12 +00006618
John McCall5d413782010-12-06 08:20:24 +00006619/// \brief Transform a C++ expression that contains cleanups that should
6620/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006621///
John McCall5d413782010-12-06 08:20:24 +00006622/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006623/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006625ExprResult
John McCall5d413782010-12-06 08:20:24 +00006626TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006627 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006628}
Mike Stump11289f42009-09-09 15:08:12 +00006629
Douglas Gregora16548e2009-08-11 05:31:07 +00006630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006631ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006632TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006633 CXXTemporaryObjectExpr *E) {
6634 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6635 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006636 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006637
Douglas Gregora16548e2009-08-11 05:31:07 +00006638 CXXConstructorDecl *Constructor
6639 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006640 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006641 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006642 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006644
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006646 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006647 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006648 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6649 &ArgumentChanged))
6650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006651
Douglas Gregora16548e2009-08-11 05:31:07 +00006652 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006653 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006654 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006655 !ArgumentChanged) {
6656 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006657 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006658 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006659 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006660
6661 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6662 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006663 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 E->getLocEnd());
6665}
Mike Stump11289f42009-09-09 15:08:12 +00006666
Douglas Gregora16548e2009-08-11 05:31:07 +00006667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006668ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006669TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006670 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006671 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6672 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregora16548e2009-08-11 05:31:07 +00006675 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006676 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006677 Args.reserve(E->arg_size());
6678 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6679 &ArgumentChanged))
6680 return ExprError();
6681
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006683 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006685 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006686
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006688 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 E->getLParenLoc(),
6690 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006691 E->getRParenLoc());
6692}
Mike Stump11289f42009-09-09 15:08:12 +00006693
Douglas Gregora16548e2009-08-11 05:31:07 +00006694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006695ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006696TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006697 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006699 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006700 Expr *OldBase;
6701 QualType BaseType;
6702 QualType ObjectType;
6703 if (!E->isImplicitAccess()) {
6704 OldBase = E->getBase();
6705 Base = getDerived().TransformExpr(OldBase);
6706 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006708
John McCall2d74de92009-12-01 22:10:20 +00006709 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006710 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006711 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006712 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006713 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006714 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006715 ObjectTy,
6716 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006717 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006718 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006719
John McCallba7bf592010-08-24 05:47:05 +00006720 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006721 BaseType = ((Expr*) Base.get())->getType();
6722 } else {
6723 OldBase = 0;
6724 BaseType = getDerived().TransformType(E->getBaseType());
6725 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6726 }
Mike Stump11289f42009-09-09 15:08:12 +00006727
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006728 // Transform the first part of the nested-name-specifier that qualifies
6729 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006730 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006731 = getDerived().TransformFirstQualifierInScope(
6732 E->getFirstQualifierFoundInScope(),
6733 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006735 NestedNameSpecifier *Qualifier = 0;
6736 if (E->getQualifier()) {
6737 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6738 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006739 ObjectType,
6740 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006741 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006743 }
Mike Stump11289f42009-09-09 15:08:12 +00006744
John McCall31f82722010-11-12 08:19:04 +00006745 // TODO: If this is a conversion-function-id, verify that the
6746 // destination type name (if present) resolves the same way after
6747 // instantiation as it did in the local scope.
6748
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006749 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006750 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006751 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006752 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006753
John McCall2d74de92009-12-01 22:10:20 +00006754 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006755 // This is a reference to a member without an explicitly-specified
6756 // template argument list. Optimize for this common case.
6757 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006758 Base.get() == OldBase &&
6759 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006760 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006761 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006762 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006763 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006764
John McCallb268a282010-08-23 23:25:46 +00006765 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006766 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006767 E->isArrow(),
6768 E->getOperatorLoc(),
6769 Qualifier,
6770 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006771 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006772 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006773 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006774 }
6775
John McCall6b51f282009-11-23 01:53:49 +00006776 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006777 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6778 E->getNumTemplateArgs(),
6779 TransArgs))
6780 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006781
John McCallb268a282010-08-23 23:25:46 +00006782 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006783 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006784 E->isArrow(),
6785 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006786 Qualifier,
6787 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006788 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006789 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006790 &TransArgs);
6791}
6792
6793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006795TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006796 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006797 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006798 QualType BaseType;
6799 if (!Old->isImplicitAccess()) {
6800 Base = getDerived().TransformExpr(Old->getBase());
6801 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006802 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006803 BaseType = ((Expr*) Base.get())->getType();
6804 } else {
6805 BaseType = getDerived().TransformType(Old->getBaseType());
6806 }
John McCall10eae182009-11-30 22:42:35 +00006807
6808 NestedNameSpecifier *Qualifier = 0;
6809 if (Old->getQualifier()) {
6810 Qualifier
6811 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006812 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006813 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006814 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006815 }
6816
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006817 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006818 Sema::LookupOrdinaryName);
6819
6820 // Transform all the decls.
6821 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6822 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006823 NamedDecl *InstD = static_cast<NamedDecl*>(
6824 getDerived().TransformDecl(Old->getMemberLoc(),
6825 *I));
John McCall84d87672009-12-10 09:41:52 +00006826 if (!InstD) {
6827 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6828 // This can happen because of dependent hiding.
6829 if (isa<UsingShadowDecl>(*I))
6830 continue;
6831 else
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006833 }
John McCall10eae182009-11-30 22:42:35 +00006834
6835 // Expand using declarations.
6836 if (isa<UsingDecl>(InstD)) {
6837 UsingDecl *UD = cast<UsingDecl>(InstD);
6838 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6839 E = UD->shadow_end(); I != E; ++I)
6840 R.addDecl(*I);
6841 continue;
6842 }
6843
6844 R.addDecl(InstD);
6845 }
6846
6847 R.resolveKind();
6848
Douglas Gregor9262f472010-04-27 18:19:34 +00006849 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006850 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006851 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006852 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006853 Old->getMemberLoc(),
6854 Old->getNamingClass()));
6855 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006856 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006857
Douglas Gregorda7be082010-04-27 16:10:10 +00006858 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006859 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006860
John McCall10eae182009-11-30 22:42:35 +00006861 TemplateArgumentListInfo TransArgs;
6862 if (Old->hasExplicitTemplateArgs()) {
6863 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6864 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006865 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6866 Old->getNumTemplateArgs(),
6867 TransArgs))
6868 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006869 }
John McCall38836f02010-01-15 08:34:02 +00006870
6871 // FIXME: to do this check properly, we will need to preserve the
6872 // first-qualifier-in-scope here, just in case we had a dependent
6873 // base (and therefore couldn't do the check) and a
6874 // nested-name-qualifier (and therefore could do the lookup).
6875 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006876
John McCallb268a282010-08-23 23:25:46 +00006877 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006878 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006879 Old->getOperatorLoc(),
6880 Old->isArrow(),
6881 Qualifier,
6882 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006883 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006884 R,
6885 (Old->hasExplicitTemplateArgs()
6886 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006887}
6888
6889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006890ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006891TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6892 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6893 if (SubExpr.isInvalid())
6894 return ExprError();
6895
6896 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006897 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006898
6899 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6900}
6901
6902template<typename Derived>
6903ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006904TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006905 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6906 if (Pattern.isInvalid())
6907 return ExprError();
6908
6909 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6910 return SemaRef.Owned(E);
6911
Douglas Gregorb8840002011-01-14 21:20:45 +00006912 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6913 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006914}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006915
6916template<typename Derived>
6917ExprResult
6918TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6919 // If E is not value-dependent, then nothing will change when we transform it.
6920 // Note: This is an instantiation-centric view.
6921 if (!E->isValueDependent())
6922 return SemaRef.Owned(E);
6923
6924 // Note: None of the implementations of TryExpandParameterPacks can ever
6925 // produce a diagnostic when given only a single unexpanded parameter pack,
6926 // so
6927 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6928 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006929 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006930 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006931 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6932 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006933 ShouldExpand, RetainExpansion,
6934 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006935 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006936
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006937 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006938 return SemaRef.Owned(E);
6939
6940 // We now know the length of the parameter pack, so build a new expression
6941 // that stores that length.
6942 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6943 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006944 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006945}
6946
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006947template<typename Derived>
6948ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00006949TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6950 SubstNonTypeTemplateParmPackExpr *E) {
6951 // Default behavior is to do nothing with this transformation.
6952 return SemaRef.Owned(E);
6953}
6954
6955template<typename Derived>
6956ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006957TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006958 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006959}
6960
Mike Stump11289f42009-09-09 15:08:12 +00006961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006962ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006963TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006964 TypeSourceInfo *EncodedTypeInfo
6965 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6966 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006968
Douglas Gregora16548e2009-08-11 05:31:07 +00006969 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006970 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006971 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006972
6973 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006974 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006975 E->getRParenLoc());
6976}
Mike Stump11289f42009-09-09 15:08:12 +00006977
Douglas Gregora16548e2009-08-11 05:31:07 +00006978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006979ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006980TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006981 // Transform arguments.
6982 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006983 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006984 Args.reserve(E->getNumArgs());
6985 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6986 &ArgChanged))
6987 return ExprError();
6988
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006989 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6990 // Class message: transform the receiver type.
6991 TypeSourceInfo *ReceiverTypeInfo
6992 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6993 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006994 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006995
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006996 // If nothing changed, just retain the existing message send.
6997 if (!getDerived().AlwaysRebuild() &&
6998 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006999 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007000
7001 // Build a new class message send.
7002 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7003 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007004 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007005 E->getMethodDecl(),
7006 E->getLeftLoc(),
7007 move_arg(Args),
7008 E->getRightLoc());
7009 }
7010
7011 // Instance message: transform the receiver
7012 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7013 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007014 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007015 = getDerived().TransformExpr(E->getInstanceReceiver());
7016 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007017 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007018
7019 // If nothing changed, just retain the existing message send.
7020 if (!getDerived().AlwaysRebuild() &&
7021 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007022 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007023
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007024 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007025 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007026 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007027 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007028 E->getMethodDecl(),
7029 E->getLeftLoc(),
7030 move_arg(Args),
7031 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007032}
7033
Mike Stump11289f42009-09-09 15:08:12 +00007034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007036TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007037 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007038}
7039
Mike Stump11289f42009-09-09 15:08:12 +00007040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007042TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007043 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007044}
7045
Mike Stump11289f42009-09-09 15:08:12 +00007046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007048TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007049 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007050 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007051 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007052 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007053
7054 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007055
Douglas Gregord51d90d2010-04-26 20:11:03 +00007056 // If nothing changed, just retain the existing expression.
7057 if (!getDerived().AlwaysRebuild() &&
7058 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007059 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007060
John McCallb268a282010-08-23 23:25:46 +00007061 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007062 E->getLocation(),
7063 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007064}
7065
Mike Stump11289f42009-09-09 15:08:12 +00007066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007068TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007069 // 'super' and types never change. Property never changes. Just
7070 // retain the existing expression.
7071 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007072 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007073
Douglas Gregor9faee212010-04-26 20:47:02 +00007074 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007075 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007076 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007077 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007078
Douglas Gregor9faee212010-04-26 20:47:02 +00007079 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007080
Douglas Gregor9faee212010-04-26 20:47:02 +00007081 // If nothing changed, just retain the existing expression.
7082 if (!getDerived().AlwaysRebuild() &&
7083 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007085
John McCallb7bd14f2010-12-02 01:19:52 +00007086 if (E->isExplicitProperty())
7087 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7088 E->getExplicitProperty(),
7089 E->getLocation());
7090
7091 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7092 E->getType(),
7093 E->getImplicitPropertyGetter(),
7094 E->getImplicitPropertySetter(),
7095 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007096}
7097
Mike Stump11289f42009-09-09 15:08:12 +00007098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007100TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007101 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007102 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007103 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007104 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007105
Douglas Gregord51d90d2010-04-26 20:11:03 +00007106 // If nothing changed, just retain the existing expression.
7107 if (!getDerived().AlwaysRebuild() &&
7108 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007109 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007110
John McCallb268a282010-08-23 23:25:46 +00007111 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007112 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007113}
7114
Mike Stump11289f42009-09-09 15:08:12 +00007115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007116ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007117TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007118 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007119 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007120 SubExprs.reserve(E->getNumSubExprs());
7121 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7122 SubExprs, &ArgumentChanged))
7123 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007124
Douglas Gregora16548e2009-08-11 05:31:07 +00007125 if (!getDerived().AlwaysRebuild() &&
7126 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007127 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007128
Douglas Gregora16548e2009-08-11 05:31:07 +00007129 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7130 move_arg(SubExprs),
7131 E->getRParenLoc());
7132}
7133
Mike Stump11289f42009-09-09 15:08:12 +00007134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007135ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007136TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007137 SourceLocation CaretLoc(E->getExprLoc());
7138
7139 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7140 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7141 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7142 llvm::SmallVector<ParmVarDecl*, 4> Params;
7143 llvm::SmallVector<QualType, 4> ParamTypes;
7144
7145 // Parameter substitution.
Douglas Gregor476e3022011-01-19 21:32:01 +00007146 BlockDecl *BD = E->getBlockDecl();
7147 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7148 BD->param_begin(),
7149 BD->param_size(), 0, ParamTypes,
7150 &Params))
7151 return true;
7152
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007153
7154 const FunctionType *BExprFunctionType = E->getFunctionType();
7155 QualType BExprResultType = BExprFunctionType->getResultType();
7156 if (!BExprResultType.isNull()) {
7157 if (!BExprResultType->isDependentType())
7158 CurBlock->ReturnType = BExprResultType;
7159 else if (BExprResultType != SemaRef.Context.DependentTy)
7160 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7161 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007162
7163 // If the return type has not been determined yet, leave it as a dependent
7164 // type; it'll get set when we process the body.
7165 if (CurBlock->ReturnType.isNull())
7166 CurBlock->ReturnType = getSema().Context.DependentTy;
7167
7168 // Don't allow returning a objc interface by value.
7169 if (CurBlock->ReturnType->isObjCObjectType()) {
7170 getSema().Diag(E->getLocStart(),
7171 diag::err_object_cannot_be_passed_returned_by_value)
7172 << 0 << CurBlock->ReturnType;
7173 return ExprError();
7174 }
John McCall3882ace2011-01-05 12:14:39 +00007175
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007176 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7177 CurBlock->ReturnType,
7178 ParamTypes.data(),
7179 ParamTypes.size(),
7180 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007181 0,
7182 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007183 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00007184
7185 // Set the parameters on the block decl.
7186 if (!Params.empty())
7187 CurBlock->TheDecl->setParams(Params.data(), Params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007188
7189 // If the return type wasn't explicitly set, it will have been marked as a
7190 // dependent type (DependentTy); clear out the return type setting so
7191 // we will deduce the return type when type-checking the block's body.
7192 if (CurBlock->ReturnType == getSema().Context.DependentTy)
7193 CurBlock->ReturnType = QualType();
7194
John McCall3882ace2011-01-05 12:14:39 +00007195 // Transform the body
7196 StmtResult Body = getDerived().TransformStmt(E->getBody());
7197 if (Body.isInvalid())
7198 return ExprError();
7199
John McCallb268a282010-08-23 23:25:46 +00007200 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007201}
7202
Mike Stump11289f42009-09-09 15:08:12 +00007203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007204ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007205TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007206 NestedNameSpecifier *Qualifier = 0;
7207
7208 ValueDecl *ND
7209 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7210 E->getDecl()));
7211 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007212 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007213
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007214 if (!getDerived().AlwaysRebuild() &&
7215 ND == E->getDecl()) {
7216 // Mark it referenced in the new context regardless.
7217 // FIXME: this is a bit instantiation-specific.
7218 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7219
John McCallc3007a22010-10-26 07:05:15 +00007220 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007221 }
7222
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007223 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007224 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007225 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007226}
Mike Stump11289f42009-09-09 15:08:12 +00007227
Douglas Gregora16548e2009-08-11 05:31:07 +00007228//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007229// Type reconstruction
7230//===----------------------------------------------------------------------===//
7231
Mike Stump11289f42009-09-09 15:08:12 +00007232template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007233QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7234 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007235 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007236 getDerived().getBaseEntity());
7237}
7238
Mike Stump11289f42009-09-09 15:08:12 +00007239template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007240QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7241 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007242 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007243 getDerived().getBaseEntity());
7244}
7245
Mike Stump11289f42009-09-09 15:08:12 +00007246template<typename Derived>
7247QualType
John McCall70dd5f62009-10-30 00:06:24 +00007248TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7249 bool WrittenAsLValue,
7250 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007251 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007252 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007253}
7254
7255template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007256QualType
John McCall70dd5f62009-10-30 00:06:24 +00007257TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7258 QualType ClassType,
7259 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007260 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007261 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007262}
7263
7264template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007265QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007266TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7267 ArrayType::ArraySizeModifier SizeMod,
7268 const llvm::APInt *Size,
7269 Expr *SizeExpr,
7270 unsigned IndexTypeQuals,
7271 SourceRange BracketsRange) {
7272 if (SizeExpr || !Size)
7273 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7274 IndexTypeQuals, BracketsRange,
7275 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007276
7277 QualType Types[] = {
7278 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7279 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7280 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007281 };
7282 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7283 QualType SizeType;
7284 for (unsigned I = 0; I != NumTypes; ++I)
7285 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7286 SizeType = Types[I];
7287 break;
7288 }
Mike Stump11289f42009-09-09 15:08:12 +00007289
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007290 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7291 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007292 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007293 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007294 getDerived().getBaseEntity());
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>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007300 ArrayType::ArraySizeModifier SizeMod,
7301 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007302 unsigned IndexTypeQuals,
7303 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007304 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007305 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007306}
7307
7308template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007309QualType
Mike Stump11289f42009-09-09 15:08:12 +00007310TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007311 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007312 unsigned IndexTypeQuals,
7313 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007314 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007315 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007316}
Mike Stump11289f42009-09-09 15:08:12 +00007317
Douglas Gregord6ff3322009-08-04 16:50:30 +00007318template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007319QualType
7320TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007321 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007322 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007323 unsigned IndexTypeQuals,
7324 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007325 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007326 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007327 IndexTypeQuals, BracketsRange);
7328}
7329
7330template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007331QualType
7332TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007333 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007334 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007335 unsigned IndexTypeQuals,
7336 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007337 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007338 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007339 IndexTypeQuals, BracketsRange);
7340}
7341
7342template<typename Derived>
7343QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007344 unsigned NumElements,
7345 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007346 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007347 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007348}
Mike Stump11289f42009-09-09 15:08:12 +00007349
Douglas Gregord6ff3322009-08-04 16:50:30 +00007350template<typename Derived>
7351QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7352 unsigned NumElements,
7353 SourceLocation AttributeLoc) {
7354 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7355 NumElements, true);
7356 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007357 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7358 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007359 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007360}
Mike Stump11289f42009-09-09 15:08:12 +00007361
Douglas Gregord6ff3322009-08-04 16:50:30 +00007362template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007363QualType
7364TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007365 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007366 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007367 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007368}
Mike Stump11289f42009-09-09 15:08:12 +00007369
Douglas Gregord6ff3322009-08-04 16:50:30 +00007370template<typename Derived>
7371QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007372 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007373 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007374 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007375 unsigned Quals,
7376 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007377 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007378 Quals,
7379 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007380 getDerived().getBaseEntity(),
7381 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007382}
Mike Stump11289f42009-09-09 15:08:12 +00007383
Douglas Gregord6ff3322009-08-04 16:50:30 +00007384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007385QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7386 return SemaRef.Context.getFunctionNoProtoType(T);
7387}
7388
7389template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007390QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7391 assert(D && "no decl found");
7392 if (D->isInvalidDecl()) return QualType();
7393
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007394 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007395 TypeDecl *Ty;
7396 if (isa<UsingDecl>(D)) {
7397 UsingDecl *Using = cast<UsingDecl>(D);
7398 assert(Using->isTypeName() &&
7399 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7400
7401 // A valid resolved using typename decl points to exactly one type decl.
7402 assert(++Using->shadow_begin() == Using->shadow_end());
7403 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007404
John McCallb96ec562009-12-04 22:46:56 +00007405 } else {
7406 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7407 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7408 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7409 }
7410
7411 return SemaRef.Context.getTypeDeclType(Ty);
7412}
7413
7414template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007415QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7416 SourceLocation Loc) {
7417 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007418}
7419
7420template<typename Derived>
7421QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7422 return SemaRef.Context.getTypeOfType(Underlying);
7423}
7424
7425template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007426QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7427 SourceLocation Loc) {
7428 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007429}
7430
7431template<typename Derived>
7432QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007433 TemplateName Template,
7434 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007435 const TemplateArgumentListInfo &TemplateArgs) {
7436 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007437}
Mike Stump11289f42009-09-09 15:08:12 +00007438
Douglas Gregor1135c352009-08-06 05:28:30 +00007439template<typename Derived>
7440NestedNameSpecifier *
7441TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7442 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007443 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007444 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007445 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007446 CXXScopeSpec SS;
7447 // FIXME: The source location information is all wrong.
7448 SS.setRange(Range);
7449 SS.setScopeRep(Prefix);
7450 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007451 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007452 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007453 ObjectType,
7454 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007455 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007456}
7457
7458template<typename Derived>
7459NestedNameSpecifier *
7460TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7461 SourceRange Range,
7462 NamespaceDecl *NS) {
7463 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7464}
7465
7466template<typename Derived>
7467NestedNameSpecifier *
7468TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7469 SourceRange Range,
7470 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007471 QualType T) {
7472 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007473 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007474 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007475 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7476 T.getTypePtr());
7477 }
Mike Stump11289f42009-09-09 15:08:12 +00007478
Douglas Gregor1135c352009-08-06 05:28:30 +00007479 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7480 return 0;
7481}
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregor71dc5092009-08-06 06:41:21 +00007483template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007484TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007485TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7486 bool TemplateKW,
7487 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007488 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007489 Template);
7490}
7491
7492template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007493TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007494TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007495 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007496 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007497 QualType ObjectType,
7498 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007499 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007500 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007501 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007502 UnqualifiedId Name;
7503 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007504 Sema::TemplateTy Template;
7505 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7506 /*FIXME:*/getDerived().getBaseLocation(),
7507 SS,
7508 Name,
John McCallba7bf592010-08-24 05:47:05 +00007509 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007510 /*EnteringContext=*/false,
7511 Template);
John McCall31f82722010-11-12 08:19:04 +00007512 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007513}
Mike Stump11289f42009-09-09 15:08:12 +00007514
Douglas Gregora16548e2009-08-11 05:31:07 +00007515template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007516TemplateName
7517TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7518 OverloadedOperatorKind Operator,
7519 QualType ObjectType) {
7520 CXXScopeSpec SS;
7521 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7522 SS.setScopeRep(Qualifier);
7523 UnqualifiedId Name;
7524 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7525 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7526 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007527 Sema::TemplateTy Template;
7528 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007529 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007530 SS,
7531 Name,
John McCallba7bf592010-08-24 05:47:05 +00007532 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007533 /*EnteringContext=*/false,
7534 Template);
7535 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007536}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007537
Douglas Gregor71395fa2009-11-04 00:56:37 +00007538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007539ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007540TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7541 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007542 Expr *OrigCallee,
7543 Expr *First,
7544 Expr *Second) {
7545 Expr *Callee = OrigCallee->IgnoreParenCasts();
7546 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007547
Douglas Gregora16548e2009-08-11 05:31:07 +00007548 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007549 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007550 if (!First->getType()->isOverloadableType() &&
7551 !Second->getType()->isOverloadableType())
7552 return getSema().CreateBuiltinArraySubscriptExpr(First,
7553 Callee->getLocStart(),
7554 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007555 } else if (Op == OO_Arrow) {
7556 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007557 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7558 } else if (Second == 0 || isPostIncDec) {
7559 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007560 // The argument is not of overloadable type, so try to create a
7561 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007562 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007563 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007564
John McCallb268a282010-08-23 23:25:46 +00007565 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007566 }
7567 } else {
John McCallb268a282010-08-23 23:25:46 +00007568 if (!First->getType()->isOverloadableType() &&
7569 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007570 // Neither of the arguments is an overloadable type, so try to
7571 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007572 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007573 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007574 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007575 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007577
Douglas Gregora16548e2009-08-11 05:31:07 +00007578 return move(Result);
7579 }
7580 }
Mike Stump11289f42009-09-09 15:08:12 +00007581
7582 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007583 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007584 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007585
John McCallb268a282010-08-23 23:25:46 +00007586 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007587 assert(ULE->requiresADL());
7588
7589 // FIXME: Do we have to check
7590 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007591 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007592 } else {
John McCallb268a282010-08-23 23:25:46 +00007593 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007594 }
Mike Stump11289f42009-09-09 15:08:12 +00007595
Douglas Gregora16548e2009-08-11 05:31:07 +00007596 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007597 Expr *Args[2] = { First, Second };
7598 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007599
Douglas Gregora16548e2009-08-11 05:31:07 +00007600 // Create the overloaded operator invocation for unary operators.
7601 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007602 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007603 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007604 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007605 }
Mike Stump11289f42009-09-09 15:08:12 +00007606
Sebastian Redladba46e2009-10-29 20:17:01 +00007607 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007608 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007609 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007610 First,
7611 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007612
Douglas Gregora16548e2009-08-11 05:31:07 +00007613 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007614 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007615 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007616 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7617 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007619
Mike Stump11289f42009-09-09 15:08:12 +00007620 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007621}
Mike Stump11289f42009-09-09 15:08:12 +00007622
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007624ExprResult
John McCallb268a282010-08-23 23:25:46 +00007625TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007626 SourceLocation OperatorLoc,
7627 bool isArrow,
7628 NestedNameSpecifier *Qualifier,
7629 SourceRange QualifierRange,
7630 TypeSourceInfo *ScopeType,
7631 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007632 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007633 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007634 CXXScopeSpec SS;
7635 if (Qualifier) {
7636 SS.setRange(QualifierRange);
7637 SS.setScopeRep(Qualifier);
7638 }
7639
John McCallb268a282010-08-23 23:25:46 +00007640 QualType BaseType = Base->getType();
7641 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007642 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007643 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007644 !BaseType->getAs<PointerType>()->getPointeeType()
7645 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007646 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007647 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007648 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007649 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007650 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007651 /*FIXME?*/true);
7652 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007653
Douglas Gregor678f90d2010-02-25 01:56:36 +00007654 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007655 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7656 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7657 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7658 NameInfo.setNamedTypeInfo(DestroyedType);
7659
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007660 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007661
John McCallb268a282010-08-23 23:25:46 +00007662 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007663 OperatorLoc, isArrow,
7664 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007665 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007666 /*TemplateArgs*/ 0);
7667}
7668
Douglas Gregord6ff3322009-08-04 16:50:30 +00007669} // end namespace clang
7670
7671#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H