blob: 3390dd7badc75384f5c171d9f058cc7968bb3f4a [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000037using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000038
Douglas Gregord6ff3322009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump11289f42009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump11289f42009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000092 /// \brief Private RAII object that helps us forget and then re-remember
93 /// the template argument corresponding to a partially-substituted parameter
94 /// pack.
95 class ForgetPartiallySubstitutedPackRAII {
96 Derived &Self;
97 TemplateArgument Old;
98
99 public:
100 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
101 Old = Self.ForgetPartiallySubstitutedPack();
102 }
103
104 ~ForgetPartiallySubstitutedPackRAII() {
105 Self.RememberPartiallySubstitutedPack(Old);
106 }
107 };
108
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109protected:
110 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000111
Mike Stump11289f42009-09-09 15:08:12 +0000112public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000114 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000115
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Retrieves a reference to the derived class.
117 Derived &getDerived() { return static_cast<Derived&>(*this); }
118
119 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000120 const Derived &getDerived() const {
121 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 }
123
John McCalldadc5752010-08-24 06:29:42 +0000124 static inline ExprResult Owned(Expr *E) { return E; }
125 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000126
Douglas Gregord6ff3322009-08-04 16:50:30 +0000127 /// \brief Retrieves a reference to the semantic analysis object used for
128 /// this tree transform.
129 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000130
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 /// \brief Whether the transformation should always rebuild AST nodes, even
132 /// if none of the children have changed.
133 ///
134 /// Subclasses may override this function to specify when the transformation
135 /// should rebuild all AST nodes.
136 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000137
Douglas Gregord6ff3322009-08-04 16:50:30 +0000138 /// \brief Returns the location of the entity being transformed, if that
139 /// information was not available elsewhere in the AST.
140 ///
Mike Stump11289f42009-09-09 15:08:12 +0000141 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000142 /// provide an alternative implementation that provides better location
143 /// information.
144 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000145
Douglas Gregord6ff3322009-08-04 16:50:30 +0000146 /// \brief Returns the name of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
149 /// By default, returns an empty name. Subclasses can provide an alternative
150 /// implementation with a more precise name.
151 DeclarationName getBaseEntity() { return DeclarationName(); }
152
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 /// \brief Sets the "base" location and entity when that
154 /// information is known based on another transformation.
155 ///
156 /// By default, the source location and entity are ignored. Subclasses can
157 /// override this function to provide a customized implementation.
158 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregora16548e2009-08-11 05:31:07 +0000160 /// \brief RAII object that temporarily sets the base location and entity
161 /// used for reporting diagnostics in types.
162 class TemporaryBase {
163 TreeTransform &Self;
164 SourceLocation OldLocation;
165 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 public:
168 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000169 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 OldLocation = Self.getDerived().getBaseLocation();
171 OldEntity = Self.getDerived().getBaseEntity();
172 Self.getDerived().setBase(Location, Entity);
173 }
Mike Stump11289f42009-09-09 15:08:12 +0000174
Douglas Gregora16548e2009-08-11 05:31:07 +0000175 ~TemporaryBase() {
176 Self.getDerived().setBase(OldLocation, OldEntity);
177 }
178 };
Mike Stump11289f42009-09-09 15:08:12 +0000179
180 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000181 /// transformed.
182 ///
183 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000184 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// not change. For example, template instantiation need not traverse
186 /// non-dependent types.
187 bool AlreadyTransformed(QualType T) {
188 return T.isNull();
189 }
190
Douglas Gregord196a582009-12-14 19:27:10 +0000191 /// \brief Determine whether the given call argument should be dropped, e.g.,
192 /// because it is a default argument.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine to
195 /// determine which kinds of call arguments get dropped. By default,
196 /// CXXDefaultArgument nodes are dropped (prior to transformation).
197 bool DropCallArgument(Expr *E) {
198 return E->isDefaultArgument();
199 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000200
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000201 /// \brief Determine whether we should expand a pack expansion with the
202 /// given set of parameter packs into separate arguments by repeatedly
203 /// transforming the pattern.
204 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000205 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// Subclasses can override this routine to provide different behavior.
207 ///
208 /// \param EllipsisLoc The location of the ellipsis that identifies the
209 /// pack expansion.
210 ///
211 /// \param PatternRange The source range that covers the entire pattern of
212 /// the pack expansion.
213 ///
214 /// \param Unexpanded The set of unexpanded parameter packs within the
215 /// pattern.
216 ///
217 /// \param NumUnexpanded The number of unexpanded parameter packs in
218 /// \p Unexpanded.
219 ///
220 /// \param ShouldExpand Will be set to \c true if the transformer should
221 /// expand the corresponding pack expansions into separate arguments. When
222 /// set, \c NumExpansions must also be set.
223 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000224 /// \param RetainExpansion Whether the caller should add an unexpanded
225 /// pack expansion after all of the expanded arguments. This is used
226 /// when extending explicitly-specified template argument packs per
227 /// C++0x [temp.arg.explicit]p9.
228 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000229 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000230 /// the expanded form of the corresponding pack expansion. This is both an
231 /// input and an output parameter, which can be set by the caller if the
232 /// number of expansions is known a priori (e.g., due to a prior substitution)
233 /// and will be set by the callee when the number of expansions is known.
234 /// The callee must set this value when \c ShouldExpand is \c true; it may
235 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000236 ///
237 /// \returns true if an error occurred (e.g., because the parameter packs
238 /// are to be instantiated with arguments of different lengths), false
239 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
240 /// must be set.
241 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
242 SourceRange PatternRange,
243 const UnexpandedParameterPack *Unexpanded,
244 unsigned NumUnexpanded,
245 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000246 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000247 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ShouldExpand = false;
249 return false;
250 }
251
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000252 /// \brief "Forget" about the partially-substituted pack template argument,
253 /// when performing an instantiation that must preserve the parameter pack
254 /// use.
255 ///
256 /// This routine is meant to be overridden by the template instantiator.
257 TemplateArgument ForgetPartiallySubstitutedPack() {
258 return TemplateArgument();
259 }
260
261 /// \brief "Remember" the partially-substituted pack template argument
262 /// after performing an instantiation that must preserve the parameter pack
263 /// use.
264 ///
265 /// This routine is meant to be overridden by the template instantiator.
266 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
267
Douglas Gregorf3010112011-01-07 16:43:16 +0000268 /// \brief Note to the derived class when a function parameter pack is
269 /// being expanded.
270 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
271
Douglas Gregord6ff3322009-08-04 16:50:30 +0000272 /// \brief Transforms the given type into another type.
273 ///
John McCall550e0c22009-10-21 00:40:46 +0000274 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000275 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000276 /// function. This is expensive, but we don't mind, because
277 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000278 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000279 ///
280 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000281 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000282
John McCall550e0c22009-10-21 00:40:46 +0000283 /// \brief Transforms the given type-with-location into a new
284 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000285 ///
John McCall550e0c22009-10-21 00:40:46 +0000286 /// By default, this routine transforms a type by delegating to the
287 /// appropriate TransformXXXType to build a new type. Subclasses
288 /// may override this function (to take over all type
289 /// transformations) or some set of the TransformXXXType functions
290 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000291 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000292
293 /// \brief Transform the given type-with-location into a new
294 /// type, collecting location information in the given builder
295 /// as necessary.
296 ///
John McCall31f82722010-11-12 08:19:04 +0000297 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000298
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000299 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000300 ///
Mike Stump11289f42009-09-09 15:08:12 +0000301 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000302 /// appropriate TransformXXXStmt function to transform a specific kind of
303 /// statement or the TransformExpr() function to transform an expression.
304 /// Subclasses may override this function to transform statements using some
305 /// other mechanism.
306 ///
307 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000308 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given expression.
311 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000312 /// By default, this routine transforms an expression by delegating to the
313 /// appropriate TransformXXXExpr function to build a new expression.
314 /// Subclasses may override this function to transform expressions using some
315 /// other mechanism.
316 ///
317 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000318 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000319
Douglas Gregora3efea12011-01-03 19:04:46 +0000320 /// \brief Transform the given list of expressions.
321 ///
322 /// This routine transforms a list of expressions by invoking
323 /// \c TransformExpr() for each subexpression. However, it also provides
324 /// support for variadic templates by expanding any pack expansions (if the
325 /// derived class permits such expansion) along the way. When pack expansions
326 /// are present, the number of outputs may not equal the number of inputs.
327 ///
328 /// \param Inputs The set of expressions to be transformed.
329 ///
330 /// \param NumInputs The number of expressions in \c Inputs.
331 ///
332 /// \param IsCall If \c true, then this transform is being performed on
333 /// function-call arguments, and any arguments that should be dropped, will
334 /// be.
335 ///
336 /// \param Outputs The transformed input expressions will be added to this
337 /// vector.
338 ///
339 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
340 /// due to transformation.
341 ///
342 /// \returns true if an error occurred, false otherwise.
343 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
344 llvm::SmallVectorImpl<Expr *> &Outputs,
345 bool *ArgChanged = 0);
346
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 /// \brief Transform the given declaration, which is referenced from a type
348 /// or expression.
349 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000350 /// By default, acts as the identity function on declarations. Subclasses
351 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000352 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000353
354 /// \brief Transform the definition of the given declaration.
355 ///
Mike Stump11289f42009-09-09 15:08:12 +0000356 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000357 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000358 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
359 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000360 }
Mike Stump11289f42009-09-09 15:08:12 +0000361
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000362 /// \brief Transform the given declaration, which was the first part of a
363 /// nested-name-specifier in a member access expression.
364 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000365 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// identifier in a nested-name-specifier of a member access expression, e.g.,
367 /// the \c T in \c x->T::member
368 ///
369 /// By default, invokes TransformDecl() to transform the declaration.
370 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000371 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
372 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374
Douglas Gregord6ff3322009-08-04 16:50:30 +0000375 /// \brief Transform the given nested-name-specifier.
376 ///
Mike Stump11289f42009-09-09 15:08:12 +0000377 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000378 /// nested-name-specifier. Subclasses may override this function to provide
379 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000380 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000381 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000382 QualType ObjectType = QualType(),
383 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000384
Douglas Gregorf816bd72009-09-03 22:13:48 +0000385 /// \brief Transform the given declaration name.
386 ///
387 /// By default, transforms the types of conversion function, constructor,
388 /// and destructor names and then (if needed) rebuilds the declaration name.
389 /// Identifiers and selectors are returned unmodified. Sublcasses may
390 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000391 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000392 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000395 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000396 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000397 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000398 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000399 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000400 QualType ObjectType = QualType(),
401 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000402
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403 /// \brief Transform the given template argument.
404 ///
Mike Stump11289f42009-09-09 15:08:12 +0000405 /// By default, this operation transforms the type, expression, or
406 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000407 /// new template argument from the transformed result. Subclasses may
408 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000409 ///
410 /// Returns true if there was an error.
411 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
412 TemplateArgumentLoc &Output);
413
Douglas Gregor62e06f22010-12-20 17:31:10 +0000414 /// \brief Transform the given set of template arguments.
415 ///
416 /// By default, this operation transforms all of the template arguments
417 /// in the input set using \c TransformTemplateArgument(), and appends
418 /// the transformed arguments to the output list.
419 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000420 /// Note that this overload of \c TransformTemplateArguments() is merely
421 /// a convenience function. Subclasses that wish to override this behavior
422 /// should override the iterator-based member template version.
423 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000424 /// \param Inputs The set of template arguments to be transformed.
425 ///
426 /// \param NumInputs The number of template arguments in \p Inputs.
427 ///
428 /// \param Outputs The set of transformed template arguments output by this
429 /// routine.
430 ///
431 /// Returns true if an error occurred.
432 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
433 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 TemplateArgumentListInfo &Outputs) {
435 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
436 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000437
438 /// \brief Transform the given set of template arguments.
439 ///
440 /// By default, this operation transforms all of the template arguments
441 /// in the input set using \c TransformTemplateArgument(), and appends
442 /// the transformed arguments to the output list.
443 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000444 /// \param First An iterator to the first template argument.
445 ///
446 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000447 ///
448 /// \param Outputs The set of transformed template arguments output by this
449 /// routine.
450 ///
451 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000452 template<typename InputIterator>
453 bool TransformTemplateArguments(InputIterator First,
454 InputIterator Last,
455 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000456
John McCall0ad16662009-10-29 08:12:44 +0000457 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
458 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
459 TemplateArgumentLoc &ArgLoc);
460
John McCallbcd03502009-12-07 02:54:59 +0000461 /// \brief Fakes up a TypeSourceInfo for a type.
462 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
463 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000464 getDerived().getBaseLocation());
465 }
Mike Stump11289f42009-09-09 15:08:12 +0000466
John McCall550e0c22009-10-21 00:40:46 +0000467#define ABSTRACT_TYPELOC(CLASS, PARENT)
468#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000469 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000470#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000471
John McCall31f82722010-11-12 08:19:04 +0000472 QualType
473 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
474 TemplateSpecializationTypeLoc TL,
475 TemplateName Template);
476
477 QualType
478 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
479 DependentTemplateSpecializationTypeLoc TL,
480 NestedNameSpecifier *Prefix);
481
John McCall58f10c32010-03-11 09:03:00 +0000482 /// \brief Transforms the parameters of a function type into the
483 /// given vectors.
484 ///
485 /// The result vectors should be kept in sync; null entries in the
486 /// variables vector are acceptable.
487 ///
488 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000489 bool TransformFunctionTypeParams(SourceLocation Loc,
490 ParmVarDecl **Params, unsigned NumParams,
491 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000492 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000493 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000494
495 /// \brief Transforms a single function-type parameter. Return null
496 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000497 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
498 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000499
John McCall31f82722010-11-12 08:19:04 +0000500 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000501
John McCalldadc5752010-08-24 06:29:42 +0000502 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
503 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000504
Douglas Gregorebe10102009-08-20 07:17:43 +0000505#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000506 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000507#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000508 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000509#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000510#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new pointer type given its pointee type.
513 ///
514 /// By default, performs semantic analysis when building the pointer type.
515 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000516 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517
518 /// \brief Build a new block pointer type given its pointee type.
519 ///
Mike Stump11289f42009-09-09 15:08:12 +0000520 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000522 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523
John McCall70dd5f62009-10-30 00:06:24 +0000524 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 ///
John McCall70dd5f62009-10-30 00:06:24 +0000526 /// By default, performs semantic analysis when building the
527 /// reference type. Subclasses may override this routine to provide
528 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 ///
John McCall70dd5f62009-10-30 00:06:24 +0000530 /// \param LValue whether the type was written with an lvalue sigil
531 /// or an rvalue sigil.
532 QualType RebuildReferenceType(QualType ReferentType,
533 bool LValue,
534 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// \brief Build a new member pointer type given the pointee type and the
537 /// class type it refers into.
538 ///
539 /// By default, performs semantic analysis when building the member pointer
540 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000541 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
542 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000543
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 /// \brief Build a new array type given the element type, size
545 /// modifier, size of the array (if known), size expression, and index type
546 /// qualifiers.
547 ///
548 /// By default, performs semantic analysis when building the array type.
549 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000550 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000551 QualType RebuildArrayType(QualType ElementType,
552 ArrayType::ArraySizeModifier SizeMod,
553 const llvm::APInt *Size,
554 Expr *SizeExpr,
555 unsigned IndexTypeQuals,
556 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000557
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558 /// \brief Build a new constant array type given the element type, size
559 /// modifier, (known) size of the array, and index type qualifiers.
560 ///
561 /// By default, performs semantic analysis when building the array type.
562 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000563 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ArrayType::ArraySizeModifier SizeMod,
565 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000566 unsigned IndexTypeQuals,
567 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568
Douglas Gregord6ff3322009-08-04 16:50:30 +0000569 /// \brief Build a new incomplete array type given the element type, size
570 /// modifier, and index type qualifiers.
571 ///
572 /// By default, performs semantic analysis when building the array type.
573 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000574 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000575 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000576 unsigned IndexTypeQuals,
577 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578
Mike Stump11289f42009-09-09 15:08:12 +0000579 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000580 /// size modifier, size expression, and index type qualifiers.
581 ///
582 /// By default, performs semantic analysis when building the array type.
583 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000584 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000585 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000586 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000587 unsigned IndexTypeQuals,
588 SourceRange BracketsRange);
589
Mike Stump11289f42009-09-09 15:08:12 +0000590 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000591 /// size modifier, size expression, and index type qualifiers.
592 ///
593 /// By default, performs semantic analysis when building the array type.
594 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000595 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000596 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000597 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000598 unsigned IndexTypeQuals,
599 SourceRange BracketsRange);
600
601 /// \brief Build a new vector type given the element type and
602 /// number of elements.
603 ///
604 /// By default, performs semantic analysis when building the vector type.
605 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000606 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000607 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000608
Douglas Gregord6ff3322009-08-04 16:50:30 +0000609 /// \brief Build a new extended vector type given the element type and
610 /// number of elements.
611 ///
612 /// By default, performs semantic analysis when building the vector type.
613 /// Subclasses may override this routine to provide different behavior.
614 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
615 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000616
617 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000618 /// given the element type and number of elements.
619 ///
620 /// By default, performs semantic analysis when building the vector type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000622 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000623 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000624 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000625
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// \brief Build a new function type.
627 ///
628 /// By default, performs semantic analysis when building the function type.
629 /// Subclasses may override this routine to provide different behavior.
630 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000631 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000633 bool Variadic, unsigned Quals,
634 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000635
John McCall550e0c22009-10-21 00:40:46 +0000636 /// \brief Build a new unprototyped function type.
637 QualType RebuildFunctionNoProtoType(QualType ResultType);
638
John McCallb96ec562009-12-04 22:46:56 +0000639 /// \brief Rebuild an unresolved typename type, given the decl that
640 /// the UnresolvedUsingTypenameDecl was transformed to.
641 QualType RebuildUnresolvedUsingType(Decl *D);
642
Douglas Gregord6ff3322009-08-04 16:50:30 +0000643 /// \brief Build a new typedef type.
644 QualType RebuildTypedefType(TypedefDecl *Typedef) {
645 return SemaRef.Context.getTypeDeclType(Typedef);
646 }
647
648 /// \brief Build a new class/struct/union type.
649 QualType RebuildRecordType(RecordDecl *Record) {
650 return SemaRef.Context.getTypeDeclType(Record);
651 }
652
653 /// \brief Build a new Enum type.
654 QualType RebuildEnumType(EnumDecl *Enum) {
655 return SemaRef.Context.getTypeDeclType(Enum);
656 }
John McCallfcc33b02009-09-05 00:15:47 +0000657
Mike Stump11289f42009-09-09 15:08:12 +0000658 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 ///
660 /// By default, performs semantic analysis when building the typeof type.
661 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000662 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663
Mike Stump11289f42009-09-09 15:08:12 +0000664 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000665 ///
666 /// By default, builds a new TypeOfType with the given underlying type.
667 QualType RebuildTypeOfType(QualType Underlying);
668
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 ///
671 /// By default, performs semantic analysis when building the decltype type.
672 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000673 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000674
Douglas Gregord6ff3322009-08-04 16:50:30 +0000675 /// \brief Build a new template specialization type.
676 ///
677 /// By default, performs semantic analysis when building the template
678 /// specialization type. Subclasses may override this routine to provide
679 /// different behavior.
680 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000681 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000682 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000683
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000684 /// \brief Build a new parenthesized type.
685 ///
686 /// By default, builds a new ParenType type from the inner type.
687 /// Subclasses may override this routine to provide different behavior.
688 QualType RebuildParenType(QualType InnerType) {
689 return SemaRef.Context.getParenType(InnerType);
690 }
691
Douglas Gregord6ff3322009-08-04 16:50:30 +0000692 /// \brief Build a new qualified name type.
693 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000694 /// By default, builds a new ElaboratedType type from the keyword,
695 /// the nested-name-specifier and the named type.
696 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000697 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
698 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000699 NestedNameSpecifier *NNS, QualType Named) {
700 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000701 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702
703 /// \brief Build a new typename type that refers to a template-id.
704 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000705 /// By default, builds a new DependentNameType type from the
706 /// nested-name-specifier and the given type. Subclasses may override
707 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000708 QualType RebuildDependentTemplateSpecializationType(
709 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000710 NestedNameSpecifier *Qualifier,
711 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000712 const IdentifierInfo *Name,
713 SourceLocation NameLoc,
714 const TemplateArgumentListInfo &Args) {
715 // Rebuild the template name.
716 // TODO: avoid TemplateName abstraction
717 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000718 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000719 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000720
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000721 if (InstName.isNull())
722 return QualType();
723
John McCallc392f372010-06-11 00:33:02 +0000724 // If it's still dependent, make a dependent specialization.
725 if (InstName.getAsDependentTemplateName())
726 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000727 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000728
729 // Otherwise, make an elaborated type wrapping a non-dependent
730 // specialization.
731 QualType T =
732 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
733 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000734
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000735 // NOTE: NNS is already recorded in template specialization type T.
736 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000737 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
739 /// \brief Build a new typename type that refers to an identifier.
740 ///
741 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000742 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000743 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000744 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000745 NestedNameSpecifier *NNS,
746 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000747 SourceLocation KeywordLoc,
748 SourceRange NNSRange,
749 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000750 CXXScopeSpec SS;
751 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000752 SS.setRange(NNSRange);
753
Douglas Gregore677daf2010-03-31 22:19:08 +0000754 if (NNS->isDependent()) {
755 // If the name is still dependent, just build a new dependent name type.
756 if (!SemaRef.computeDeclContext(SS))
757 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
758 }
759
Abramo Bagnara6150c882010-05-11 21:36:43 +0000760 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000761 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
762 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000763
764 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
765
Abramo Bagnarad7548482010-05-19 21:37:53 +0000766 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000767 // into a non-dependent elaborated-type-specifier. Find the tag we're
768 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000769 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000770 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
771 if (!DC)
772 return QualType();
773
John McCallbf8c5192010-05-27 06:40:31 +0000774 if (SemaRef.RequireCompleteDeclContext(SS, DC))
775 return QualType();
776
Douglas Gregore677daf2010-03-31 22:19:08 +0000777 TagDecl *Tag = 0;
778 SemaRef.LookupQualifiedName(Result, DC);
779 switch (Result.getResultKind()) {
780 case LookupResult::NotFound:
781 case LookupResult::NotFoundInCurrentInstantiation:
782 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000783
Douglas Gregore677daf2010-03-31 22:19:08 +0000784 case LookupResult::Found:
785 Tag = Result.getAsSingle<TagDecl>();
786 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000787
Douglas Gregore677daf2010-03-31 22:19:08 +0000788 case LookupResult::FoundOverloaded:
789 case LookupResult::FoundUnresolvedValue:
790 llvm_unreachable("Tag lookup cannot find non-tags");
791 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000792
Douglas Gregore677daf2010-03-31 22:19:08 +0000793 case LookupResult::Ambiguous:
794 // Let the LookupResult structure handle ambiguities.
795 return QualType();
796 }
797
798 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000799 // Check where the name exists but isn't a tag type and use that to emit
800 // better diagnostics.
801 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
802 SemaRef.LookupQualifiedName(Result, DC);
803 switch (Result.getResultKind()) {
804 case LookupResult::Found:
805 case LookupResult::FoundOverloaded:
806 case LookupResult::FoundUnresolvedValue: {
807 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
808 unsigned Kind = 0;
809 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
810 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
811 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
812 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
813 break;
814 }
815 default:
816 // FIXME: Would be nice to highlight just the source range.
817 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
818 << Kind << Id << DC;
819 break;
820 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000821 return QualType();
822 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000823
Abramo Bagnarad7548482010-05-19 21:37:53 +0000824 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
825 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000826 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
827 return QualType();
828 }
829
830 // Build the elaborated-type-specifier type.
831 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000832 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000833 }
Mike Stump11289f42009-09-09 15:08:12 +0000834
Douglas Gregor822d0302011-01-12 17:07:58 +0000835 /// \brief Build a new pack expansion type.
836 ///
837 /// By default, builds a new PackExpansionType type from the given pattern.
838 /// Subclasses may override this routine to provide different behavior.
839 QualType RebuildPackExpansionType(QualType Pattern,
840 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000841 SourceLocation EllipsisLoc,
842 llvm::Optional<unsigned> NumExpansions) {
843 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
844 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000845 }
846
Douglas Gregor1135c352009-08-06 05:28:30 +0000847 /// \brief Build a new nested-name-specifier given the prefix and an
848 /// identifier that names the next step in the nested-name-specifier.
849 ///
850 /// By default, performs semantic analysis when building the new
851 /// nested-name-specifier. Subclasses may override this routine to provide
852 /// different behavior.
853 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
854 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000855 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000856 QualType ObjectType,
857 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000858
859 /// \brief Build a new nested-name-specifier given the prefix and the
860 /// namespace named in the next step in the nested-name-specifier.
861 ///
862 /// By default, performs semantic analysis when building the new
863 /// nested-name-specifier. Subclasses may override this routine to provide
864 /// different behavior.
865 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
866 SourceRange Range,
867 NamespaceDecl *NS);
868
869 /// \brief Build a new nested-name-specifier given the prefix and the
870 /// type named in the next step in the nested-name-specifier.
871 ///
872 /// By default, performs semantic analysis when building the new
873 /// nested-name-specifier. Subclasses may override this routine to provide
874 /// different behavior.
875 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
876 SourceRange Range,
877 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000878 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000879
880 /// \brief Build a new template name given a nested name specifier, a flag
881 /// indicating whether the "template" keyword was provided, and the template
882 /// that the template name refers to.
883 ///
884 /// By default, builds the new template name directly. Subclasses may override
885 /// this routine to provide different behavior.
886 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
887 bool TemplateKW,
888 TemplateDecl *Template);
889
Douglas Gregor71dc5092009-08-06 06:41:21 +0000890 /// \brief Build a new template name given a nested name specifier and the
891 /// name that is referred to as a template.
892 ///
893 /// By default, performs semantic analysis to determine whether the name can
894 /// be resolved to a specific template, then builds the appropriate kind of
895 /// template name. Subclasses may override this routine to provide different
896 /// behavior.
897 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000898 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000899 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000900 QualType ObjectType,
901 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000902
Douglas Gregor71395fa2009-11-04 00:56:37 +0000903 /// \brief Build a new template name given a nested name specifier and the
904 /// overloaded operator name that is referred to as a template.
905 ///
906 /// By default, performs semantic analysis to determine whether the name can
907 /// be resolved to a specific template, then builds the appropriate kind of
908 /// template name. Subclasses may override this routine to provide different
909 /// behavior.
910 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
911 OverloadedOperatorKind Operator,
912 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000913
914 /// \brief Build a new template name given a template template parameter pack
915 /// and the
916 ///
917 /// By default, performs semantic analysis to determine whether the name can
918 /// be resolved to a specific template, then builds the appropriate kind of
919 /// template name. Subclasses may override this routine to provide different
920 /// behavior.
921 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
922 const TemplateArgument &ArgPack) {
923 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
924 }
925
Douglas Gregorebe10102009-08-20 07:17:43 +0000926 /// \brief Build a new compound statement.
927 ///
928 /// By default, performs semantic analysis to build the new statement.
929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000930 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000931 MultiStmtArg Statements,
932 SourceLocation RBraceLoc,
933 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000934 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000935 IsStmtExpr);
936 }
937
938 /// \brief Build a new case statement.
939 ///
940 /// By default, performs semantic analysis to build the new statement.
941 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000942 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000943 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000944 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000945 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000946 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000947 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000948 ColonLoc);
949 }
Mike Stump11289f42009-09-09 15:08:12 +0000950
Douglas Gregorebe10102009-08-20 07:17:43 +0000951 /// \brief Attach the body to a new case statement.
952 ///
953 /// By default, performs semantic analysis to build the new statement.
954 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000955 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000956 getSema().ActOnCaseStmtBody(S, Body);
957 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000958 }
Mike Stump11289f42009-09-09 15:08:12 +0000959
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 /// \brief Build a new default statement.
961 ///
962 /// By default, performs semantic analysis to build the new statement.
963 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000964 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000965 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000966 Stmt *SubStmt) {
967 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000968 /*CurScope=*/0);
969 }
Mike Stump11289f42009-09-09 15:08:12 +0000970
Douglas Gregorebe10102009-08-20 07:17:43 +0000971 /// \brief Build a new label statement.
972 ///
973 /// By default, performs semantic analysis to build the new statement.
974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000975 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000976 IdentifierInfo *Id,
977 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000978 Stmt *SubStmt, bool HasUnusedAttr) {
979 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
980 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 }
Mike Stump11289f42009-09-09 15:08:12 +0000982
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 /// \brief Build a new "if" statement.
984 ///
985 /// By default, performs semantic analysis to build the new statement.
986 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000987 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000988 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000989 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000990 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 }
Mike Stump11289f42009-09-09 15:08:12 +0000992
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 /// \brief Start building a new switch statement.
994 ///
995 /// By default, performs semantic analysis to build the new statement.
996 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000997 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000998 Expr *Cond, VarDecl *CondVar) {
999 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001000 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 }
Mike Stump11289f42009-09-09 15:08:12 +00001002
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 /// \brief Attach the body to the switch statement.
1004 ///
1005 /// By default, performs semantic analysis to build the new statement.
1006 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001007 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +00001008 Stmt *Switch, Stmt *Body) {
1009 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 }
1011
1012 /// \brief Build a new while statement.
1013 ///
1014 /// By default, performs semantic analysis to build the new statement.
1015 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001016 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00001017 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001018 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +00001019 Stmt *Body) {
1020 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 }
Mike Stump11289f42009-09-09 15:08:12 +00001022
Douglas Gregorebe10102009-08-20 07:17:43 +00001023 /// \brief Build a new do-while statement.
1024 ///
1025 /// By default, performs semantic analysis to build the new statement.
1026 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001027 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +00001028 SourceLocation WhileLoc,
1029 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001030 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001032 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1033 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001034 }
1035
1036 /// \brief Build a new for statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001040 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001041 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001042 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001043 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +00001044 SourceLocation RParenLoc, Stmt *Body) {
1045 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +00001046 CondVar,
John McCallb268a282010-08-23 23:25:46 +00001047 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 }
Mike Stump11289f42009-09-09 15:08:12 +00001049
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 /// \brief Build a new goto statement.
1051 ///
1052 /// By default, performs semantic analysis to build the new statement.
1053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001054 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001055 SourceLocation LabelLoc,
1056 LabelStmt *Label) {
1057 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1058 }
1059
1060 /// \brief Build a new indirect goto statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001064 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001065 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +00001066 Expr *Target) {
1067 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new return statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001074 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +00001075 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +00001076
John McCallb268a282010-08-23 23:25:46 +00001077 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001078 }
Mike Stump11289f42009-09-09 15:08:12 +00001079
Douglas Gregorebe10102009-08-20 07:17:43 +00001080 /// \brief Build a new declaration statement.
1081 ///
1082 /// By default, performs semantic analysis to build the new statement.
1083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001084 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001085 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001086 SourceLocation EndLoc) {
1087 return getSema().Owned(
1088 new (getSema().Context) DeclStmt(
1089 DeclGroupRef::Create(getSema().Context,
1090 Decls, NumDecls),
1091 StartLoc, EndLoc));
1092 }
Mike Stump11289f42009-09-09 15:08:12 +00001093
Anders Carlssonaaeef072010-01-24 05:50:09 +00001094 /// \brief Build a new inline asm statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001098 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001099 bool IsSimple,
1100 bool IsVolatile,
1101 unsigned NumOutputs,
1102 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001103 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001104 MultiExprArg Constraints,
1105 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001106 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001107 MultiExprArg Clobbers,
1108 SourceLocation RParenLoc,
1109 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001110 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001111 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001112 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 RParenLoc, MSAsm);
1114 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001115
1116 /// \brief Build a new Objective-C @try statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001120 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001121 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001122 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001123 Stmt *Finally) {
1124 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1125 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001126 }
1127
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001128 /// \brief Rebuild an Objective-C exception declaration.
1129 ///
1130 /// By default, performs semantic analysis to build the new declaration.
1131 /// Subclasses may override this routine to provide different behavior.
1132 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1133 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001134 return getSema().BuildObjCExceptionDecl(TInfo, T,
1135 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001136 ExceptionDecl->getLocation());
1137 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001138
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001139 /// \brief Build a new Objective-C @catch statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001143 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001144 SourceLocation RParenLoc,
1145 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001146 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001147 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001149 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001150
Douglas Gregor306de2f2010-04-22 23:59:56 +00001151 /// \brief Build a new Objective-C @finally statement.
1152 ///
1153 /// By default, performs semantic analysis to build the new statement.
1154 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001155 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001156 Stmt *Body) {
1157 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001159
Douglas Gregor6148de72010-04-22 22:01:21 +00001160 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001165 Expr *Operand) {
1166 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001167 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001168
Douglas Gregor6148de72010-04-22 22:01:21 +00001169 /// \brief Build a new Objective-C @synchronized statement.
1170 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001171 /// By default, performs semantic analysis to build the new statement.
1172 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001173 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001174 Expr *Object,
1175 Stmt *Body) {
1176 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1177 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001178 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001179
1180 /// \brief Build a new Objective-C fast enumeration statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001185 SourceLocation LParenLoc,
1186 Stmt *Element,
1187 Expr *Collection,
1188 SourceLocation RParenLoc,
1189 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001190 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001191 Element,
1192 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001193 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001194 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001195 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001196
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 /// \brief Build a new C++ exception declaration.
1198 ///
1199 /// By default, performs semantic analysis to build the new decaration.
1200 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001201 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001202 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001203 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001204 SourceLocation Loc) {
1205 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001206 }
1207
1208 /// \brief Build a new C++ catch statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001212 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001213 VarDecl *ExceptionDecl,
1214 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001215 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1216 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 /// \brief Build a new C++ try statement.
1220 ///
1221 /// By default, performs semantic analysis to build the new statement.
1222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001223 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001224 Stmt *TryBlock,
1225 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001226 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new expression that references a declaration.
1230 ///
1231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001233 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001234 LookupResult &R,
1235 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001236 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1237 }
1238
1239
1240 /// \brief Build a new expression that references a declaration.
1241 ///
1242 /// By default, performs semantic analysis to build the new expression.
1243 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001244 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001245 SourceRange QualifierRange,
1246 ValueDecl *VD,
1247 const DeclarationNameInfo &NameInfo,
1248 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001249 CXXScopeSpec SS;
1250 SS.setScopeRep(Qualifier);
1251 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001252
1253 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001254
1255 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001259 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001262 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001264 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 }
1266
Douglas Gregorad8a3362009-09-04 17:36:40 +00001267 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001268 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001271 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001272 SourceLocation OperatorLoc,
1273 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001274 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001275 SourceRange QualifierRange,
1276 TypeSourceInfo *ScopeType,
1277 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001278 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001279 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001280
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001282 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// By default, performs semantic analysis to build the new expression.
1284 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001285 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001286 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001287 Expr *SubExpr) {
1288 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 }
Mike Stump11289f42009-09-09 15:08:12 +00001290
Douglas Gregor882211c2010-04-28 22:16:22 +00001291 /// \brief Build a new builtin offsetof expression.
1292 ///
1293 /// By default, performs semantic analysis to build the new expression.
1294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001295 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001296 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001297 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001298 unsigned NumComponents,
1299 SourceLocation RParenLoc) {
1300 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1301 NumComponents, RParenLoc);
1302 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001303
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001305 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001308 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001309 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001311 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 }
1313
Mike Stump11289f42009-09-09 15:08:12 +00001314 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001316 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001319 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001321 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001322 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001325
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 return move(Result);
1327 }
Mike Stump11289f42009-09-09 15:08:12 +00001328
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001330 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// By default, performs semantic analysis to build the new expression.
1332 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001333 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001335 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001337 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1338 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 RBracketLoc);
1340 }
1341
1342 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001343 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001346 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001349 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001350 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 }
1352
1353 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001354 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001358 bool isArrow,
1359 NestedNameSpecifier *Qualifier,
1360 SourceRange QualifierRange,
1361 const DeclarationNameInfo &MemberNameInfo,
1362 ValueDecl *Member,
1363 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001364 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001365 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001366 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001367 // We have a reference to an unnamed field. This is always the
1368 // base of an anonymous struct/union member access, i.e. the
1369 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001370 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001371 assert(Member->getType()->isRecordType() &&
1372 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001373
John McCallb268a282010-08-23 23:25:46 +00001374 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001375 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001376 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001377
John McCall7decc9e2010-11-18 06:31:45 +00001378 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001379 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001380 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001381 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001382 cast<FieldDecl>(Member)->getType(),
1383 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001384 return getSema().Owned(ME);
1385 }
Mike Stump11289f42009-09-09 15:08:12 +00001386
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001387 CXXScopeSpec SS;
1388 if (Qualifier) {
1389 SS.setRange(QualifierRange);
1390 SS.setScopeRep(Qualifier);
1391 }
1392
John McCallb268a282010-08-23 23:25:46 +00001393 getSema().DefaultFunctionArrayConversion(Base);
1394 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001395
John McCall16df1e52010-03-30 21:47:33 +00001396 // FIXME: this involves duplicating earlier analysis in a lot of
1397 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001398 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001399 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001400 R.resolveKind();
1401
John McCallb268a282010-08-23 23:25:46 +00001402 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001403 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001404 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 }
Mike Stump11289f42009-09-09 15:08:12 +00001406
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001411 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001412 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001413 Expr *LHS, Expr *RHS) {
1414 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 }
1416
1417 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001418 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001421 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001423 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001425 Expr *RHS) {
1426 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1427 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 }
1429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001431 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001434 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001437 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001438 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001439 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
Mike Stump11289f42009-09-09 15:08:12 +00001441
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001443 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001446 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001447 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001450 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 }
Mike Stump11289f42009-09-09 15:08:12 +00001453
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001455 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001458 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 SourceLocation OpLoc,
1460 SourceLocation AccessorLoc,
1461 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001462
John McCall10eae182009-11-30 22:42:35 +00001463 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001464 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001465 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001466 OpLoc, /*IsArrow*/ false,
1467 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001468 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001469 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
Mike Stump11289f42009-09-09 15:08:12 +00001471
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001473 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 SourceLocation RBraceLoc,
1479 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001480 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001481 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1482 if (Result.isInvalid() || ResultTy->isDependentType())
1483 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001484
Douglas Gregord3d93062009-11-09 17:16:50 +00001485 // Patch in the result type we were given, which may have been computed
1486 // when the initial InitListExpr was built.
1487 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1488 ILE->setType(ResultTy);
1489 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001493 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001496 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 MultiExprArg ArrayExprs,
1498 SourceLocation EqualOrColonLoc,
1499 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001500 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001501 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001503 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 ArrayExprs.release();
1508 return move(Result);
1509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001512 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// By default, builds the implicit value initialization without performing
1514 /// any semantic analysis. Subclasses may override this routine to provide
1515 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001516 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001521 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001526 SourceLocation RParenLoc) {
1527 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001529 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
1531
1532 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001533 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001536 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 MultiExprArg SubExprs,
1538 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001539 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001540 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
1545 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// rather than attempting to map the label statement itself.
1547 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001548 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 SourceLocation LabelLoc,
1550 LabelStmt *Label) {
1551 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1552 }
Mike Stump11289f42009-09-09 15:08:12 +00001553
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001555 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001559 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001561 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 }
Mike Stump11289f42009-09-09 15:08:12 +00001563
Douglas Gregora16548e2009-08-11 05:31:07 +00001564 /// \brief Build a new __builtin_choose_expr expression.
1565 ///
1566 /// By default, performs semantic analysis to build the new expression.
1567 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001568 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001569 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 SourceLocation RParenLoc) {
1571 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001572 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 RParenLoc);
1574 }
Mike Stump11289f42009-09-09 15:08:12 +00001575
Douglas Gregora16548e2009-08-11 05:31:07 +00001576 /// \brief Build a new overloaded operator call expression.
1577 ///
1578 /// By default, performs semantic analysis to build the new expression.
1579 /// The semantic analysis provides the behavior of template instantiation,
1580 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001581 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 /// argument-dependent lookup, etc. Subclasses may override this routine to
1583 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001584 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001586 Expr *Callee,
1587 Expr *First,
1588 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001589
1590 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// reinterpret_cast.
1592 ///
1593 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001594 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001596 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001597 Stmt::StmtClass Class,
1598 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001599 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 SourceLocation RAngleLoc,
1601 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001602 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation RParenLoc) {
1604 switch (Class) {
1605 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001606 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001607 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001608 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001609
1610 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001611 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001612 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001613 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001614
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001616 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001617 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001618 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001622 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001623 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001624 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 default:
1627 assert(false && "Invalid C++ named cast");
1628 break;
1629 }
Mike Stump11289f42009-09-09 15:08:12 +00001630
John McCallfaf5fb42010-08-26 23:41:50 +00001631 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 }
Mike Stump11289f42009-09-09 15:08:12 +00001633
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 /// \brief Build a new C++ static_cast expression.
1635 ///
1636 /// By default, performs semantic analysis to build the new expression.
1637 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001638 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001640 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 SourceLocation RAngleLoc,
1642 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001643 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001645 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001646 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001647 SourceRange(LAngleLoc, RAngleLoc),
1648 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 }
1650
1651 /// \brief Build a new C++ dynamic_cast expression.
1652 ///
1653 /// By default, performs semantic analysis to build the new expression.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001657 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 SourceLocation RAngleLoc,
1659 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001660 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001662 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001663 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001664 SourceRange(LAngleLoc, RAngleLoc),
1665 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 }
1667
1668 /// \brief Build a new C++ reinterpret_cast expression.
1669 ///
1670 /// By default, performs semantic analysis to build the new expression.
1671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001672 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001674 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 SourceLocation RAngleLoc,
1676 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001677 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001679 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001680 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001681 SourceRange(LAngleLoc, RAngleLoc),
1682 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001683 }
1684
1685 /// \brief Build a new C++ const_cast expression.
1686 ///
1687 /// By default, performs semantic analysis to build the new expression.
1688 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001689 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001691 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 SourceLocation RAngleLoc,
1693 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001694 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001696 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001697 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001698 SourceRange(LAngleLoc, RAngleLoc),
1699 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001700 }
Mike Stump11289f42009-09-09 15:08:12 +00001701
Douglas Gregora16548e2009-08-11 05:31:07 +00001702 /// \brief Build a new C++ functional-style cast expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001706 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1707 SourceLocation LParenLoc,
1708 Expr *Sub,
1709 SourceLocation RParenLoc) {
1710 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001711 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 RParenLoc);
1713 }
Mike Stump11289f42009-09-09 15:08:12 +00001714
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 /// \brief Build a new C++ typeid(type) expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001719 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001720 SourceLocation TypeidLoc,
1721 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001722 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001723 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001724 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 }
Mike Stump11289f42009-09-09 15:08:12 +00001726
Francois Pichet9f4f2072010-09-08 12:20:18 +00001727
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 /// \brief Build a new C++ typeid(expr) expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001732 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001733 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001734 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001736 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001737 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001738 }
1739
Francois Pichet9f4f2072010-09-08 12:20:18 +00001740 /// \brief Build a new C++ __uuidof(type) expression.
1741 ///
1742 /// By default, performs semantic analysis to build the new expression.
1743 /// Subclasses may override this routine to provide different behavior.
1744 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1745 SourceLocation TypeidLoc,
1746 TypeSourceInfo *Operand,
1747 SourceLocation RParenLoc) {
1748 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1749 RParenLoc);
1750 }
1751
1752 /// \brief Build a new C++ __uuidof(expr) expression.
1753 ///
1754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
1756 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1757 SourceLocation TypeidLoc,
1758 Expr *Operand,
1759 SourceLocation RParenLoc) {
1760 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1761 RParenLoc);
1762 }
1763
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// \brief Build a new C++ "this" expression.
1765 ///
1766 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001767 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001769 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001770 QualType ThisType,
1771 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001773 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1774 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ throw expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001781 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001782 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001783 }
1784
1785 /// \brief Build a new C++ default-argument expression.
1786 ///
1787 /// By default, builds a new default-argument expression, which does not
1788 /// require any semantic analysis. Subclasses may override this routine to
1789 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001790 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001791 ParmVarDecl *Param) {
1792 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1793 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 }
1795
1796 /// \brief Build a new C++ zero-initialization expression.
1797 ///
1798 /// By default, performs semantic analysis to build the new expression.
1799 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001800 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1801 SourceLocation LParenLoc,
1802 SourceLocation RParenLoc) {
1803 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001804 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001805 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001806 }
Mike Stump11289f42009-09-09 15:08:12 +00001807
Douglas Gregora16548e2009-08-11 05:31:07 +00001808 /// \brief Build a new C++ "new" expression.
1809 ///
1810 /// By default, performs semantic analysis to build the new expression.
1811 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001812 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001813 bool UseGlobal,
1814 SourceLocation PlacementLParen,
1815 MultiExprArg PlacementArgs,
1816 SourceLocation PlacementRParen,
1817 SourceRange TypeIdParens,
1818 QualType AllocatedType,
1819 TypeSourceInfo *AllocatedTypeInfo,
1820 Expr *ArraySize,
1821 SourceLocation ConstructorLParen,
1822 MultiExprArg ConstructorArgs,
1823 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001824 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 PlacementLParen,
1826 move(PlacementArgs),
1827 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001828 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001829 AllocatedType,
1830 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001831 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001832 ConstructorLParen,
1833 move(ConstructorArgs),
1834 ConstructorRParen);
1835 }
Mike Stump11289f42009-09-09 15:08:12 +00001836
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 /// \brief Build a new C++ "delete" expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001841 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001842 bool IsGlobalDelete,
1843 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001844 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001846 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001847 }
Mike Stump11289f42009-09-09 15:08:12 +00001848
Douglas Gregora16548e2009-08-11 05:31:07 +00001849 /// \brief Build a new unary type trait expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001853 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001854 SourceLocation StartLoc,
1855 TypeSourceInfo *T,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 }
1859
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001860 /// \brief Build a new binary type trait expression.
1861 ///
1862 /// By default, performs semantic analysis to build the new expression.
1863 /// Subclasses may override this routine to provide different behavior.
1864 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1865 SourceLocation StartLoc,
1866 TypeSourceInfo *LhsT,
1867 TypeSourceInfo *RhsT,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1870 }
1871
Mike Stump11289f42009-09-09 15:08:12 +00001872 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 /// expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001877 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001879 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001880 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001881 CXXScopeSpec SS;
1882 SS.setRange(QualifierRange);
1883 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001884
1885 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001886 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001887 *TemplateArgs);
1888
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001889 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 }
1891
1892 /// \brief Build a new template-id expression.
1893 ///
1894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001896 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001897 LookupResult &R,
1898 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001899 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001900 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 }
1902
1903 /// \brief Build a new object-construction expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001907 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001908 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 CXXConstructorDecl *Constructor,
1910 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001911 MultiExprArg Args,
1912 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001913 CXXConstructExpr::ConstructionKind ConstructKind,
1914 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001915 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001916 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001917 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001918 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001919
Douglas Gregordb121ba2009-12-14 16:27:04 +00001920 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001921 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001922 RequiresZeroInit, ConstructKind,
1923 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 }
1925
1926 /// \brief Build a new object-construction expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001930 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1931 SourceLocation LParenLoc,
1932 MultiExprArg Args,
1933 SourceLocation RParenLoc) {
1934 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 LParenLoc,
1936 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001937 RParenLoc);
1938 }
1939
1940 /// \brief Build a new object-construction expression.
1941 ///
1942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001944 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1945 SourceLocation LParenLoc,
1946 MultiExprArg Args,
1947 SourceLocation RParenLoc) {
1948 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 LParenLoc,
1950 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 RParenLoc);
1952 }
Mike Stump11289f42009-09-09 15:08:12 +00001953
Douglas Gregora16548e2009-08-11 05:31:07 +00001954 /// \brief Build a new member reference expression.
1955 ///
1956 /// By default, performs semantic analysis to build the new expression.
1957 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001958 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001959 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 bool IsArrow,
1961 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001962 NestedNameSpecifier *Qualifier,
1963 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001964 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001965 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001966 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001967 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001968 SS.setRange(QualifierRange);
1969 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001970
John McCallb268a282010-08-23 23:25:46 +00001971 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001972 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001973 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001974 MemberNameInfo,
1975 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 }
1977
John McCall10eae182009-11-30 22:42:35 +00001978 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001979 ///
1980 /// By default, performs semantic analysis to build the new expression.
1981 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001982 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001983 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001984 SourceLocation OperatorLoc,
1985 bool IsArrow,
1986 NestedNameSpecifier *Qualifier,
1987 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001988 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001989 LookupResult &R,
1990 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001991 CXXScopeSpec SS;
1992 SS.setRange(QualifierRange);
1993 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001994
John McCallb268a282010-08-23 23:25:46 +00001995 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001996 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001997 SS, FirstQualifierInScope,
1998 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001999 }
Mike Stump11289f42009-09-09 15:08:12 +00002000
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002001 /// \brief Build a new noexcept expression.
2002 ///
2003 /// By default, performs semantic analysis to build the new expression.
2004 /// Subclasses may override this routine to provide different behavior.
2005 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2006 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2007 }
2008
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002009 /// \brief Build a new expression to compute the length of a parameter pack.
2010 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2011 SourceLocation PackLoc,
2012 SourceLocation RParenLoc,
2013 unsigned Length) {
2014 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2015 OperatorLoc, Pack, PackLoc,
2016 RParenLoc, Length);
2017 }
2018
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// \brief Build a new Objective-C @encode expression.
2020 ///
2021 /// By default, performs semantic analysis to build the new expression.
2022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002023 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002024 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002025 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002026 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002028 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002029
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002030 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002031 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002032 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002033 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002034 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002035 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002036 MultiExprArg Args,
2037 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002038 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2039 ReceiverTypeInfo->getType(),
2040 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002041 Sel, Method, LBracLoc, SelectorLoc,
2042 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 }
2044
2045 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002046 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002048 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002049 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002050 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002051 MultiExprArg Args,
2052 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002053 return SemaRef.BuildInstanceMessage(Receiver,
2054 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002055 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002056 Sel, Method, LBracLoc, SelectorLoc,
2057 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002058 }
2059
Douglas Gregord51d90d2010-04-26 20:11:03 +00002060 /// \brief Build a new Objective-C ivar reference expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002065 SourceLocation IvarLoc,
2066 bool IsArrow, bool IsFreeIvar) {
2067 // FIXME: We lose track of the IsFreeIvar bit.
2068 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002069 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002070 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2071 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002072 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002073 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002074 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002075 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002076 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002077 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002078
Douglas Gregord51d90d2010-04-26 20:11:03 +00002079 if (Result.get())
2080 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002081
John McCallb268a282010-08-23 23:25:46 +00002082 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002083 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002084 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002085 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002086 /*TemplateArgs=*/0);
2087 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002088
2089 /// \brief Build a new Objective-C property reference expression.
2090 ///
2091 /// By default, performs semantic analysis to build the new expression.
2092 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002094 ObjCPropertyDecl *Property,
2095 SourceLocation PropertyLoc) {
2096 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002097 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002098 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2099 Sema::LookupMemberName);
2100 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002101 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002102 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002103 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002104 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002105 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002106
Douglas Gregor9faee212010-04-26 20:47:02 +00002107 if (Result.get())
2108 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002109
John McCallb268a282010-08-23 23:25:46 +00002110 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002111 /*FIXME:*/PropertyLoc, IsArrow,
2112 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002113 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002114 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002115 /*TemplateArgs=*/0);
2116 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002117
John McCallb7bd14f2010-12-02 01:19:52 +00002118 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002119 ///
2120 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002121 /// Subclasses may override this routine to provide different behavior.
2122 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2123 ObjCMethodDecl *Getter,
2124 ObjCMethodDecl *Setter,
2125 SourceLocation PropertyLoc) {
2126 // Since these expressions can only be value-dependent, we do not
2127 // need to perform semantic analysis again.
2128 return Owned(
2129 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2130 VK_LValue, OK_ObjCProperty,
2131 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002132 }
2133
Douglas Gregord51d90d2010-04-26 20:11:03 +00002134 /// \brief Build a new Objective-C "isa" expression.
2135 ///
2136 /// By default, performs semantic analysis to build the new expression.
2137 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002138 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002139 bool IsArrow) {
2140 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002141 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002142 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2143 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002144 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002145 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002146 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002147 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002148 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002149
Douglas Gregord51d90d2010-04-26 20:11:03 +00002150 if (Result.get())
2151 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002152
John McCallb268a282010-08-23 23:25:46 +00002153 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002154 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002155 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002156 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002157 /*TemplateArgs=*/0);
2158 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002159
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// \brief Build a new shuffle vector expression.
2161 ///
2162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002164 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002165 MultiExprArg SubExprs,
2166 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002167 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002168 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2170 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2171 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2172 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002173
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 // Build a reference to the __builtin_shufflevector builtin
2175 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002176 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002178 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002180
2181 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 unsigned NumSubExprs = SubExprs.size();
2183 Expr **Subs = (Expr **)SubExprs.release();
2184 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2185 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002186 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002187 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002189 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002190
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002197 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 }
John McCall31f82722010-11-12 08:19:04 +00002199
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002200 /// \brief Build a new template argument pack expansion.
2201 ///
2202 /// By default, performs semantic analysis to build a new pack expansion
2203 /// for a template argument. Subclasses may override this routine to provide
2204 /// different behavior.
2205 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002206 SourceLocation EllipsisLoc,
2207 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002208 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002209 case TemplateArgument::Expression: {
2210 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002211 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2212 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002213 if (Result.isInvalid())
2214 return TemplateArgumentLoc();
2215
2216 return TemplateArgumentLoc(Result.get(), Result.get());
2217 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002218
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002219 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002220 return TemplateArgumentLoc(TemplateArgument(
2221 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002222 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002223 Pattern.getTemplateQualifierRange(),
2224 Pattern.getTemplateNameLoc(),
2225 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002226
2227 case TemplateArgument::Null:
2228 case TemplateArgument::Integral:
2229 case TemplateArgument::Declaration:
2230 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002231 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002232 llvm_unreachable("Pack expansion pattern has no parameter packs");
2233
2234 case TemplateArgument::Type:
2235 if (TypeSourceInfo *Expansion
2236 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002237 EllipsisLoc,
2238 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002239 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2240 Expansion);
2241 break;
2242 }
2243
2244 return TemplateArgumentLoc();
2245 }
2246
Douglas Gregor968f23a2011-01-03 19:31:53 +00002247 /// \brief Build a new expression pack expansion.
2248 ///
2249 /// By default, performs semantic analysis to build a new pack expansion
2250 /// for an expression. Subclasses may override this routine to provide
2251 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002252 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2253 llvm::Optional<unsigned> NumExpansions) {
2254 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002255 }
2256
John McCall31f82722010-11-12 08:19:04 +00002257private:
2258 QualType TransformTypeInObjectScope(QualType T,
2259 QualType ObjectType,
2260 NamedDecl *FirstQualifierInScope,
2261 NestedNameSpecifier *Prefix);
2262
2263 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2264 QualType ObjectType,
2265 NamedDecl *FirstQualifierInScope,
2266 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002267};
Douglas Gregora16548e2009-08-11 05:31:07 +00002268
Douglas Gregorebe10102009-08-20 07:17:43 +00002269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002270StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002271 if (!S)
2272 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002273
Douglas Gregorebe10102009-08-20 07:17:43 +00002274 switch (S->getStmtClass()) {
2275 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002276
Douglas Gregorebe10102009-08-20 07:17:43 +00002277 // Transform individual statement nodes
2278#define STMT(Node, Parent) \
2279 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2280#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002281#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregorebe10102009-08-20 07:17:43 +00002283 // Transform expressions by calling TransformExpr.
2284#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002285#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002286#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002287#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002288 {
John McCalldadc5752010-08-24 06:29:42 +00002289 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002290 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002291 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002292
John McCallb268a282010-08-23 23:25:46 +00002293 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002294 }
Mike Stump11289f42009-09-09 15:08:12 +00002295 }
2296
John McCallc3007a22010-10-26 07:05:15 +00002297 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002298}
Mike Stump11289f42009-09-09 15:08:12 +00002299
2300
Douglas Gregore922c772009-08-04 22:27:00 +00002301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002302ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 if (!E)
2304 return SemaRef.Owned(E);
2305
2306 switch (E->getStmtClass()) {
2307 case Stmt::NoStmtClass: break;
2308#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002309#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002310#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002311 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002312#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002313 }
2314
John McCallc3007a22010-10-26 07:05:15 +00002315 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002316}
2317
2318template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002319bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2320 unsigned NumInputs,
2321 bool IsCall,
2322 llvm::SmallVectorImpl<Expr *> &Outputs,
2323 bool *ArgChanged) {
2324 for (unsigned I = 0; I != NumInputs; ++I) {
2325 // If requested, drop call arguments that need to be dropped.
2326 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2327 if (ArgChanged)
2328 *ArgChanged = true;
2329
2330 break;
2331 }
2332
Douglas Gregor968f23a2011-01-03 19:31:53 +00002333 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2334 Expr *Pattern = Expansion->getPattern();
2335
2336 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2337 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2339
2340 // Determine whether the set of unexpanded parameter packs can and should
2341 // be expanded.
2342 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002343 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002344 llvm::Optional<unsigned> OrigNumExpansions
2345 = Expansion->getNumExpansions();
2346 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002347 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2348 Pattern->getSourceRange(),
2349 Unexpanded.data(),
2350 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002351 Expand, RetainExpansion,
2352 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002353 return true;
2354
2355 if (!Expand) {
2356 // The transform has determined that we should perform a simple
2357 // transformation on the pack expansion, producing another pack
2358 // expansion.
2359 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2360 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2361 if (OutPattern.isInvalid())
2362 return true;
2363
2364 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002365 Expansion->getEllipsisLoc(),
2366 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002367 if (Out.isInvalid())
2368 return true;
2369
2370 if (ArgChanged)
2371 *ArgChanged = true;
2372 Outputs.push_back(Out.get());
2373 continue;
2374 }
2375
2376 // The transform has determined that we should perform an elementwise
2377 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002378 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002379 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2380 ExprResult Out = getDerived().TransformExpr(Pattern);
2381 if (Out.isInvalid())
2382 return true;
2383
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002384 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002385 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2386 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002387 if (Out.isInvalid())
2388 return true;
2389 }
2390
Douglas Gregor968f23a2011-01-03 19:31:53 +00002391 if (ArgChanged)
2392 *ArgChanged = true;
2393 Outputs.push_back(Out.get());
2394 }
2395
2396 continue;
2397 }
2398
Douglas Gregora3efea12011-01-03 19:04:46 +00002399 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2400 if (Result.isInvalid())
2401 return true;
2402
2403 if (Result.get() != Inputs[I] && ArgChanged)
2404 *ArgChanged = true;
2405
2406 Outputs.push_back(Result.get());
2407 }
2408
2409 return false;
2410}
2411
2412template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002413NestedNameSpecifier *
2414TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002415 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002416 QualType ObjectType,
2417 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002418 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002419
Douglas Gregorebe10102009-08-20 07:17:43 +00002420 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002421 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002422 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002423 ObjectType,
2424 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002425 if (!Prefix)
2426 return 0;
2427 }
Mike Stump11289f42009-09-09 15:08:12 +00002428
Douglas Gregor1135c352009-08-06 05:28:30 +00002429 switch (NNS->getKind()) {
2430 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002431 if (Prefix) {
2432 // The object type and qualifier-in-scope really apply to the
2433 // leftmost entity.
2434 ObjectType = QualType();
2435 FirstQualifierInScope = 0;
2436 }
2437
Mike Stump11289f42009-09-09 15:08:12 +00002438 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002439 "Identifier nested-name-specifier with no prefix or object type");
2440 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2441 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002442 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002443
2444 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002445 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002446 ObjectType,
2447 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002448
Douglas Gregor1135c352009-08-06 05:28:30 +00002449 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002450 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002451 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002452 getDerived().TransformDecl(Range.getBegin(),
2453 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002454 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002455 Prefix == NNS->getPrefix() &&
2456 NS == NNS->getAsNamespace())
2457 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002458
Douglas Gregor1135c352009-08-06 05:28:30 +00002459 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2460 }
Mike Stump11289f42009-09-09 15:08:12 +00002461
Douglas Gregor1135c352009-08-06 05:28:30 +00002462 case NestedNameSpecifier::Global:
2463 // There is no meaningful transformation that one could perform on the
2464 // global scope.
2465 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002466
Douglas Gregor1135c352009-08-06 05:28:30 +00002467 case NestedNameSpecifier::TypeSpecWithTemplate:
2468 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002469 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002470 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2471 ObjectType,
2472 FirstQualifierInScope,
2473 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002474 if (T.isNull())
2475 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002476
Douglas Gregor1135c352009-08-06 05:28:30 +00002477 if (!getDerived().AlwaysRebuild() &&
2478 Prefix == NNS->getPrefix() &&
2479 T == QualType(NNS->getAsType(), 0))
2480 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002481
2482 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2483 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002484 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002485 }
2486 }
Mike Stump11289f42009-09-09 15:08:12 +00002487
Douglas Gregor1135c352009-08-06 05:28:30 +00002488 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002489 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002490}
2491
2492template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002493DeclarationNameInfo
2494TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002495::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002496 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002497 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002498 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002499
2500 switch (Name.getNameKind()) {
2501 case DeclarationName::Identifier:
2502 case DeclarationName::ObjCZeroArgSelector:
2503 case DeclarationName::ObjCOneArgSelector:
2504 case DeclarationName::ObjCMultiArgSelector:
2505 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002506 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002507 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002508 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002509
Douglas Gregorf816bd72009-09-03 22:13:48 +00002510 case DeclarationName::CXXConstructorName:
2511 case DeclarationName::CXXDestructorName:
2512 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002513 TypeSourceInfo *NewTInfo;
2514 CanQualType NewCanTy;
2515 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002516 NewTInfo = getDerived().TransformType(OldTInfo);
2517 if (!NewTInfo)
2518 return DeclarationNameInfo();
2519 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002520 }
2521 else {
2522 NewTInfo = 0;
2523 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002524 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002525 if (NewT.isNull())
2526 return DeclarationNameInfo();
2527 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2528 }
Mike Stump11289f42009-09-09 15:08:12 +00002529
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002530 DeclarationName NewName
2531 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2532 NewCanTy);
2533 DeclarationNameInfo NewNameInfo(NameInfo);
2534 NewNameInfo.setName(NewName);
2535 NewNameInfo.setNamedTypeInfo(NewTInfo);
2536 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002537 }
Mike Stump11289f42009-09-09 15:08:12 +00002538 }
2539
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002540 assert(0 && "Unknown name kind.");
2541 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002542}
2543
2544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002545TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002546TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002547 QualType ObjectType,
2548 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002549 SourceLocation Loc = getDerived().getBaseLocation();
2550
Douglas Gregor71dc5092009-08-06 06:41:21 +00002551 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002552 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002553 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002554 /*FIXME*/ SourceRange(Loc),
2555 ObjectType,
2556 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002557 if (!NNS)
2558 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002559
Douglas Gregor71dc5092009-08-06 06:41:21 +00002560 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002561 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002562 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002563 if (!TransTemplate)
2564 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002565
Douglas Gregor71dc5092009-08-06 06:41:21 +00002566 if (!getDerived().AlwaysRebuild() &&
2567 NNS == QTN->getQualifier() &&
2568 TransTemplate == Template)
2569 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002570
Douglas Gregor71dc5092009-08-06 06:41:21 +00002571 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2572 TransTemplate);
2573 }
Mike Stump11289f42009-09-09 15:08:12 +00002574
John McCalle66edc12009-11-24 19:00:30 +00002575 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002576 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002577 }
Mike Stump11289f42009-09-09 15:08:12 +00002578
Douglas Gregor71dc5092009-08-06 06:41:21 +00002579 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002580 NestedNameSpecifier *NNS = DTN->getQualifier();
2581 if (NNS) {
2582 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2583 /*FIXME:*/SourceRange(Loc),
2584 ObjectType,
2585 FirstQualifierInScope);
2586 if (!NNS) return TemplateName();
2587
2588 // These apply to the scope specifier, not the template.
2589 ObjectType = QualType();
2590 FirstQualifierInScope = 0;
2591 }
Mike Stump11289f42009-09-09 15:08:12 +00002592
Douglas Gregor71dc5092009-08-06 06:41:21 +00002593 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002594 NNS == DTN->getQualifier() &&
2595 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002596 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002597
Douglas Gregora5614c52010-09-08 23:56:00 +00002598 if (DTN->isIdentifier()) {
2599 // FIXME: Bad range
2600 SourceRange QualifierRange(getDerived().getBaseLocation());
2601 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2602 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002603 ObjectType,
2604 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002605 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002606
2607 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002608 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002609 }
Mike Stump11289f42009-09-09 15:08:12 +00002610
Douglas Gregor71dc5092009-08-06 06:41:21 +00002611 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002612 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002613 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002614 if (!TransTemplate)
2615 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002616
Douglas Gregor71dc5092009-08-06 06:41:21 +00002617 if (!getDerived().AlwaysRebuild() &&
2618 TransTemplate == Template)
2619 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002620
Douglas Gregor71dc5092009-08-06 06:41:21 +00002621 return TemplateName(TransTemplate);
2622 }
Mike Stump11289f42009-09-09 15:08:12 +00002623
Douglas Gregor5590be02011-01-15 06:45:20 +00002624 if (SubstTemplateTemplateParmPackStorage *SubstPack
2625 = Name.getAsSubstTemplateTemplateParmPack()) {
2626 TemplateTemplateParmDecl *TransParam
2627 = cast_or_null<TemplateTemplateParmDecl>(
2628 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2629 if (!TransParam)
2630 return TemplateName();
2631
2632 if (!getDerived().AlwaysRebuild() &&
2633 TransParam == SubstPack->getParameterPack())
2634 return Name;
2635
2636 return getDerived().RebuildTemplateName(TransParam,
2637 SubstPack->getArgumentPack());
2638 }
2639
John McCalle66edc12009-11-24 19:00:30 +00002640 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002641 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002642 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002643}
2644
2645template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002646void TreeTransform<Derived>::InventTemplateArgumentLoc(
2647 const TemplateArgument &Arg,
2648 TemplateArgumentLoc &Output) {
2649 SourceLocation Loc = getDerived().getBaseLocation();
2650 switch (Arg.getKind()) {
2651 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002652 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002653 break;
2654
2655 case TemplateArgument::Type:
2656 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002657 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002658
John McCall0ad16662009-10-29 08:12:44 +00002659 break;
2660
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002661 case TemplateArgument::Template:
2662 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2663 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002664
2665 case TemplateArgument::TemplateExpansion:
2666 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2667 break;
2668
John McCall0ad16662009-10-29 08:12:44 +00002669 case TemplateArgument::Expression:
2670 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2671 break;
2672
2673 case TemplateArgument::Declaration:
2674 case TemplateArgument::Integral:
2675 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002676 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002677 break;
2678 }
2679}
2680
2681template<typename Derived>
2682bool TreeTransform<Derived>::TransformTemplateArgument(
2683 const TemplateArgumentLoc &Input,
2684 TemplateArgumentLoc &Output) {
2685 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002686 switch (Arg.getKind()) {
2687 case TemplateArgument::Null:
2688 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002689 Output = Input;
2690 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregore922c772009-08-04 22:27:00 +00002692 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002693 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002694 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002695 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002696
2697 DI = getDerived().TransformType(DI);
2698 if (!DI) return true;
2699
2700 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2701 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002702 }
Mike Stump11289f42009-09-09 15:08:12 +00002703
Douglas Gregore922c772009-08-04 22:27:00 +00002704 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002705 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002706 DeclarationName Name;
2707 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2708 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002709 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002710 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002711 if (!D) return true;
2712
John McCall0d07eb32009-10-29 18:45:58 +00002713 Expr *SourceExpr = Input.getSourceDeclExpression();
2714 if (SourceExpr) {
2715 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002716 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002717 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002718 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002719 }
2720
2721 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002722 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002723 }
Mike Stump11289f42009-09-09 15:08:12 +00002724
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002725 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002726 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002727 TemplateName Template
2728 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2729 if (Template.isNull())
2730 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002731
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002732 Output = TemplateArgumentLoc(TemplateArgument(Template),
2733 Input.getTemplateQualifierRange(),
2734 Input.getTemplateNameLoc());
2735 return false;
2736 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002737
2738 case TemplateArgument::TemplateExpansion:
2739 llvm_unreachable("Caller should expand pack expansions");
2740
Douglas Gregore922c772009-08-04 22:27:00 +00002741 case TemplateArgument::Expression: {
2742 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002743 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002744 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002745
John McCall0ad16662009-10-29 08:12:44 +00002746 Expr *InputExpr = Input.getSourceExpression();
2747 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2748
John McCalldadc5752010-08-24 06:29:42 +00002749 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002750 = getDerived().TransformExpr(InputExpr);
2751 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002752 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002753 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregore922c772009-08-04 22:27:00 +00002756 case TemplateArgument::Pack: {
2757 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2758 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002759 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002760 AEnd = Arg.pack_end();
2761 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002762
John McCall0ad16662009-10-29 08:12:44 +00002763 // FIXME: preserve source information here when we start
2764 // caring about parameter packs.
2765
John McCall0d07eb32009-10-29 18:45:58 +00002766 TemplateArgumentLoc InputArg;
2767 TemplateArgumentLoc OutputArg;
2768 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2769 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002770 return true;
2771
John McCall0d07eb32009-10-29 18:45:58 +00002772 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002773 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002774
2775 TemplateArgument *TransformedArgsPtr
2776 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2777 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2778 TransformedArgsPtr);
2779 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2780 TransformedArgs.size()),
2781 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002782 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002783 }
2784 }
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregore922c772009-08-04 22:27:00 +00002786 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002787 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002788}
2789
Douglas Gregorfe921a72010-12-20 23:36:19 +00002790/// \brief Iterator adaptor that invents template argument location information
2791/// for each of the template arguments in its underlying iterator.
2792template<typename Derived, typename InputIterator>
2793class TemplateArgumentLocInventIterator {
2794 TreeTransform<Derived> &Self;
2795 InputIterator Iter;
2796
2797public:
2798 typedef TemplateArgumentLoc value_type;
2799 typedef TemplateArgumentLoc reference;
2800 typedef typename std::iterator_traits<InputIterator>::difference_type
2801 difference_type;
2802 typedef std::input_iterator_tag iterator_category;
2803
2804 class pointer {
2805 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002806
Douglas Gregorfe921a72010-12-20 23:36:19 +00002807 public:
2808 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2809
2810 const TemplateArgumentLoc *operator->() const { return &Arg; }
2811 };
2812
2813 TemplateArgumentLocInventIterator() { }
2814
2815 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2816 InputIterator Iter)
2817 : Self(Self), Iter(Iter) { }
2818
2819 TemplateArgumentLocInventIterator &operator++() {
2820 ++Iter;
2821 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002822 }
2823
Douglas Gregorfe921a72010-12-20 23:36:19 +00002824 TemplateArgumentLocInventIterator operator++(int) {
2825 TemplateArgumentLocInventIterator Old(*this);
2826 ++(*this);
2827 return Old;
2828 }
2829
2830 reference operator*() const {
2831 TemplateArgumentLoc Result;
2832 Self.InventTemplateArgumentLoc(*Iter, Result);
2833 return Result;
2834 }
2835
2836 pointer operator->() const { return pointer(**this); }
2837
2838 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2839 const TemplateArgumentLocInventIterator &Y) {
2840 return X.Iter == Y.Iter;
2841 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002842
Douglas Gregorfe921a72010-12-20 23:36:19 +00002843 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2844 const TemplateArgumentLocInventIterator &Y) {
2845 return X.Iter != Y.Iter;
2846 }
2847};
2848
Douglas Gregor42cafa82010-12-20 17:42:22 +00002849template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002850template<typename InputIterator>
2851bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2852 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002853 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002854 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002855 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002856 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002857
2858 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2859 // Unpack argument packs, which we translate them into separate
2860 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002861 // FIXME: We could do much better if we could guarantee that the
2862 // TemplateArgumentLocInfo for the pack expansion would be usable for
2863 // all of the template arguments in the argument pack.
2864 typedef TemplateArgumentLocInventIterator<Derived,
2865 TemplateArgument::pack_iterator>
2866 PackLocIterator;
2867 if (TransformTemplateArguments(PackLocIterator(*this,
2868 In.getArgument().pack_begin()),
2869 PackLocIterator(*this,
2870 In.getArgument().pack_end()),
2871 Outputs))
2872 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002873
2874 continue;
2875 }
2876
2877 if (In.getArgument().isPackExpansion()) {
2878 // We have a pack expansion, for which we will be substituting into
2879 // the pattern.
2880 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002881 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002882 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002883 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2884 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002885
2886 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2887 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2888 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2889
2890 // Determine whether the set of unexpanded parameter packs can and should
2891 // be expanded.
2892 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002893 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002894 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002895 if (getDerived().TryExpandParameterPacks(Ellipsis,
2896 Pattern.getSourceRange(),
2897 Unexpanded.data(),
2898 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002899 Expand,
2900 RetainExpansion,
2901 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002902 return true;
2903
2904 if (!Expand) {
2905 // The transform has determined that we should perform a simple
2906 // transformation on the pack expansion, producing another pack
2907 // expansion.
2908 TemplateArgumentLoc OutPattern;
2909 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2910 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2911 return true;
2912
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002913 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2914 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002915 if (Out.getArgument().isNull())
2916 return true;
2917
2918 Outputs.addArgument(Out);
2919 continue;
2920 }
2921
2922 // The transform has determined that we should perform an elementwise
2923 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002924 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2926
2927 if (getDerived().TransformTemplateArgument(Pattern, Out))
2928 return true;
2929
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002930 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002931 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2932 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002933 if (Out.getArgument().isNull())
2934 return true;
2935 }
2936
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002937 Outputs.addArgument(Out);
2938 }
2939
Douglas Gregor48d24112011-01-10 20:53:55 +00002940 // If we're supposed to retain a pack expansion, do so by temporarily
2941 // forgetting the partially-substituted parameter pack.
2942 if (RetainExpansion) {
2943 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2944
2945 if (getDerived().TransformTemplateArgument(Pattern, Out))
2946 return true;
2947
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002948 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2949 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002950 if (Out.getArgument().isNull())
2951 return true;
2952
2953 Outputs.addArgument(Out);
2954 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002955
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002956 continue;
2957 }
2958
2959 // The simple case:
2960 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002961 return true;
2962
2963 Outputs.addArgument(Out);
2964 }
2965
2966 return false;
2967
2968}
2969
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970//===----------------------------------------------------------------------===//
2971// Type transformation
2972//===----------------------------------------------------------------------===//
2973
2974template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002975QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976 if (getDerived().AlreadyTransformed(T))
2977 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 // Temporary workaround. All of these transformations should
2980 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002981 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002982 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002983
John McCall31f82722010-11-12 08:19:04 +00002984 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002985
John McCall550e0c22009-10-21 00:40:46 +00002986 if (!NewDI)
2987 return QualType();
2988
2989 return NewDI->getType();
2990}
2991
2992template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002993TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002994 if (getDerived().AlreadyTransformed(DI->getType()))
2995 return DI;
2996
2997 TypeLocBuilder TLB;
2998
2999 TypeLoc TL = DI->getTypeLoc();
3000 TLB.reserve(TL.getFullDataSize());
3001
John McCall31f82722010-11-12 08:19:04 +00003002 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003003 if (Result.isNull())
3004 return 0;
3005
John McCallbcd03502009-12-07 02:54:59 +00003006 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003007}
3008
3009template<typename Derived>
3010QualType
John McCall31f82722010-11-12 08:19:04 +00003011TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003012 switch (T.getTypeLocClass()) {
3013#define ABSTRACT_TYPELOC(CLASS, PARENT)
3014#define TYPELOC(CLASS, PARENT) \
3015 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003016 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003017#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018 }
Mike Stump11289f42009-09-09 15:08:12 +00003019
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003020 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003021 return QualType();
3022}
3023
3024/// FIXME: By default, this routine adds type qualifiers only to types
3025/// that can have qualifiers, and silently suppresses those qualifiers
3026/// that are not permitted (e.g., qualifiers on reference or function
3027/// types). This is the right thing for template instantiation, but
3028/// probably not for other clients.
3029template<typename Derived>
3030QualType
3031TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003032 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003033 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003034
John McCall31f82722010-11-12 08:19:04 +00003035 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003036 if (Result.isNull())
3037 return QualType();
3038
3039 // Silently suppress qualifiers if the result type can't be qualified.
3040 // FIXME: this is the right thing for template instantiation, but
3041 // probably not for other clients.
3042 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003043 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003044
John McCallcb0f89a2010-06-05 06:41:15 +00003045 if (!Quals.empty()) {
3046 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3047 TLB.push<QualifiedTypeLoc>(Result);
3048 // No location information to preserve.
3049 }
John McCall550e0c22009-10-21 00:40:46 +00003050
3051 return Result;
3052}
3053
John McCall31f82722010-11-12 08:19:04 +00003054/// \brief Transforms a type that was written in a scope specifier,
3055/// given an object type, the results of unqualified lookup, and
3056/// an already-instantiated prefix.
3057///
3058/// The object type is provided iff the scope specifier qualifies the
3059/// member of a dependent member-access expression. The prefix is
3060/// provided iff the the scope specifier in which this appears has a
3061/// prefix.
3062///
3063/// This is private to TreeTransform.
3064template<typename Derived>
3065QualType
3066TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3067 QualType ObjectType,
3068 NamedDecl *UnqualLookup,
3069 NestedNameSpecifier *Prefix) {
3070 if (getDerived().AlreadyTransformed(T))
3071 return T;
3072
3073 TypeSourceInfo *TSI =
3074 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
3075
3076 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3077 UnqualLookup, Prefix);
3078 if (!TSI) return QualType();
3079 return TSI->getType();
3080}
3081
3082template<typename Derived>
3083TypeSourceInfo *
3084TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3085 QualType ObjectType,
3086 NamedDecl *UnqualLookup,
3087 NestedNameSpecifier *Prefix) {
3088 // TODO: in some cases, we might be some verification to do here.
3089 if (ObjectType.isNull())
3090 return getDerived().TransformType(TSI);
3091
3092 QualType T = TSI->getType();
3093 if (getDerived().AlreadyTransformed(T))
3094 return TSI;
3095
3096 TypeLocBuilder TLB;
3097 QualType Result;
3098
3099 if (isa<TemplateSpecializationType>(T)) {
3100 TemplateSpecializationTypeLoc TL
3101 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3102
3103 TemplateName Template =
3104 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3105 ObjectType, UnqualLookup);
3106 if (Template.isNull()) return 0;
3107
3108 Result = getDerived()
3109 .TransformTemplateSpecializationType(TLB, TL, Template);
3110 } else if (isa<DependentTemplateSpecializationType>(T)) {
3111 DependentTemplateSpecializationTypeLoc TL
3112 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3113
3114 Result = getDerived()
3115 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3116 } else {
3117 // Nothing special needs to be done for these.
3118 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3119 }
3120
3121 if (Result.isNull()) return 0;
3122 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3123}
3124
John McCall550e0c22009-10-21 00:40:46 +00003125template <class TyLoc> static inline
3126QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3127 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3128 NewT.setNameLoc(T.getNameLoc());
3129 return T.getType();
3130}
3131
John McCall550e0c22009-10-21 00:40:46 +00003132template<typename Derived>
3133QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003134 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003135 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3136 NewT.setBuiltinLoc(T.getBuiltinLoc());
3137 if (T.needsExtraLocalData())
3138 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3139 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140}
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003143QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003144 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003145 // FIXME: recurse?
3146 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147}
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003150QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003151 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003152 QualType PointeeType
3153 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003154 if (PointeeType.isNull())
3155 return QualType();
3156
3157 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003158 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003159 // A dependent pointer type 'T *' has is being transformed such
3160 // that an Objective-C class type is being replaced for 'T'. The
3161 // resulting pointer type is an ObjCObjectPointerType, not a
3162 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003163 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003164
John McCall8b07ec22010-05-15 11:32:37 +00003165 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3166 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003167 return Result;
3168 }
John McCall31f82722010-11-12 08:19:04 +00003169
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003170 if (getDerived().AlwaysRebuild() ||
3171 PointeeType != TL.getPointeeLoc().getType()) {
3172 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3173 if (Result.isNull())
3174 return QualType();
3175 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003176
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003177 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3178 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003179 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003180}
Mike Stump11289f42009-09-09 15:08:12 +00003181
3182template<typename Derived>
3183QualType
John McCall550e0c22009-10-21 00:40:46 +00003184TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003185 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003186 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003187 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3188 if (PointeeType.isNull())
3189 return QualType();
3190
3191 QualType Result = TL.getType();
3192 if (getDerived().AlwaysRebuild() ||
3193 PointeeType != TL.getPointeeLoc().getType()) {
3194 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003195 TL.getSigilLoc());
3196 if (Result.isNull())
3197 return QualType();
3198 }
3199
Douglas Gregor049211a2010-04-22 16:50:51 +00003200 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003201 NewT.setSigilLoc(TL.getSigilLoc());
3202 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003203}
3204
John McCall70dd5f62009-10-30 00:06:24 +00003205/// Transforms a reference type. Note that somewhat paradoxically we
3206/// don't care whether the type itself is an l-value type or an r-value
3207/// type; we only care if the type was *written* as an l-value type
3208/// or an r-value type.
3209template<typename Derived>
3210QualType
3211TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003212 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003213 const ReferenceType *T = TL.getTypePtr();
3214
3215 // Note that this works with the pointee-as-written.
3216 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3217 if (PointeeType.isNull())
3218 return QualType();
3219
3220 QualType Result = TL.getType();
3221 if (getDerived().AlwaysRebuild() ||
3222 PointeeType != T->getPointeeTypeAsWritten()) {
3223 Result = getDerived().RebuildReferenceType(PointeeType,
3224 T->isSpelledAsLValue(),
3225 TL.getSigilLoc());
3226 if (Result.isNull())
3227 return QualType();
3228 }
3229
3230 // r-value references can be rebuilt as l-value references.
3231 ReferenceTypeLoc NewTL;
3232 if (isa<LValueReferenceType>(Result))
3233 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3234 else
3235 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3236 NewTL.setSigilLoc(TL.getSigilLoc());
3237
3238 return Result;
3239}
3240
Mike Stump11289f42009-09-09 15:08:12 +00003241template<typename Derived>
3242QualType
John McCall550e0c22009-10-21 00:40:46 +00003243TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003244 LValueReferenceTypeLoc TL) {
3245 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246}
3247
Mike Stump11289f42009-09-09 15:08:12 +00003248template<typename Derived>
3249QualType
John McCall550e0c22009-10-21 00:40:46 +00003250TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003251 RValueReferenceTypeLoc TL) {
3252 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003253}
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003256QualType
John McCall550e0c22009-10-21 00:40:46 +00003257TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003258 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003259 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003260
3261 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003262 if (PointeeType.isNull())
3263 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003264
John McCall550e0c22009-10-21 00:40:46 +00003265 // TODO: preserve source information for this.
3266 QualType ClassType
3267 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003268 if (ClassType.isNull())
3269 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003270
John McCall550e0c22009-10-21 00:40:46 +00003271 QualType Result = TL.getType();
3272 if (getDerived().AlwaysRebuild() ||
3273 PointeeType != T->getPointeeType() ||
3274 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003275 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3276 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003277 if (Result.isNull())
3278 return QualType();
3279 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003280
John McCall550e0c22009-10-21 00:40:46 +00003281 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3282 NewTL.setSigilLoc(TL.getSigilLoc());
3283
3284 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285}
3286
Mike Stump11289f42009-09-09 15:08:12 +00003287template<typename Derived>
3288QualType
John McCall550e0c22009-10-21 00:40:46 +00003289TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003290 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003291 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003292 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 if (ElementType.isNull())
3294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003295
John McCall550e0c22009-10-21 00:40:46 +00003296 QualType Result = TL.getType();
3297 if (getDerived().AlwaysRebuild() ||
3298 ElementType != T->getElementType()) {
3299 Result = getDerived().RebuildConstantArrayType(ElementType,
3300 T->getSizeModifier(),
3301 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003302 T->getIndexTypeCVRQualifiers(),
3303 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003304 if (Result.isNull())
3305 return QualType();
3306 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003307
John McCall550e0c22009-10-21 00:40:46 +00003308 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3309 NewTL.setLBracketLoc(TL.getLBracketLoc());
3310 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 Expr *Size = TL.getSizeExpr();
3313 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003314 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003315 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3316 }
3317 NewTL.setSizeExpr(Size);
3318
3319 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320}
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003324 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003325 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003326 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003327 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328 if (ElementType.isNull())
3329 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003330
John McCall550e0c22009-10-21 00:40:46 +00003331 QualType Result = TL.getType();
3332 if (getDerived().AlwaysRebuild() ||
3333 ElementType != T->getElementType()) {
3334 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003335 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003336 T->getIndexTypeCVRQualifiers(),
3337 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003338 if (Result.isNull())
3339 return QualType();
3340 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003341
John McCall550e0c22009-10-21 00:40:46 +00003342 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3343 NewTL.setLBracketLoc(TL.getLBracketLoc());
3344 NewTL.setRBracketLoc(TL.getRBracketLoc());
3345 NewTL.setSizeExpr(0);
3346
3347 return Result;
3348}
3349
3350template<typename Derived>
3351QualType
3352TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003353 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003354 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003355 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3356 if (ElementType.isNull())
3357 return QualType();
3358
3359 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003360 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003361
John McCalldadc5752010-08-24 06:29:42 +00003362 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003363 = getDerived().TransformExpr(T->getSizeExpr());
3364 if (SizeResult.isInvalid())
3365 return QualType();
3366
John McCallb268a282010-08-23 23:25:46 +00003367 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003368
3369 QualType Result = TL.getType();
3370 if (getDerived().AlwaysRebuild() ||
3371 ElementType != T->getElementType() ||
3372 Size != T->getSizeExpr()) {
3373 Result = getDerived().RebuildVariableArrayType(ElementType,
3374 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003375 Size,
John McCall550e0c22009-10-21 00:40:46 +00003376 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003377 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003378 if (Result.isNull())
3379 return QualType();
3380 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003381
John McCall550e0c22009-10-21 00:40:46 +00003382 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3383 NewTL.setLBracketLoc(TL.getLBracketLoc());
3384 NewTL.setRBracketLoc(TL.getRBracketLoc());
3385 NewTL.setSizeExpr(Size);
3386
3387 return Result;
3388}
3389
3390template<typename Derived>
3391QualType
3392TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003393 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003394 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003395 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3396 if (ElementType.isNull())
3397 return QualType();
3398
3399 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003401
John McCall33ddac02011-01-19 10:06:00 +00003402 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3403 Expr *origSize = TL.getSizeExpr();
3404 if (!origSize) origSize = T->getSizeExpr();
3405
3406 ExprResult sizeResult
3407 = getDerived().TransformExpr(origSize);
3408 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003409 return QualType();
3410
John McCall33ddac02011-01-19 10:06:00 +00003411 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003412
3413 QualType Result = TL.getType();
3414 if (getDerived().AlwaysRebuild() ||
3415 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003416 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003417 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3418 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003419 size,
John McCall550e0c22009-10-21 00:40:46 +00003420 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003421 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003422 if (Result.isNull())
3423 return QualType();
3424 }
John McCall550e0c22009-10-21 00:40:46 +00003425
3426 // We might have any sort of array type now, but fortunately they
3427 // all have the same location layout.
3428 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3429 NewTL.setLBracketLoc(TL.getLBracketLoc());
3430 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003431 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003432
3433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003434}
Mike Stump11289f42009-09-09 15:08:12 +00003435
3436template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003438 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003439 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003440 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003441
3442 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003443 QualType ElementType = getDerived().TransformType(T->getElementType());
3444 if (ElementType.isNull())
3445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregore922c772009-08-04 22:27:00 +00003447 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003448 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003449
John McCalldadc5752010-08-24 06:29:42 +00003450 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003451 if (Size.isInvalid())
3452 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003453
John McCall550e0c22009-10-21 00:40:46 +00003454 QualType Result = TL.getType();
3455 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003456 ElementType != T->getElementType() ||
3457 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003458 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003459 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003460 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003461 if (Result.isNull())
3462 return QualType();
3463 }
John McCall550e0c22009-10-21 00:40:46 +00003464
3465 // Result might be dependent or not.
3466 if (isa<DependentSizedExtVectorType>(Result)) {
3467 DependentSizedExtVectorTypeLoc NewTL
3468 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3469 NewTL.setNameLoc(TL.getNameLoc());
3470 } else {
3471 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3472 NewTL.setNameLoc(TL.getNameLoc());
3473 }
3474
3475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003476}
Mike Stump11289f42009-09-09 15:08:12 +00003477
3478template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003479QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003480 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003481 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003482 QualType ElementType = getDerived().TransformType(T->getElementType());
3483 if (ElementType.isNull())
3484 return QualType();
3485
John McCall550e0c22009-10-21 00:40:46 +00003486 QualType Result = TL.getType();
3487 if (getDerived().AlwaysRebuild() ||
3488 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003489 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003490 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003491 if (Result.isNull())
3492 return QualType();
3493 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003494
John McCall550e0c22009-10-21 00:40:46 +00003495 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3496 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003497
John McCall550e0c22009-10-21 00:40:46 +00003498 return Result;
3499}
3500
3501template<typename Derived>
3502QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003503 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003504 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003505 QualType ElementType = getDerived().TransformType(T->getElementType());
3506 if (ElementType.isNull())
3507 return QualType();
3508
3509 QualType Result = TL.getType();
3510 if (getDerived().AlwaysRebuild() ||
3511 ElementType != T->getElementType()) {
3512 Result = getDerived().RebuildExtVectorType(ElementType,
3513 T->getNumElements(),
3514 /*FIXME*/ SourceLocation());
3515 if (Result.isNull())
3516 return QualType();
3517 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003518
John McCall550e0c22009-10-21 00:40:46 +00003519 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3520 NewTL.setNameLoc(TL.getNameLoc());
3521
3522 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523}
Mike Stump11289f42009-09-09 15:08:12 +00003524
3525template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003526ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003527TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3528 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003529 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003530 TypeSourceInfo *NewDI = 0;
3531
3532 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3533 // If we're substituting into a pack expansion type and we know the
3534 TypeLoc OldTL = OldDI->getTypeLoc();
3535 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3536
3537 TypeLocBuilder TLB;
3538 TypeLoc NewTL = OldDI->getTypeLoc();
3539 TLB.reserve(NewTL.getFullDataSize());
3540
3541 QualType Result = getDerived().TransformType(TLB,
3542 OldExpansionTL.getPatternLoc());
3543 if (Result.isNull())
3544 return 0;
3545
3546 Result = RebuildPackExpansionType(Result,
3547 OldExpansionTL.getPatternLoc().getSourceRange(),
3548 OldExpansionTL.getEllipsisLoc(),
3549 NumExpansions);
3550 if (Result.isNull())
3551 return 0;
3552
3553 PackExpansionTypeLoc NewExpansionTL
3554 = TLB.push<PackExpansionTypeLoc>(Result);
3555 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3556 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3557 } else
3558 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003559 if (!NewDI)
3560 return 0;
3561
3562 if (NewDI == OldDI)
3563 return OldParm;
3564 else
3565 return ParmVarDecl::Create(SemaRef.Context,
3566 OldParm->getDeclContext(),
3567 OldParm->getLocation(),
3568 OldParm->getIdentifier(),
3569 NewDI->getType(),
3570 NewDI,
3571 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003572 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003573 /* DefArg */ NULL);
3574}
3575
3576template<typename Derived>
3577bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003578 TransformFunctionTypeParams(SourceLocation Loc,
3579 ParmVarDecl **Params, unsigned NumParams,
3580 const QualType *ParamTypes,
3581 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3582 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3583 for (unsigned i = 0; i != NumParams; ++i) {
3584 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003585 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003586 if (OldParm->isParameterPack()) {
3587 // We have a function parameter pack that may need to be expanded.
3588 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003589
Douglas Gregor5499af42011-01-05 23:12:31 +00003590 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003591 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3592 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3593 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3594 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003595
3596 // Determine whether we should expand the parameter packs.
3597 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003598 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003599 llvm::Optional<unsigned> OrigNumExpansions
3600 = ExpansionTL.getTypePtr()->getNumExpansions();
3601 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003602 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3603 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003604 Unexpanded.data(),
3605 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003606 ShouldExpand,
3607 RetainExpansion,
3608 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003609 return true;
3610 }
3611
3612 if (ShouldExpand) {
3613 // Expand the function parameter pack into multiple, separate
3614 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003615 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003616 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003617 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3618 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003619 = getDerived().TransformFunctionTypeParam(OldParm,
3620 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003621 if (!NewParm)
3622 return true;
3623
Douglas Gregordd472162011-01-07 00:20:55 +00003624 OutParamTypes.push_back(NewParm->getType());
3625 if (PVars)
3626 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003627 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003628
3629 // If we're supposed to retain a pack expansion, do so by temporarily
3630 // forgetting the partially-substituted parameter pack.
3631 if (RetainExpansion) {
3632 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3633 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003634 = getDerived().TransformFunctionTypeParam(OldParm,
3635 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003636 if (!NewParm)
3637 return true;
3638
3639 OutParamTypes.push_back(NewParm->getType());
3640 if (PVars)
3641 PVars->push_back(NewParm);
3642 }
3643
Douglas Gregor5499af42011-01-05 23:12:31 +00003644 // We're done with the pack expansion.
3645 continue;
3646 }
3647
3648 // We'll substitute the parameter now without expanding the pack
3649 // expansion.
3650 }
3651
3652 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003653 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3654 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003655 if (!NewParm)
3656 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003657
Douglas Gregordd472162011-01-07 00:20:55 +00003658 OutParamTypes.push_back(NewParm->getType());
3659 if (PVars)
3660 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003661 continue;
3662 }
John McCall58f10c32010-03-11 09:03:00 +00003663
3664 // Deal with the possibility that we don't have a parameter
3665 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003666 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003667 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003668 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003669 if (const PackExpansionType *Expansion
3670 = dyn_cast<PackExpansionType>(OldType)) {
3671 // We have a function parameter pack that may need to be expanded.
3672 QualType Pattern = Expansion->getPattern();
3673 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3674 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3675
3676 // Determine whether we should expand the parameter packs.
3677 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003678 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003679 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003680 Unexpanded.data(),
3681 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003682 ShouldExpand,
3683 RetainExpansion,
3684 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003685 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003686 }
3687
3688 if (ShouldExpand) {
3689 // Expand the function parameter pack into multiple, separate
3690 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003691 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003692 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3693 QualType NewType = getDerived().TransformType(Pattern);
3694 if (NewType.isNull())
3695 return true;
John McCall58f10c32010-03-11 09:03:00 +00003696
Douglas Gregordd472162011-01-07 00:20:55 +00003697 OutParamTypes.push_back(NewType);
3698 if (PVars)
3699 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003700 }
3701
3702 // We're done with the pack expansion.
3703 continue;
3704 }
3705
Douglas Gregor48d24112011-01-10 20:53:55 +00003706 // If we're supposed to retain a pack expansion, do so by temporarily
3707 // forgetting the partially-substituted parameter pack.
3708 if (RetainExpansion) {
3709 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3710 QualType NewType = getDerived().TransformType(Pattern);
3711 if (NewType.isNull())
3712 return true;
3713
3714 OutParamTypes.push_back(NewType);
3715 if (PVars)
3716 PVars->push_back(0);
3717 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003718
Douglas Gregor5499af42011-01-05 23:12:31 +00003719 // We'll substitute the parameter now without expanding the pack
3720 // expansion.
3721 OldType = Expansion->getPattern();
3722 IsPackExpansion = true;
3723 }
3724
3725 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3726 QualType NewType = getDerived().TransformType(OldType);
3727 if (NewType.isNull())
3728 return true;
3729
3730 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003731 NewType = getSema().Context.getPackExpansionType(NewType,
3732 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003733
Douglas Gregordd472162011-01-07 00:20:55 +00003734 OutParamTypes.push_back(NewType);
3735 if (PVars)
3736 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003737 }
3738
3739 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003740 }
John McCall58f10c32010-03-11 09:03:00 +00003741
3742template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003743QualType
John McCall550e0c22009-10-21 00:40:46 +00003744TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003745 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003746 // Transform the parameters and return type.
3747 //
3748 // We instantiate in source order, with the return type first followed by
3749 // the parameters, because users tend to expect this (even if they shouldn't
3750 // rely on it!).
3751 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003752 // When the function has a trailing return type, we instantiate the
3753 // parameters before the return type, since the return type can then refer
3754 // to the parameters themselves (via decltype, sizeof, etc.).
3755 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003756 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003757 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003758 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003759
Douglas Gregor7fb25412010-10-01 18:44:50 +00003760 QualType ResultType;
3761
3762 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003763 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3764 TL.getParmArray(),
3765 TL.getNumArgs(),
3766 TL.getTypePtr()->arg_type_begin(),
3767 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003768 return QualType();
3769
3770 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3771 if (ResultType.isNull())
3772 return QualType();
3773 }
3774 else {
3775 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3776 if (ResultType.isNull())
3777 return QualType();
3778
Douglas Gregordd472162011-01-07 00:20:55 +00003779 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3780 TL.getParmArray(),
3781 TL.getNumArgs(),
3782 TL.getTypePtr()->arg_type_begin(),
3783 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003784 return QualType();
3785 }
3786
John McCall550e0c22009-10-21 00:40:46 +00003787 QualType Result = TL.getType();
3788 if (getDerived().AlwaysRebuild() ||
3789 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003790 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003791 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3792 Result = getDerived().RebuildFunctionProtoType(ResultType,
3793 ParamTypes.data(),
3794 ParamTypes.size(),
3795 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003796 T->getTypeQuals(),
3797 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003798 if (Result.isNull())
3799 return QualType();
3800 }
Mike Stump11289f42009-09-09 15:08:12 +00003801
John McCall550e0c22009-10-21 00:40:46 +00003802 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3803 NewTL.setLParenLoc(TL.getLParenLoc());
3804 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003805 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003806 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3807 NewTL.setArg(i, ParamDecls[i]);
3808
3809 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003810}
Mike Stump11289f42009-09-09 15:08:12 +00003811
Douglas Gregord6ff3322009-08-04 16:50:30 +00003812template<typename Derived>
3813QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003814 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003815 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003816 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003817 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3818 if (ResultType.isNull())
3819 return QualType();
3820
3821 QualType Result = TL.getType();
3822 if (getDerived().AlwaysRebuild() ||
3823 ResultType != T->getResultType())
3824 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3825
3826 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3827 NewTL.setLParenLoc(TL.getLParenLoc());
3828 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003829 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003830
3831 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003832}
Mike Stump11289f42009-09-09 15:08:12 +00003833
John McCallb96ec562009-12-04 22:46:56 +00003834template<typename Derived> QualType
3835TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003836 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003837 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003838 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003839 if (!D)
3840 return QualType();
3841
3842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3844 Result = getDerived().RebuildUnresolvedUsingType(D);
3845 if (Result.isNull())
3846 return QualType();
3847 }
3848
3849 // We might get an arbitrary type spec type back. We should at
3850 // least always get a type spec type, though.
3851 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3852 NewTL.setNameLoc(TL.getNameLoc());
3853
3854 return Result;
3855}
3856
Douglas Gregord6ff3322009-08-04 16:50:30 +00003857template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003858QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003859 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003860 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003862 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3863 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003864 if (!Typedef)
3865 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003866
John McCall550e0c22009-10-21 00:40:46 +00003867 QualType Result = TL.getType();
3868 if (getDerived().AlwaysRebuild() ||
3869 Typedef != T->getDecl()) {
3870 Result = getDerived().RebuildTypedefType(Typedef);
3871 if (Result.isNull())
3872 return QualType();
3873 }
Mike Stump11289f42009-09-09 15:08:12 +00003874
John McCall550e0c22009-10-21 00:40:46 +00003875 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3876 NewTL.setNameLoc(TL.getNameLoc());
3877
3878 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003879}
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregord6ff3322009-08-04 16:50:30 +00003881template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003882QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003883 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003884 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003885 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003886
John McCalldadc5752010-08-24 06:29:42 +00003887 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003888 if (E.isInvalid())
3889 return QualType();
3890
John McCall550e0c22009-10-21 00:40:46 +00003891 QualType Result = TL.getType();
3892 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003893 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003894 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003895 if (Result.isNull())
3896 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003897 }
John McCall550e0c22009-10-21 00:40:46 +00003898 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003899
John McCall550e0c22009-10-21 00:40:46 +00003900 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003901 NewTL.setTypeofLoc(TL.getTypeofLoc());
3902 NewTL.setLParenLoc(TL.getLParenLoc());
3903 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003904
3905 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003906}
Mike Stump11289f42009-09-09 15:08:12 +00003907
3908template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003909QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003910 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003911 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3912 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3913 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003915
John McCall550e0c22009-10-21 00:40:46 +00003916 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003917 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3918 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003919 if (Result.isNull())
3920 return QualType();
3921 }
Mike Stump11289f42009-09-09 15:08:12 +00003922
John McCall550e0c22009-10-21 00:40:46 +00003923 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003924 NewTL.setTypeofLoc(TL.getTypeofLoc());
3925 NewTL.setLParenLoc(TL.getLParenLoc());
3926 NewTL.setRParenLoc(TL.getRParenLoc());
3927 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003928
3929 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003930}
Mike Stump11289f42009-09-09 15:08:12 +00003931
3932template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003933QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003934 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003935 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003936
Douglas Gregore922c772009-08-04 22:27:00 +00003937 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003938 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003939
John McCalldadc5752010-08-24 06:29:42 +00003940 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003941 if (E.isInvalid())
3942 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003943
John McCall550e0c22009-10-21 00:40:46 +00003944 QualType Result = TL.getType();
3945 if (getDerived().AlwaysRebuild() ||
3946 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003947 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003948 if (Result.isNull())
3949 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003950 }
John McCall550e0c22009-10-21 00:40:46 +00003951 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003952
John McCall550e0c22009-10-21 00:40:46 +00003953 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3954 NewTL.setNameLoc(TL.getNameLoc());
3955
3956 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957}
3958
3959template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003960QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003961 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003962 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003963 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003964 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3965 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003966 if (!Record)
3967 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003968
John McCall550e0c22009-10-21 00:40:46 +00003969 QualType Result = TL.getType();
3970 if (getDerived().AlwaysRebuild() ||
3971 Record != T->getDecl()) {
3972 Result = getDerived().RebuildRecordType(Record);
3973 if (Result.isNull())
3974 return QualType();
3975 }
Mike Stump11289f42009-09-09 15:08:12 +00003976
John McCall550e0c22009-10-21 00:40:46 +00003977 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3978 NewTL.setNameLoc(TL.getNameLoc());
3979
3980 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003981}
Mike Stump11289f42009-09-09 15:08:12 +00003982
3983template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003984QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003985 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003986 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003987 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003988 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3989 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003990 if (!Enum)
3991 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003992
John McCall550e0c22009-10-21 00:40:46 +00003993 QualType Result = TL.getType();
3994 if (getDerived().AlwaysRebuild() ||
3995 Enum != T->getDecl()) {
3996 Result = getDerived().RebuildEnumType(Enum);
3997 if (Result.isNull())
3998 return QualType();
3999 }
Mike Stump11289f42009-09-09 15:08:12 +00004000
John McCall550e0c22009-10-21 00:40:46 +00004001 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4002 NewTL.setNameLoc(TL.getNameLoc());
4003
4004 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004005}
John McCallfcc33b02009-09-05 00:15:47 +00004006
John McCalle78aac42010-03-10 03:28:59 +00004007template<typename Derived>
4008QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4009 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004010 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004011 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4012 TL.getTypePtr()->getDecl());
4013 if (!D) return QualType();
4014
4015 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4016 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4017 return T;
4018}
4019
Douglas Gregord6ff3322009-08-04 16:50:30 +00004020template<typename Derived>
4021QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004022 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004023 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004024 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004025}
4026
Mike Stump11289f42009-09-09 15:08:12 +00004027template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004028QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004029 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004030 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004031 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004032}
4033
4034template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004035QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4036 TypeLocBuilder &TLB,
4037 SubstTemplateTypeParmPackTypeLoc TL) {
4038 return TransformTypeSpecType(TLB, TL);
4039}
4040
4041template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004042QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004043 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004044 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004045 const TemplateSpecializationType *T = TL.getTypePtr();
4046
Mike Stump11289f42009-09-09 15:08:12 +00004047 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004048 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004049 if (Template.isNull())
4050 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004051
John McCall31f82722010-11-12 08:19:04 +00004052 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4053}
4054
Douglas Gregorfe921a72010-12-20 23:36:19 +00004055namespace {
4056 /// \brief Simple iterator that traverses the template arguments in a
4057 /// container that provides a \c getArgLoc() member function.
4058 ///
4059 /// This iterator is intended to be used with the iterator form of
4060 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4061 template<typename ArgLocContainer>
4062 class TemplateArgumentLocContainerIterator {
4063 ArgLocContainer *Container;
4064 unsigned Index;
4065
4066 public:
4067 typedef TemplateArgumentLoc value_type;
4068 typedef TemplateArgumentLoc reference;
4069 typedef int difference_type;
4070 typedef std::input_iterator_tag iterator_category;
4071
4072 class pointer {
4073 TemplateArgumentLoc Arg;
4074
4075 public:
4076 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4077
4078 const TemplateArgumentLoc *operator->() const {
4079 return &Arg;
4080 }
4081 };
4082
4083
4084 TemplateArgumentLocContainerIterator() {}
4085
4086 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4087 unsigned Index)
4088 : Container(&Container), Index(Index) { }
4089
4090 TemplateArgumentLocContainerIterator &operator++() {
4091 ++Index;
4092 return *this;
4093 }
4094
4095 TemplateArgumentLocContainerIterator operator++(int) {
4096 TemplateArgumentLocContainerIterator Old(*this);
4097 ++(*this);
4098 return Old;
4099 }
4100
4101 TemplateArgumentLoc operator*() const {
4102 return Container->getArgLoc(Index);
4103 }
4104
4105 pointer operator->() const {
4106 return pointer(Container->getArgLoc(Index));
4107 }
4108
4109 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004110 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004111 return X.Container == Y.Container && X.Index == Y.Index;
4112 }
4113
4114 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004115 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004116 return !(X == Y);
4117 }
4118 };
4119}
4120
4121
John McCall31f82722010-11-12 08:19:04 +00004122template <typename Derived>
4123QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4124 TypeLocBuilder &TLB,
4125 TemplateSpecializationTypeLoc TL,
4126 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004127 TemplateArgumentListInfo NewTemplateArgs;
4128 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4129 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004130 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4131 ArgIterator;
4132 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4133 ArgIterator(TL, TL.getNumArgs()),
4134 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004135 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004136
John McCall0ad16662009-10-29 08:12:44 +00004137 // FIXME: maybe don't rebuild if all the template arguments are the same.
4138
4139 QualType Result =
4140 getDerived().RebuildTemplateSpecializationType(Template,
4141 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004142 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004143
4144 if (!Result.isNull()) {
4145 TemplateSpecializationTypeLoc NewTL
4146 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4147 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4148 NewTL.setLAngleLoc(TL.getLAngleLoc());
4149 NewTL.setRAngleLoc(TL.getRAngleLoc());
4150 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4151 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004152 }
Mike Stump11289f42009-09-09 15:08:12 +00004153
John McCall0ad16662009-10-29 08:12:44 +00004154 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004155}
Mike Stump11289f42009-09-09 15:08:12 +00004156
4157template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004158QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004159TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004160 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004161 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004162
4163 NestedNameSpecifier *NNS = 0;
4164 // NOTE: the qualifier in an ElaboratedType is optional.
4165 if (T->getQualifier() != 0) {
4166 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004167 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004168 if (!NNS)
4169 return QualType();
4170 }
Mike Stump11289f42009-09-09 15:08:12 +00004171
John McCall31f82722010-11-12 08:19:04 +00004172 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4173 if (NamedT.isNull())
4174 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004175
John McCall550e0c22009-10-21 00:40:46 +00004176 QualType Result = TL.getType();
4177 if (getDerived().AlwaysRebuild() ||
4178 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004179 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004180 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4181 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004182 if (Result.isNull())
4183 return QualType();
4184 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004185
Abramo Bagnara6150c882010-05-11 21:36:43 +00004186 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004187 NewTL.setKeywordLoc(TL.getKeywordLoc());
4188 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004189
4190 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191}
Mike Stump11289f42009-09-09 15:08:12 +00004192
4193template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004194QualType TreeTransform<Derived>::TransformAttributedType(
4195 TypeLocBuilder &TLB,
4196 AttributedTypeLoc TL) {
4197 const AttributedType *oldType = TL.getTypePtr();
4198 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4199 if (modifiedType.isNull())
4200 return QualType();
4201
4202 QualType result = TL.getType();
4203
4204 // FIXME: dependent operand expressions?
4205 if (getDerived().AlwaysRebuild() ||
4206 modifiedType != oldType->getModifiedType()) {
4207 // TODO: this is really lame; we should really be rebuilding the
4208 // equivalent type from first principles.
4209 QualType equivalentType
4210 = getDerived().TransformType(oldType->getEquivalentType());
4211 if (equivalentType.isNull())
4212 return QualType();
4213 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4214 modifiedType,
4215 equivalentType);
4216 }
4217
4218 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4219 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4220 if (TL.hasAttrOperand())
4221 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4222 if (TL.hasAttrExprOperand())
4223 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4224 else if (TL.hasAttrEnumOperand())
4225 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4226
4227 return result;
4228}
4229
4230template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004231QualType
4232TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4233 ParenTypeLoc TL) {
4234 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4235 if (Inner.isNull())
4236 return QualType();
4237
4238 QualType Result = TL.getType();
4239 if (getDerived().AlwaysRebuild() ||
4240 Inner != TL.getInnerLoc().getType()) {
4241 Result = getDerived().RebuildParenType(Inner);
4242 if (Result.isNull())
4243 return QualType();
4244 }
4245
4246 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4247 NewTL.setLParenLoc(TL.getLParenLoc());
4248 NewTL.setRParenLoc(TL.getRParenLoc());
4249 return Result;
4250}
4251
4252template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004253QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004254 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004255 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004256
Douglas Gregord6ff3322009-08-04 16:50:30 +00004257 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004258 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004259 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004260 if (!NNS)
4261 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004262
John McCallc392f372010-06-11 00:33:02 +00004263 QualType Result
4264 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4265 T->getIdentifier(),
4266 TL.getKeywordLoc(),
4267 TL.getQualifierRange(),
4268 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004269 if (Result.isNull())
4270 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004271
Abramo Bagnarad7548482010-05-19 21:37:53 +00004272 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4273 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004274 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4275
Abramo Bagnarad7548482010-05-19 21:37:53 +00004276 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4277 NewTL.setKeywordLoc(TL.getKeywordLoc());
4278 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004279 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004280 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4281 NewTL.setKeywordLoc(TL.getKeywordLoc());
4282 NewTL.setQualifierRange(TL.getQualifierRange());
4283 NewTL.setNameLoc(TL.getNameLoc());
4284 }
John McCall550e0c22009-10-21 00:40:46 +00004285 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286}
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregord6ff3322009-08-04 16:50:30 +00004288template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004289QualType TreeTransform<Derived>::
4290 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004291 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004292 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004293
4294 NestedNameSpecifier *NNS
4295 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004296 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004297 if (!NNS)
4298 return QualType();
4299
John McCall31f82722010-11-12 08:19:04 +00004300 return getDerived()
4301 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4302}
4303
4304template<typename Derived>
4305QualType TreeTransform<Derived>::
4306 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4307 DependentTemplateSpecializationTypeLoc TL,
4308 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004309 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004310
John McCallc392f372010-06-11 00:33:02 +00004311 TemplateArgumentListInfo NewTemplateArgs;
4312 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4313 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004314
4315 typedef TemplateArgumentLocContainerIterator<
4316 DependentTemplateSpecializationTypeLoc> ArgIterator;
4317 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4318 ArgIterator(TL, TL.getNumArgs()),
4319 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004320 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004321
Douglas Gregora5614c52010-09-08 23:56:00 +00004322 QualType Result
4323 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4324 NNS,
4325 TL.getQualifierRange(),
4326 T->getIdentifier(),
4327 TL.getNameLoc(),
4328 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004329 if (Result.isNull())
4330 return QualType();
4331
4332 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4333 QualType NamedT = ElabT->getNamedType();
4334
4335 // Copy information relevant to the template specialization.
4336 TemplateSpecializationTypeLoc NamedTL
4337 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4338 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4339 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4340 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4341 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4342
4343 // Copy information relevant to the elaborated type.
4344 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4345 NewTL.setKeywordLoc(TL.getKeywordLoc());
4346 NewTL.setQualifierRange(TL.getQualifierRange());
4347 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004348 TypeLoc NewTL(Result, TL.getOpaqueData());
4349 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004350 }
4351 return Result;
4352}
4353
4354template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004355QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4356 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004357 QualType Pattern
4358 = getDerived().TransformType(TLB, TL.getPatternLoc());
4359 if (Pattern.isNull())
4360 return QualType();
4361
4362 QualType Result = TL.getType();
4363 if (getDerived().AlwaysRebuild() ||
4364 Pattern != TL.getPatternLoc().getType()) {
4365 Result = getDerived().RebuildPackExpansionType(Pattern,
4366 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004367 TL.getEllipsisLoc(),
4368 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004369 if (Result.isNull())
4370 return QualType();
4371 }
4372
4373 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4374 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4375 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004376}
4377
4378template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004379QualType
4380TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004381 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004382 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004383 TLB.pushFullCopy(TL);
4384 return TL.getType();
4385}
4386
4387template<typename Derived>
4388QualType
4389TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004390 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004391 // ObjCObjectType is never dependent.
4392 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004393 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004394}
Mike Stump11289f42009-09-09 15:08:12 +00004395
4396template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004397QualType
4398TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004399 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004400 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004401 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004402 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004403}
4404
Douglas Gregord6ff3322009-08-04 16:50:30 +00004405//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004406// Statement transformation
4407//===----------------------------------------------------------------------===//
4408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004409StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004410TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004411 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004412}
4413
4414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004415StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004416TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4417 return getDerived().TransformCompoundStmt(S, false);
4418}
4419
4420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004421StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004422TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004423 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004424 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004425 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004426 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004427 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4428 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004429 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004430 if (Result.isInvalid()) {
4431 // Immediately fail if this was a DeclStmt, since it's very
4432 // likely that this will cause problems for future statements.
4433 if (isa<DeclStmt>(*B))
4434 return StmtError();
4435
4436 // Otherwise, just keep processing substatements and fail later.
4437 SubStmtInvalid = true;
4438 continue;
4439 }
Mike Stump11289f42009-09-09 15:08:12 +00004440
Douglas Gregorebe10102009-08-20 07:17:43 +00004441 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4442 Statements.push_back(Result.takeAs<Stmt>());
4443 }
Mike Stump11289f42009-09-09 15:08:12 +00004444
John McCall1ababa62010-08-27 19:56:05 +00004445 if (SubStmtInvalid)
4446 return StmtError();
4447
Douglas Gregorebe10102009-08-20 07:17:43 +00004448 if (!getDerived().AlwaysRebuild() &&
4449 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004450 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004451
4452 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4453 move_arg(Statements),
4454 S->getRBracLoc(),
4455 IsStmtExpr);
4456}
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregorebe10102009-08-20 07:17:43 +00004458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004459StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004460TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004461 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004462 {
4463 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004464 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004465
Eli Friedman06577382009-11-19 03:14:00 +00004466 // Transform the left-hand case value.
4467 LHS = getDerived().TransformExpr(S->getLHS());
4468 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004469 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Eli Friedman06577382009-11-19 03:14:00 +00004471 // Transform the right-hand case value (for the GNU case-range extension).
4472 RHS = getDerived().TransformExpr(S->getRHS());
4473 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004474 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004475 }
Mike Stump11289f42009-09-09 15:08:12 +00004476
Douglas Gregorebe10102009-08-20 07:17:43 +00004477 // Build the case statement.
4478 // Case statements are always rebuilt so that they will attached to their
4479 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004480 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004481 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004482 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004483 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004484 S->getColonLoc());
4485 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004486 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004487
Douglas Gregorebe10102009-08-20 07:17:43 +00004488 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004489 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004490 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004491 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004492
Douglas Gregorebe10102009-08-20 07:17:43 +00004493 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004494 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004495}
4496
4497template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004498StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004499TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004500 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004501 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004502 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004503 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004504
Douglas Gregorebe10102009-08-20 07:17:43 +00004505 // Default statements are always rebuilt
4506 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004507 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004508}
Mike Stump11289f42009-09-09 15:08:12 +00004509
Douglas Gregorebe10102009-08-20 07:17:43 +00004510template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004511StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004512TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004513 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004514 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004515 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004516
Douglas Gregorebe10102009-08-20 07:17:43 +00004517 // FIXME: Pass the real colon location in.
4518 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4519 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004520 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004521}
Mike Stump11289f42009-09-09 15:08:12 +00004522
Douglas Gregorebe10102009-08-20 07:17:43 +00004523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004524StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004525TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004526 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004527 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004528 VarDecl *ConditionVar = 0;
4529 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004530 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004531 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004532 getDerived().TransformDefinition(
4533 S->getConditionVariable()->getLocation(),
4534 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004535 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004536 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004537 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004538 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004539
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004540 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004541 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004542
4543 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004544 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004545 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4546 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004547 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004548 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004549
John McCallb268a282010-08-23 23:25:46 +00004550 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004551 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004552 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004553
John McCallb268a282010-08-23 23:25:46 +00004554 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4555 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004556 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004557
Douglas Gregorebe10102009-08-20 07:17:43 +00004558 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004559 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004560 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004561 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregorebe10102009-08-20 07:17:43 +00004563 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004564 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004565 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004566 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregorebe10102009-08-20 07:17:43 +00004568 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004569 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004570 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004571 Then.get() == S->getThen() &&
4572 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004573 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004575 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004576 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004577 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004578}
4579
4580template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004581StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004582TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004583 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004584 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004585 VarDecl *ConditionVar = 0;
4586 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004587 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004588 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004589 getDerived().TransformDefinition(
4590 S->getConditionVariable()->getLocation(),
4591 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004592 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004593 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004594 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004595 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004596
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004597 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004598 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004599 }
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregorebe10102009-08-20 07:17:43 +00004601 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004602 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004603 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004604 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004605 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004607
Douglas Gregorebe10102009-08-20 07:17:43 +00004608 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004609 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004610 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004611 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregorebe10102009-08-20 07:17:43 +00004613 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004614 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4615 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004616}
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregorebe10102009-08-20 07:17:43 +00004618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004619StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004620TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004621 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004622 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004623 VarDecl *ConditionVar = 0;
4624 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004625 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004626 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004627 getDerived().TransformDefinition(
4628 S->getConditionVariable()->getLocation(),
4629 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004630 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004631 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004632 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004633 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004634
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004635 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004636 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004637
4638 if (S->getCond()) {
4639 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004640 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4641 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004642 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004643 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004644 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004645 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004646 }
Mike Stump11289f42009-09-09 15:08:12 +00004647
John McCallb268a282010-08-23 23:25:46 +00004648 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4649 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004650 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004651
Douglas Gregorebe10102009-08-20 07:17:43 +00004652 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004653 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004654 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004655 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregorebe10102009-08-20 07:17:43 +00004657 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004658 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004659 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004660 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004661 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004663 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004664 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004665}
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregorebe10102009-08-20 07:17:43 +00004667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004668StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004669TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004670 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004671 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004672 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004673 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004674
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004675 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004676 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004677 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004678 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004679
Douglas Gregorebe10102009-08-20 07:17:43 +00004680 if (!getDerived().AlwaysRebuild() &&
4681 Cond.get() == S->getCond() &&
4682 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004683 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004684
John McCallb268a282010-08-23 23:25:46 +00004685 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4686 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004687 S->getRParenLoc());
4688}
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregorebe10102009-08-20 07:17:43 +00004690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004691StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004692TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004693 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004694 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004695 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004696 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregorebe10102009-08-20 07:17:43 +00004698 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004699 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004700 VarDecl *ConditionVar = 0;
4701 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004702 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004703 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004704 getDerived().TransformDefinition(
4705 S->getConditionVariable()->getLocation(),
4706 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004707 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004708 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004709 } else {
4710 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004711
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004712 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004713 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004714
4715 if (S->getCond()) {
4716 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004717 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4718 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004719 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004720 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004721
John McCallb268a282010-08-23 23:25:46 +00004722 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004723 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004724 }
Mike Stump11289f42009-09-09 15:08:12 +00004725
John McCallb268a282010-08-23 23:25:46 +00004726 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4727 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004728 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004729
Douglas Gregorebe10102009-08-20 07:17:43 +00004730 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004731 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004732 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004733 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004734
John McCallb268a282010-08-23 23:25:46 +00004735 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4736 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004737 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004738
Douglas Gregorebe10102009-08-20 07:17:43 +00004739 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004740 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004741 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004742 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregorebe10102009-08-20 07:17:43 +00004744 if (!getDerived().AlwaysRebuild() &&
4745 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004746 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004747 Inc.get() == S->getInc() &&
4748 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004749 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregorebe10102009-08-20 07:17:43 +00004751 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004752 Init.get(), FullCond, ConditionVar,
4753 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004754}
4755
4756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004757StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004758TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004759 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004760 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004761 S->getLabel());
4762}
4763
4764template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004765StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004766TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004767 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004768 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004769 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004770
Douglas Gregorebe10102009-08-20 07:17:43 +00004771 if (!getDerived().AlwaysRebuild() &&
4772 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004773 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004774
4775 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004776 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004777}
4778
4779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004780StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004781TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004782 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004783}
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregorebe10102009-08-20 07:17:43 +00004785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004786StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004787TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004788 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004789}
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregorebe10102009-08-20 07:17:43 +00004791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004792StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004793TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004794 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004795 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004796 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004797
Mike Stump11289f42009-09-09 15:08:12 +00004798 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004799 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004800 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004801}
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregorebe10102009-08-20 07:17:43 +00004803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004804StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004805TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004806 bool DeclChanged = false;
4807 llvm::SmallVector<Decl *, 4> Decls;
4808 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4809 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004810 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4811 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004812 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004813 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregorebe10102009-08-20 07:17:43 +00004815 if (Transformed != *D)
4816 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregorebe10102009-08-20 07:17:43 +00004818 Decls.push_back(Transformed);
4819 }
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregorebe10102009-08-20 07:17:43 +00004821 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004822 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004823
4824 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004825 S->getStartLoc(), S->getEndLoc());
4826}
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregorebe10102009-08-20 07:17:43 +00004828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004829StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004830TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004831 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004832 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004833}
4834
4835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004836StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004837TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004838
John McCall37ad5512010-08-23 06:44:23 +00004839 ASTOwningVector<Expr*> Constraints(getSema());
4840 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004841 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004842
John McCalldadc5752010-08-24 06:29:42 +00004843 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004844 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004845
4846 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004847
Anders Carlssonaaeef072010-01-24 05:50:09 +00004848 // Go through the outputs.
4849 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004850 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004851
Anders Carlssonaaeef072010-01-24 05:50:09 +00004852 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004853 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004854
Anders Carlssonaaeef072010-01-24 05:50:09 +00004855 // Transform the output expr.
4856 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004857 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004858 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004859 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004860
Anders Carlssonaaeef072010-01-24 05:50:09 +00004861 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004862
John McCallb268a282010-08-23 23:25:46 +00004863 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004864 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004865
Anders Carlssonaaeef072010-01-24 05:50:09 +00004866 // Go through the inputs.
4867 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004868 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004869
Anders Carlssonaaeef072010-01-24 05:50:09 +00004870 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004871 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004872
Anders Carlssonaaeef072010-01-24 05:50:09 +00004873 // Transform the input expr.
4874 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004875 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004876 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004877 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004878
Anders Carlssonaaeef072010-01-24 05:50:09 +00004879 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004880
John McCallb268a282010-08-23 23:25:46 +00004881 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004882 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004883
Anders Carlssonaaeef072010-01-24 05:50:09 +00004884 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004885 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004886
4887 // Go through the clobbers.
4888 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004889 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004890
4891 // No need to transform the asm string literal.
4892 AsmString = SemaRef.Owned(S->getAsmString());
4893
4894 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4895 S->isSimple(),
4896 S->isVolatile(),
4897 S->getNumOutputs(),
4898 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004899 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004900 move_arg(Constraints),
4901 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004902 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004903 move_arg(Clobbers),
4904 S->getRParenLoc(),
4905 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004906}
4907
4908
4909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004910StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004911TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004912 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004913 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004914 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004915 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004916
Douglas Gregor96c79492010-04-23 22:50:49 +00004917 // Transform the @catch statements (if present).
4918 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004919 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004920 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004921 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004922 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004924 if (Catch.get() != S->getCatchStmt(I))
4925 AnyCatchChanged = true;
4926 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004927 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004928
Douglas Gregor306de2f2010-04-22 23:59:56 +00004929 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004930 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004931 if (S->getFinallyStmt()) {
4932 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4933 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004934 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004935 }
4936
4937 // If nothing changed, just retain this statement.
4938 if (!getDerived().AlwaysRebuild() &&
4939 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004940 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004941 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004942 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004943
Douglas Gregor306de2f2010-04-22 23:59:56 +00004944 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004945 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4946 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004947}
Mike Stump11289f42009-09-09 15:08:12 +00004948
Douglas Gregorebe10102009-08-20 07:17:43 +00004949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004950StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004951TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004952 // Transform the @catch parameter, if there is one.
4953 VarDecl *Var = 0;
4954 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4955 TypeSourceInfo *TSInfo = 0;
4956 if (FromVar->getTypeSourceInfo()) {
4957 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4958 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004959 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004960 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004961
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004962 QualType T;
4963 if (TSInfo)
4964 T = TSInfo->getType();
4965 else {
4966 T = getDerived().TransformType(FromVar->getType());
4967 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004968 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004969 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004970
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004971 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4972 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004973 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004974 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004975
John McCalldadc5752010-08-24 06:29:42 +00004976 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004977 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004978 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004979
4980 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004981 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004982 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004983}
Mike Stump11289f42009-09-09 15:08:12 +00004984
Douglas Gregorebe10102009-08-20 07:17:43 +00004985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004986StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004987TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004988 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004989 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004990 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004991 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004992
Douglas Gregor306de2f2010-04-22 23:59:56 +00004993 // If nothing changed, just retain this statement.
4994 if (!getDerived().AlwaysRebuild() &&
4995 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004996 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004997
4998 // Build a new statement.
4999 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005000 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005001}
Mike Stump11289f42009-09-09 15:08:12 +00005002
Douglas Gregorebe10102009-08-20 07:17:43 +00005003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005004StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005005TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005006 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005007 if (S->getThrowExpr()) {
5008 Operand = getDerived().TransformExpr(S->getThrowExpr());
5009 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005010 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005011 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005012
Douglas Gregor2900c162010-04-22 21:44:01 +00005013 if (!getDerived().AlwaysRebuild() &&
5014 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005015 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005016
John McCallb268a282010-08-23 23:25:46 +00005017 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005018}
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregorebe10102009-08-20 07:17:43 +00005020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005021StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005022TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005023 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005024 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005025 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005026 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005027 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005028
Douglas Gregor6148de72010-04-22 22:01:21 +00005029 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005030 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005031 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005032 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005033
Douglas Gregor6148de72010-04-22 22:01:21 +00005034 // If nothing change, just retain the current statement.
5035 if (!getDerived().AlwaysRebuild() &&
5036 Object.get() == S->getSynchExpr() &&
5037 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005038 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005039
5040 // Build a new statement.
5041 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005042 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005043}
5044
5045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005046StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005047TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005048 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005049 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005050 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005051 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005052 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005053
Douglas Gregorf68a5082010-04-22 23:10:45 +00005054 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005055 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005056 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005057 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005058
Douglas Gregorf68a5082010-04-22 23:10:45 +00005059 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005060 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005061 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005062 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063
Douglas Gregorf68a5082010-04-22 23:10:45 +00005064 // If nothing changed, just retain this statement.
5065 if (!getDerived().AlwaysRebuild() &&
5066 Element.get() == S->getElement() &&
5067 Collection.get() == S->getCollection() &&
5068 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005069 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005070
Douglas Gregorf68a5082010-04-22 23:10:45 +00005071 // Build a new statement.
5072 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5073 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005074 Element.get(),
5075 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005076 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005077 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005078}
5079
5080
5081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005082StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005083TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5084 // Transform the exception declaration, if any.
5085 VarDecl *Var = 0;
5086 if (S->getExceptionDecl()) {
5087 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005088 TypeSourceInfo *T = getDerived().TransformType(
5089 ExceptionDecl->getTypeSourceInfo());
5090 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005091 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005093 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005094 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005095 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005096 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005097 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 }
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregorebe10102009-08-20 07:17:43 +00005100 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005101 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005102 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005103 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregorebe10102009-08-20 07:17:43 +00005105 if (!getDerived().AlwaysRebuild() &&
5106 !Var &&
5107 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005108 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005109
5110 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5111 Var,
John McCallb268a282010-08-23 23:25:46 +00005112 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005113}
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregorebe10102009-08-20 07:17:43 +00005115template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005116StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005117TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5118 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005119 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005120 = getDerived().TransformCompoundStmt(S->getTryBlock());
5121 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005122 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005123
Douglas Gregorebe10102009-08-20 07:17:43 +00005124 // Transform the handlers.
5125 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005126 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005128 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005129 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5130 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005131 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005132
Douglas Gregorebe10102009-08-20 07:17:43 +00005133 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5134 Handlers.push_back(Handler.takeAs<Stmt>());
5135 }
Mike Stump11289f42009-09-09 15:08:12 +00005136
Douglas Gregorebe10102009-08-20 07:17:43 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 TryBlock.get() == S->getTryBlock() &&
5139 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005140 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005141
John McCallb268a282010-08-23 23:25:46 +00005142 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005143 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005144}
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregorebe10102009-08-20 07:17:43 +00005146//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005147// Expression transformation
5148//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005150ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005151TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005152 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005153}
Mike Stump11289f42009-09-09 15:08:12 +00005154
5155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005157TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005158 NestedNameSpecifier *Qualifier = 0;
5159 if (E->getQualifier()) {
5160 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005161 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005162 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005163 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005164 }
John McCallce546572009-12-08 09:08:17 +00005165
5166 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005167 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5168 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005171
John McCall815039a2010-08-17 21:27:17 +00005172 DeclarationNameInfo NameInfo = E->getNameInfo();
5173 if (NameInfo.getName()) {
5174 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5175 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005176 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005177 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005178
5179 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005180 Qualifier == E->getQualifier() &&
5181 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005182 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005183 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005184
5185 // Mark it referenced in the new context regardless.
5186 // FIXME: this is a bit instantiation-specific.
5187 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5188
John McCallc3007a22010-10-26 07:05:15 +00005189 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005190 }
John McCallce546572009-12-08 09:08:17 +00005191
5192 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005193 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005194 TemplateArgs = &TransArgs;
5195 TransArgs.setLAngleLoc(E->getLAngleLoc());
5196 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005197 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5198 E->getNumTemplateArgs(),
5199 TransArgs))
5200 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005201 }
5202
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005203 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005204 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005205}
Mike Stump11289f42009-09-09 15:08:12 +00005206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005208ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005209TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005210 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005211}
Mike Stump11289f42009-09-09 15:08:12 +00005212
Douglas Gregora16548e2009-08-11 05:31:07 +00005213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005214ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005215TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005221TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005222 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005223}
Mike Stump11289f42009-09-09 15:08:12 +00005224
Douglas Gregora16548e2009-08-11 05:31:07 +00005225template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005226ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005227TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005228 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005229}
Mike Stump11289f42009-09-09 15:08:12 +00005230
Douglas Gregora16548e2009-08-11 05:31:07 +00005231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005233TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005234 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005235}
5236
5237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005239TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005240 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005243
Douglas Gregora16548e2009-08-11 05:31:07 +00005244 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005245 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005246
John McCallb268a282010-08-23 23:25:46 +00005247 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 E->getRParen());
5249}
5250
Mike Stump11289f42009-09-09 15:08:12 +00005251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005253TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005254 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005256 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005257
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005259 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5262 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005263 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005264}
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregora16548e2009-08-11 05:31:07 +00005266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005267ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005268TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5269 // Transform the type.
5270 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5271 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005272 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005273
Douglas Gregor882211c2010-04-28 22:16:22 +00005274 // Transform all of the components into components similar to what the
5275 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005276 // FIXME: It would be slightly more efficient in the non-dependent case to
5277 // just map FieldDecls, rather than requiring the rebuilder to look for
5278 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005279 // template code that we don't care.
5280 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005281 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005282 typedef OffsetOfExpr::OffsetOfNode Node;
5283 llvm::SmallVector<Component, 4> Components;
5284 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5285 const Node &ON = E->getComponent(I);
5286 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005287 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005288 Comp.LocStart = ON.getRange().getBegin();
5289 Comp.LocEnd = ON.getRange().getEnd();
5290 switch (ON.getKind()) {
5291 case Node::Array: {
5292 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005293 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005294 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005295 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005296
Douglas Gregor882211c2010-04-28 22:16:22 +00005297 ExprChanged = ExprChanged || Index.get() != FromIndex;
5298 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005299 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005300 break;
5301 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005302
Douglas Gregor882211c2010-04-28 22:16:22 +00005303 case Node::Field:
5304 case Node::Identifier:
5305 Comp.isBrackets = false;
5306 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005307 if (!Comp.U.IdentInfo)
5308 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005309
Douglas Gregor882211c2010-04-28 22:16:22 +00005310 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005311
Douglas Gregord1702062010-04-29 00:18:15 +00005312 case Node::Base:
5313 // Will be recomputed during the rebuild.
5314 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005315 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316
Douglas Gregor882211c2010-04-28 22:16:22 +00005317 Components.push_back(Comp);
5318 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005319
Douglas Gregor882211c2010-04-28 22:16:22 +00005320 // If nothing changed, retain the existing expression.
5321 if (!getDerived().AlwaysRebuild() &&
5322 Type == E->getTypeSourceInfo() &&
5323 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005324 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005325
Douglas Gregor882211c2010-04-28 22:16:22 +00005326 // Build a new offsetof expression.
5327 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5328 Components.data(), Components.size(),
5329 E->getRParenLoc());
5330}
5331
5332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005333ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005334TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5335 assert(getDerived().AlreadyTransformed(E->getType()) &&
5336 "opaque value expression requires transformation");
5337 return SemaRef.Owned(E);
5338}
5339
5340template<typename Derived>
5341ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005342TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005343 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005344 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005345
John McCallbcd03502009-12-07 02:54:59 +00005346 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005347 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005349
John McCall4c98fd82009-11-04 07:28:41 +00005350 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005351 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005352
John McCall4c98fd82009-11-04 07:28:41 +00005353 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005354 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 E->getSourceRange());
5356 }
Mike Stump11289f42009-09-09 15:08:12 +00005357
John McCalldadc5752010-08-24 06:29:42 +00005358 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005359 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005360 // C++0x [expr.sizeof]p1:
5361 // The operand is either an expression, which is an unevaluated operand
5362 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005363 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005364
Douglas Gregora16548e2009-08-11 05:31:07 +00005365 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5366 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005370 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 }
Mike Stump11289f42009-09-09 15:08:12 +00005372
John McCallb268a282010-08-23 23:25:46 +00005373 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005374 E->isSizeOf(),
5375 E->getSourceRange());
5376}
Mike Stump11289f42009-09-09 15:08:12 +00005377
Douglas Gregora16548e2009-08-11 05:31:07 +00005378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005379ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005380TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005381 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005384
John McCalldadc5752010-08-24 06:29:42 +00005385 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005386 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005388
5389
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 if (!getDerived().AlwaysRebuild() &&
5391 LHS.get() == E->getLHS() &&
5392 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005393 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005394
John McCallb268a282010-08-23 23:25:46 +00005395 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005397 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 E->getRBracketLoc());
5399}
Mike Stump11289f42009-09-09 15:08:12 +00005400
5401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005403TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005405 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005406 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005407 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005408
5409 // Transform arguments.
5410 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005411 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005412 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5413 &ArgChanged))
5414 return ExprError();
5415
Douglas Gregora16548e2009-08-11 05:31:07 +00005416 if (!getDerived().AlwaysRebuild() &&
5417 Callee.get() == E->getCallee() &&
5418 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005419 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregora16548e2009-08-11 05:31:07 +00005421 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005422 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005424 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005425 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005426 E->getRParenLoc());
5427}
Mike Stump11289f42009-09-09 15:08:12 +00005428
5429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005430ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005431TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005432 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005436 NestedNameSpecifier *Qualifier = 0;
5437 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005438 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005439 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005440 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005441 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005442 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005443 }
Mike Stump11289f42009-09-09 15:08:12 +00005444
Eli Friedman2cfcef62009-12-04 06:40:45 +00005445 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005446 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5447 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005449 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005450
John McCall16df1e52010-03-30 21:47:33 +00005451 NamedDecl *FoundDecl = E->getFoundDecl();
5452 if (FoundDecl == E->getMemberDecl()) {
5453 FoundDecl = Member;
5454 } else {
5455 FoundDecl = cast_or_null<NamedDecl>(
5456 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5457 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005458 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005459 }
5460
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 if (!getDerived().AlwaysRebuild() &&
5462 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005463 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005464 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005465 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005466 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005468 // Mark it referenced in the new context regardless.
5469 // FIXME: this is a bit instantiation-specific.
5470 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005471 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005472 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005473
John McCall6b51f282009-11-23 01:53:49 +00005474 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005475 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005476 TransArgs.setLAngleLoc(E->getLAngleLoc());
5477 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005478 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5479 E->getNumTemplateArgs(),
5480 TransArgs))
5481 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005482 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005483
Douglas Gregora16548e2009-08-11 05:31:07 +00005484 // FIXME: Bogus source location for the operator
5485 SourceLocation FakeOperatorLoc
5486 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5487
John McCall38836f02010-01-15 08:34:02 +00005488 // FIXME: to do this check properly, we will need to preserve the
5489 // first-qualifier-in-scope here, just in case we had a dependent
5490 // base (and therefore couldn't do the check) and a
5491 // nested-name-qualifier (and therefore could do the lookup).
5492 NamedDecl *FirstQualifierInScope = 0;
5493
John McCallb268a282010-08-23 23:25:46 +00005494 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005495 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005496 Qualifier,
5497 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005498 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005499 Member,
John McCall16df1e52010-03-30 21:47:33 +00005500 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005501 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005502 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005503 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005504}
Mike Stump11289f42009-09-09 15:08:12 +00005505
Douglas Gregora16548e2009-08-11 05:31:07 +00005506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005507ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005508TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005509 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005510 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005512
John McCalldadc5752010-08-24 06:29:42 +00005513 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005516
Douglas Gregora16548e2009-08-11 05:31:07 +00005517 if (!getDerived().AlwaysRebuild() &&
5518 LHS.get() == E->getLHS() &&
5519 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005520 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005521
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005523 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005524}
5525
Mike Stump11289f42009-09-09 15:08:12 +00005526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005527ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005528TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005529 CompoundAssignOperator *E) {
5530 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005531}
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregora16548e2009-08-11 05:31:07 +00005533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005534ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005535TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005536 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005537 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005539
John McCalldadc5752010-08-24 06:29:42 +00005540 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005543
John McCalldadc5752010-08-24 06:29:42 +00005544 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 if (!getDerived().AlwaysRebuild() &&
5549 Cond.get() == E->getCond() &&
5550 LHS.get() == E->getLHS() &&
5551 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005552 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005553
John McCallb268a282010-08-23 23:25:46 +00005554 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005555 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005556 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005557 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005558 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
5561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005563TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005564 // Implicit casts are eliminated during transformation, since they
5565 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005566 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005567}
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregora16548e2009-08-11 05:31:07 +00005569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005570ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005571TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005572 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5573 if (!Type)
5574 return ExprError();
5575
John McCalldadc5752010-08-24 06:29:42 +00005576 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005577 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005578 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005582 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005584 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005585
John McCall97513962010-01-15 18:39:57 +00005586 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005587 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005589 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005590}
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005593ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005594TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005595 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5596 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5597 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
John McCalldadc5752010-08-24 06:29:42 +00005600 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005605 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005607 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005608
John McCall5d7aa7f2010-01-19 22:33:45 +00005609 // Note: the expression type doesn't necessarily match the
5610 // type-as-written, but that's okay, because it should always be
5611 // derivable from the initializer.
5612
John McCalle15bbff2010-01-18 19:35:47 +00005613 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005614 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005615 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregora16548e2009-08-11 05:31:07 +00005618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005620TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005621 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005622 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 if (!getDerived().AlwaysRebuild() &&
5626 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005627 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005628
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005630 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005632 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 E->getAccessorLoc(),
5634 E->getAccessor());
5635}
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregora16548e2009-08-11 05:31:07 +00005637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005639TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005641
John McCall37ad5512010-08-23 06:44:23 +00005642 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005643 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5644 Inits, &InitChanged))
5645 return ExprError();
5646
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005648 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005651 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005652}
Mike Stump11289f42009-09-09 15:08:12 +00005653
Douglas Gregora16548e2009-08-11 05:31:07 +00005654template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005655ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005656TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005658
Douglas Gregorebe10102009-08-20 07:17:43 +00005659 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005660 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregorebe10102009-08-20 07:17:43 +00005664 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005665 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005666 bool ExprChanged = false;
5667 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5668 DEnd = E->designators_end();
5669 D != DEnd; ++D) {
5670 if (D->isFieldDesignator()) {
5671 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5672 D->getDotLoc(),
5673 D->getFieldLoc()));
5674 continue;
5675 }
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregora16548e2009-08-11 05:31:07 +00005677 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005678 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005681
5682 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005683 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005684
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5686 ArrayExprs.push_back(Index.release());
5687 continue;
5688 }
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregora16548e2009-08-11 05:31:07 +00005690 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005691 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5693 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005694 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005695
John McCalldadc5752010-08-24 06:29:42 +00005696 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005698 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005699
5700 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 End.get(),
5702 D->getLBracketLoc(),
5703 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005704
Douglas Gregora16548e2009-08-11 05:31:07 +00005705 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5706 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005707
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 ArrayExprs.push_back(Start.release());
5709 ArrayExprs.push_back(End.release());
5710 }
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 if (!getDerived().AlwaysRebuild() &&
5713 Init.get() == E->getInit() &&
5714 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005715 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregora16548e2009-08-11 05:31:07 +00005717 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5718 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005719 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005720}
Mike Stump11289f42009-09-09 15:08:12 +00005721
Douglas Gregora16548e2009-08-11 05:31:07 +00005722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005723ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005724TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005725 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005726 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005727
Douglas Gregor3da3c062009-10-28 00:29:27 +00005728 // FIXME: Will we ever have proper type location here? Will we actually
5729 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 QualType T = getDerived().TransformType(E->getType());
5731 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 if (!getDerived().AlwaysRebuild() &&
5735 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005736 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 return getDerived().RebuildImplicitValueInitExpr(T);
5739}
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005743TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005744 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5745 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005747
John McCalldadc5752010-08-24 06:29:42 +00005748 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005751
Douglas Gregora16548e2009-08-11 05:31:07 +00005752 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005753 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005755 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005756
John McCallb268a282010-08-23 23:25:46 +00005757 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005758 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005759}
5760
5761template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005762ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005763TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005765 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005766 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5767 &ArgumentChanged))
5768 return ExprError();
5769
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5771 move_arg(Inits),
5772 E->getRParenLoc());
5773}
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregora16548e2009-08-11 05:31:07 +00005775/// \brief Transform an address-of-label expression.
5776///
5777/// By default, the transformation of an address-of-label expression always
5778/// rebuilds the expression, so that the label identifier can be resolved to
5779/// the corresponding label statement by semantic analysis.
5780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005782TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5784 E->getLabel());
5785}
Mike Stump11289f42009-09-09 15:08:12 +00005786
5787template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005788ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005789TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005790 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5792 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005793 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005794
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 if (!getDerived().AlwaysRebuild() &&
5796 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005797 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005798
5799 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005800 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005801 E->getRParenLoc());
5802}
Mike Stump11289f42009-09-09 15:08:12 +00005803
Douglas Gregora16548e2009-08-11 05:31:07 +00005804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005806TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005807 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005810
John McCalldadc5752010-08-24 06:29:42 +00005811 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005814
John McCalldadc5752010-08-24 06:29:42 +00005815 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005816 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005817 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005818
Douglas Gregora16548e2009-08-11 05:31:07 +00005819 if (!getDerived().AlwaysRebuild() &&
5820 Cond.get() == E->getCond() &&
5821 LHS.get() == E->getLHS() &&
5822 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005823 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005824
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005826 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 E->getRParenLoc());
5828}
Mike Stump11289f42009-09-09 15:08:12 +00005829
Douglas Gregora16548e2009-08-11 05:31:07 +00005830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005832TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005833 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005834}
5835
5836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005838TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005839 switch (E->getOperator()) {
5840 case OO_New:
5841 case OO_Delete:
5842 case OO_Array_New:
5843 case OO_Array_Delete:
5844 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005845 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005846
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005847 case OO_Call: {
5848 // This is a call to an object's operator().
5849 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5850
5851 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005852 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005853 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005855
5856 // FIXME: Poor location information
5857 SourceLocation FakeLParenLoc
5858 = SemaRef.PP.getLocForEndOfToken(
5859 static_cast<Expr *>(Object.get())->getLocEnd());
5860
5861 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005862 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005863 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5864 Args))
5865 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005866
John McCallb268a282010-08-23 23:25:46 +00005867 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005868 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005869 E->getLocEnd());
5870 }
5871
5872#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5873 case OO_##Name:
5874#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5875#include "clang/Basic/OperatorKinds.def"
5876 case OO_Subscript:
5877 // Handled below.
5878 break;
5879
5880 case OO_Conditional:
5881 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005883
5884 case OO_None:
5885 case NUM_OVERLOADED_OPERATORS:
5886 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005887 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005888 }
5889
John McCalldadc5752010-08-24 06:29:42 +00005890 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005892 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005893
John McCalldadc5752010-08-24 06:29:42 +00005894 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005895 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005896 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005897
John McCalldadc5752010-08-24 06:29:42 +00005898 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005899 if (E->getNumArgs() == 2) {
5900 Second = getDerived().TransformExpr(E->getArg(1));
5901 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 }
Mike Stump11289f42009-09-09 15:08:12 +00005904
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 if (!getDerived().AlwaysRebuild() &&
5906 Callee.get() == E->getCallee() &&
5907 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005908 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005909 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005910
Douglas Gregora16548e2009-08-11 05:31:07 +00005911 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5912 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005913 Callee.get(),
5914 First.get(),
5915 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005916}
Mike Stump11289f42009-09-09 15:08:12 +00005917
Douglas Gregora16548e2009-08-11 05:31:07 +00005918template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005919ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005920TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5921 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005922}
Mike Stump11289f42009-09-09 15:08:12 +00005923
Douglas Gregora16548e2009-08-11 05:31:07 +00005924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005926TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005927 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5928 if (!Type)
5929 return ExprError();
5930
John McCalldadc5752010-08-24 06:29:42 +00005931 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005932 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005933 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005935
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005937 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005938 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005939 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005940
Douglas Gregora16548e2009-08-11 05:31:07 +00005941 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005942 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005943 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5944 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5945 SourceLocation FakeRParenLoc
5946 = SemaRef.PP.getLocForEndOfToken(
5947 E->getSubExpr()->getSourceRange().getEnd());
5948 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005949 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005950 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005951 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 FakeRAngleLoc,
5953 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005954 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005955 FakeRParenLoc);
5956}
Mike Stump11289f42009-09-09 15:08:12 +00005957
Douglas Gregora16548e2009-08-11 05:31:07 +00005958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005960TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5961 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005962}
Mike Stump11289f42009-09-09 15:08:12 +00005963
5964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005966TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5967 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005968}
5969
Douglas Gregora16548e2009-08-11 05:31:07 +00005970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005971ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005972TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005973 CXXReinterpretCastExpr *E) {
5974 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005975}
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregora16548e2009-08-11 05:31:07 +00005977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005978ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005979TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5980 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005981}
Mike Stump11289f42009-09-09 15:08:12 +00005982
Douglas Gregora16548e2009-08-11 05:31:07 +00005983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005984ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005985TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005986 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005987 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5988 if (!Type)
5989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005990
John McCalldadc5752010-08-24 06:29:42 +00005991 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005992 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005993 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005997 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005999 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006000
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006001 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006002 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006003 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 E->getRParenLoc());
6005}
Mike Stump11289f42009-09-09 15:08:12 +00006006
Douglas Gregora16548e2009-08-11 05:31:07 +00006007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006011 TypeSourceInfo *TInfo
6012 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6013 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006015
Douglas Gregora16548e2009-08-11 05:31:07 +00006016 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006017 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006018 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006019
Douglas Gregor9da64192010-04-26 22:37:10 +00006020 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6021 E->getLocStart(),
6022 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006023 E->getLocEnd());
6024 }
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 // We don't know whether the expression is potentially evaluated until
6027 // after we perform semantic analysis, so the expression is potentially
6028 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006029 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006030 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006031
John McCalldadc5752010-08-24 06:29:42 +00006032 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006033 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregora16548e2009-08-11 05:31:07 +00006036 if (!getDerived().AlwaysRebuild() &&
6037 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006038 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006039
Douglas Gregor9da64192010-04-26 22:37:10 +00006040 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6041 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006042 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 E->getLocEnd());
6044}
6045
6046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006047ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006048TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6049 if (E->isTypeOperand()) {
6050 TypeSourceInfo *TInfo
6051 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6052 if (!TInfo)
6053 return ExprError();
6054
6055 if (!getDerived().AlwaysRebuild() &&
6056 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006057 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006058
6059 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6060 E->getLocStart(),
6061 TInfo,
6062 E->getLocEnd());
6063 }
6064
6065 // We don't know whether the expression is potentially evaluated until
6066 // after we perform semantic analysis, so the expression is potentially
6067 // potentially evaluated.
6068 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6069
6070 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6071 if (SubExpr.isInvalid())
6072 return ExprError();
6073
6074 if (!getDerived().AlwaysRebuild() &&
6075 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006076 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006077
6078 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6079 E->getLocStart(),
6080 SubExpr.get(),
6081 E->getLocEnd());
6082}
6083
6084template<typename Derived>
6085ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006086TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006087 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006088}
Mike Stump11289f42009-09-09 15:08:12 +00006089
Douglas Gregora16548e2009-08-11 05:31:07 +00006090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006091ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006092TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006093 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006094 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006095}
Mike Stump11289f42009-09-09 15:08:12 +00006096
Douglas Gregora16548e2009-08-11 05:31:07 +00006097template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006098ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006099TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006100 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6101 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6102 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006103
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006104 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006105 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregorb15af892010-01-07 23:12:05 +00006107 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006108}
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregora16548e2009-08-11 05:31:07 +00006110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006112TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006113 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006114 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006115 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006116
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 if (!getDerived().AlwaysRebuild() &&
6118 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006120
John McCallb268a282010-08-23 23:25:46 +00006121 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006122}
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006126TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006127 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006128 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6129 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006132
Chandler Carruth794da4c2010-02-08 06:42:49 +00006133 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006134 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006135 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregor033f6752009-12-23 23:03:06 +00006137 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006138}
Mike Stump11289f42009-09-09 15:08:12 +00006139
Douglas Gregora16548e2009-08-11 05:31:07 +00006140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006141ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006142TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6143 CXXScalarValueInitExpr *E) {
6144 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6145 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006146 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006147
Douglas Gregora16548e2009-08-11 05:31:07 +00006148 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006149 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006150 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregor2b88c112010-09-08 00:15:04 +00006152 return getDerived().RebuildCXXScalarValueInitExpr(T,
6153 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006154 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006155}
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregora16548e2009-08-11 05:31:07 +00006157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006159TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006160 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006161 TypeSourceInfo *AllocTypeInfo
6162 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6163 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregora16548e2009-08-11 05:31:07 +00006166 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006167 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006168 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006169 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006170
Douglas Gregora16548e2009-08-11 05:31:07 +00006171 // Transform the placement arguments (if any).
6172 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006173 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006174 if (getDerived().TransformExprs(E->getPlacementArgs(),
6175 E->getNumPlacementArgs(), true,
6176 PlacementArgs, &ArgumentChanged))
6177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006178
Douglas Gregorebe10102009-08-20 07:17:43 +00006179 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006180 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006181 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6182 ConstructorArgs, &ArgumentChanged))
6183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006184
Douglas Gregord2d9da02010-02-26 00:38:10 +00006185 // Transform constructor, new operator, and delete operator.
6186 CXXConstructorDecl *Constructor = 0;
6187 if (E->getConstructor()) {
6188 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006189 getDerived().TransformDecl(E->getLocStart(),
6190 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006191 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006192 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006193 }
6194
6195 FunctionDecl *OperatorNew = 0;
6196 if (E->getOperatorNew()) {
6197 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006198 getDerived().TransformDecl(E->getLocStart(),
6199 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006200 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006201 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006202 }
6203
6204 FunctionDecl *OperatorDelete = 0;
6205 if (E->getOperatorDelete()) {
6206 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006207 getDerived().TransformDecl(E->getLocStart(),
6208 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006209 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006211 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006212
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006214 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006216 Constructor == E->getConstructor() &&
6217 OperatorNew == E->getOperatorNew() &&
6218 OperatorDelete == E->getOperatorDelete() &&
6219 !ArgumentChanged) {
6220 // Mark any declarations we need as referenced.
6221 // FIXME: instantiation-specific.
6222 if (Constructor)
6223 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6224 if (OperatorNew)
6225 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6226 if (OperatorDelete)
6227 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006228 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006229 }
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregor0744ef62010-09-07 21:49:58 +00006231 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006232 if (!ArraySize.get()) {
6233 // If no array size was specified, but the new expression was
6234 // instantiated with an array type (e.g., "new T" where T is
6235 // instantiated with "int[4]"), extract the outer bound from the
6236 // array type as our array size. We do this with constant and
6237 // dependently-sized array types.
6238 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6239 if (!ArrayT) {
6240 // Do nothing
6241 } else if (const ConstantArrayType *ConsArrayT
6242 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006243 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006244 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6245 ConsArrayT->getSize(),
6246 SemaRef.Context.getSizeType(),
6247 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006248 AllocType = ConsArrayT->getElementType();
6249 } else if (const DependentSizedArrayType *DepArrayT
6250 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6251 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006252 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006253 AllocType = DepArrayT->getElementType();
6254 }
6255 }
6256 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006257
Douglas Gregora16548e2009-08-11 05:31:07 +00006258 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6259 E->isGlobalNew(),
6260 /*FIXME:*/E->getLocStart(),
6261 move_arg(PlacementArgs),
6262 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006263 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006264 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006265 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006266 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 /*FIXME:*/E->getLocStart(),
6268 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006269 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006270}
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregora16548e2009-08-11 05:31:07 +00006272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006274TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006275 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006276 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregord2d9da02010-02-26 00:38:10 +00006279 // Transform the delete operator, if known.
6280 FunctionDecl *OperatorDelete = 0;
6281 if (E->getOperatorDelete()) {
6282 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006283 getDerived().TransformDecl(E->getLocStart(),
6284 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006285 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006286 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006287 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006288
Douglas Gregora16548e2009-08-11 05:31:07 +00006289 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006290 Operand.get() == E->getArgument() &&
6291 OperatorDelete == E->getOperatorDelete()) {
6292 // Mark any declarations we need as referenced.
6293 // FIXME: instantiation-specific.
6294 if (OperatorDelete)
6295 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006296
6297 if (!E->getArgument()->isTypeDependent()) {
6298 QualType Destroyed = SemaRef.Context.getBaseElementType(
6299 E->getDestroyedType());
6300 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6301 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6302 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6303 SemaRef.LookupDestructor(Record));
6304 }
6305 }
6306
John McCallc3007a22010-10-26 07:05:15 +00006307 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006308 }
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregora16548e2009-08-11 05:31:07 +00006310 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6311 E->isGlobalDelete(),
6312 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006313 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006314}
Mike Stump11289f42009-09-09 15:08:12 +00006315
Douglas Gregora16548e2009-08-11 05:31:07 +00006316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006317ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006318TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006319 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006320 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006321 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006322 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006323
John McCallba7bf592010-08-24 05:47:05 +00006324 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006325 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006326 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006327 E->getOperatorLoc(),
6328 E->isArrow()? tok::arrow : tok::period,
6329 ObjectTypePtr,
6330 MayBePseudoDestructor);
6331 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006332 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006333
John McCallba7bf592010-08-24 05:47:05 +00006334 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006335 NestedNameSpecifier *Qualifier = E->getQualifier();
6336 if (Qualifier) {
6337 Qualifier
6338 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6339 E->getQualifierRange(),
6340 ObjectType);
6341 if (!Qualifier)
6342 return ExprError();
6343 }
Mike Stump11289f42009-09-09 15:08:12 +00006344
Douglas Gregor678f90d2010-02-25 01:56:36 +00006345 PseudoDestructorTypeStorage Destroyed;
6346 if (E->getDestroyedTypeInfo()) {
6347 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006348 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6349 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006350 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006351 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006352 Destroyed = DestroyedTypeInfo;
6353 } else if (ObjectType->isDependentType()) {
6354 // We aren't likely to be able to resolve the identifier down to a type
6355 // now anyway, so just retain the identifier.
6356 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6357 E->getDestroyedTypeLoc());
6358 } else {
6359 // Look for a destructor known with the given name.
6360 CXXScopeSpec SS;
6361 if (Qualifier) {
6362 SS.setScopeRep(Qualifier);
6363 SS.setRange(E->getQualifierRange());
6364 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006365
John McCallba7bf592010-08-24 05:47:05 +00006366 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006367 *E->getDestroyedTypeIdentifier(),
6368 E->getDestroyedTypeLoc(),
6369 /*Scope=*/0,
6370 SS, ObjectTypePtr,
6371 false);
6372 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006373 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006374
Douglas Gregor678f90d2010-02-25 01:56:36 +00006375 Destroyed
6376 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6377 E->getDestroyedTypeLoc());
6378 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006379
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006380 TypeSourceInfo *ScopeTypeInfo = 0;
6381 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006382 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006383 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006385 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006386
John McCallb268a282010-08-23 23:25:46 +00006387 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006388 E->getOperatorLoc(),
6389 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006390 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006391 E->getQualifierRange(),
6392 ScopeTypeInfo,
6393 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006394 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006395 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006396}
Mike Stump11289f42009-09-09 15:08:12 +00006397
Douglas Gregorad8a3362009-09-04 17:36:40 +00006398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006399ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006400TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006401 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006402 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6403
6404 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6405 Sema::LookupOrdinaryName);
6406
6407 // Transform all the decls.
6408 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6409 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006410 NamedDecl *InstD = static_cast<NamedDecl*>(
6411 getDerived().TransformDecl(Old->getNameLoc(),
6412 *I));
John McCall84d87672009-12-10 09:41:52 +00006413 if (!InstD) {
6414 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6415 // This can happen because of dependent hiding.
6416 if (isa<UsingShadowDecl>(*I))
6417 continue;
6418 else
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006420 }
John McCalle66edc12009-11-24 19:00:30 +00006421
6422 // Expand using declarations.
6423 if (isa<UsingDecl>(InstD)) {
6424 UsingDecl *UD = cast<UsingDecl>(InstD);
6425 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6426 E = UD->shadow_end(); I != E; ++I)
6427 R.addDecl(*I);
6428 continue;
6429 }
6430
6431 R.addDecl(InstD);
6432 }
6433
6434 // Resolve a kind, but don't do any further analysis. If it's
6435 // ambiguous, the callee needs to deal with it.
6436 R.resolveKind();
6437
6438 // Rebuild the nested-name qualifier, if present.
6439 CXXScopeSpec SS;
6440 NestedNameSpecifier *Qualifier = 0;
6441 if (Old->getQualifier()) {
6442 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006443 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006444 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006445 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006446
John McCalle66edc12009-11-24 19:00:30 +00006447 SS.setScopeRep(Qualifier);
6448 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006449 }
6450
Douglas Gregor9262f472010-04-27 18:19:34 +00006451 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006452 CXXRecordDecl *NamingClass
6453 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6454 Old->getNameLoc(),
6455 Old->getNamingClass()));
6456 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006457 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006458
Douglas Gregorda7be082010-04-27 16:10:10 +00006459 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006460 }
6461
6462 // If we have no template arguments, it's a normal declaration name.
6463 if (!Old->hasExplicitTemplateArgs())
6464 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6465
6466 // If we have template arguments, rebuild them, then rebuild the
6467 // templateid expression.
6468 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006469 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6470 Old->getNumTemplateArgs(),
6471 TransArgs))
6472 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006473
6474 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6475 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006476}
Mike Stump11289f42009-09-09 15:08:12 +00006477
Douglas Gregora16548e2009-08-11 05:31:07 +00006478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006479ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006481 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6482 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006484
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006486 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006488
Mike Stump11289f42009-09-09 15:08:12 +00006489 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006491 T,
6492 E->getLocEnd());
6493}
Mike Stump11289f42009-09-09 15:08:12 +00006494
Douglas Gregora16548e2009-08-11 05:31:07 +00006495template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006496ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006497TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6498 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6499 if (!LhsT)
6500 return ExprError();
6501
6502 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6503 if (!RhsT)
6504 return ExprError();
6505
6506 if (!getDerived().AlwaysRebuild() &&
6507 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6508 return SemaRef.Owned(E);
6509
6510 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6511 E->getLocStart(),
6512 LhsT, RhsT,
6513 E->getLocEnd());
6514}
6515
6516template<typename Derived>
6517ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006518TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006519 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006520 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006521 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006522 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006524 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006525
John McCall31f82722010-11-12 08:19:04 +00006526 // TODO: If this is a conversion-function-id, verify that the
6527 // destination type name (if present) resolves the same way after
6528 // instantiation as it did in the local scope.
6529
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006530 DeclarationNameInfo NameInfo
6531 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6532 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006533 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006534
John McCalle66edc12009-11-24 19:00:30 +00006535 if (!E->hasExplicitTemplateArgs()) {
6536 if (!getDerived().AlwaysRebuild() &&
6537 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006538 // Note: it is sufficient to compare the Name component of NameInfo:
6539 // if name has not changed, DNLoc has not changed either.
6540 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006541 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006542
John McCalle66edc12009-11-24 19:00:30 +00006543 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6544 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006545 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006546 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006547 }
John McCall6b51f282009-11-23 01:53:49 +00006548
6549 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006550 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6551 E->getNumTemplateArgs(),
6552 TransArgs))
6553 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006554
John McCalle66edc12009-11-24 19:00:30 +00006555 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6556 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006557 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006558 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006559}
6560
6561template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006562ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006563TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006564 // CXXConstructExprs are always implicit, so when we have a
6565 // 1-argument construction we just transform that argument.
6566 if (E->getNumArgs() == 1 ||
6567 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6568 return getDerived().TransformExpr(E->getArg(0));
6569
Douglas Gregora16548e2009-08-11 05:31:07 +00006570 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6571
6572 QualType T = getDerived().TransformType(E->getType());
6573 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006575
6576 CXXConstructorDecl *Constructor
6577 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006578 getDerived().TransformDecl(E->getLocStart(),
6579 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006580 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006582
Douglas Gregora16548e2009-08-11 05:31:07 +00006583 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006584 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006585 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6586 &ArgumentChanged))
6587 return ExprError();
6588
Douglas Gregora16548e2009-08-11 05:31:07 +00006589 if (!getDerived().AlwaysRebuild() &&
6590 T == E->getType() &&
6591 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006592 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006593 // Mark the constructor as referenced.
6594 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006595 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006596 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006597 }
Mike Stump11289f42009-09-09 15:08:12 +00006598
Douglas Gregordb121ba2009-12-14 16:27:04 +00006599 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6600 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006601 move_arg(Args),
6602 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006603 E->getConstructionKind(),
6604 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006605}
Mike Stump11289f42009-09-09 15:08:12 +00006606
Douglas Gregora16548e2009-08-11 05:31:07 +00006607/// \brief Transform a C++ temporary-binding expression.
6608///
Douglas Gregor363b1512009-12-24 18:51:59 +00006609/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6610/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006613TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006614 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006615}
Mike Stump11289f42009-09-09 15:08:12 +00006616
John McCall5d413782010-12-06 08:20:24 +00006617/// \brief Transform a C++ expression that contains cleanups that should
6618/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006619///
John McCall5d413782010-12-06 08:20:24 +00006620/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006621/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006623ExprResult
John McCall5d413782010-12-06 08:20:24 +00006624TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006625 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006626}
Mike Stump11289f42009-09-09 15:08:12 +00006627
Douglas Gregora16548e2009-08-11 05:31:07 +00006628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006629ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006630TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006631 CXXTemporaryObjectExpr *E) {
6632 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6633 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006635
Douglas Gregora16548e2009-08-11 05:31:07 +00006636 CXXConstructorDecl *Constructor
6637 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006638 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006639 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006640 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006641 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006644 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006646 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6647 &ArgumentChanged))
6648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006649
Douglas Gregora16548e2009-08-11 05:31:07 +00006650 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006651 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006652 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006653 !ArgumentChanged) {
6654 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006655 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006656 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006657 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006658
6659 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6660 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006661 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006662 E->getLocEnd());
6663}
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregora16548e2009-08-11 05:31:07 +00006665template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006666ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006667TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006668 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006669 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6670 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006672
Douglas Gregora16548e2009-08-11 05:31:07 +00006673 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006674 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006675 Args.reserve(E->arg_size());
6676 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6677 &ArgumentChanged))
6678 return ExprError();
6679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006681 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006683 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006684
Douglas Gregora16548e2009-08-11 05:31:07 +00006685 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006686 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 E->getLParenLoc(),
6688 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 E->getRParenLoc());
6690}
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregora16548e2009-08-11 05:31:07 +00006692template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006693ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006694TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006695 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006696 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006697 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006698 Expr *OldBase;
6699 QualType BaseType;
6700 QualType ObjectType;
6701 if (!E->isImplicitAccess()) {
6702 OldBase = E->getBase();
6703 Base = getDerived().TransformExpr(OldBase);
6704 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006706
John McCall2d74de92009-12-01 22:10:20 +00006707 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006708 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006709 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006710 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006711 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006712 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006713 ObjectTy,
6714 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006715 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006717
John McCallba7bf592010-08-24 05:47:05 +00006718 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006719 BaseType = ((Expr*) Base.get())->getType();
6720 } else {
6721 OldBase = 0;
6722 BaseType = getDerived().TransformType(E->getBaseType());
6723 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6724 }
Mike Stump11289f42009-09-09 15:08:12 +00006725
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006726 // Transform the first part of the nested-name-specifier that qualifies
6727 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006728 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006729 = getDerived().TransformFirstQualifierInScope(
6730 E->getFirstQualifierFoundInScope(),
6731 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006732
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006733 NestedNameSpecifier *Qualifier = 0;
6734 if (E->getQualifier()) {
6735 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6736 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006737 ObjectType,
6738 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006739 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006740 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006741 }
Mike Stump11289f42009-09-09 15:08:12 +00006742
John McCall31f82722010-11-12 08:19:04 +00006743 // TODO: If this is a conversion-function-id, verify that the
6744 // destination type name (if present) resolves the same way after
6745 // instantiation as it did in the local scope.
6746
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006747 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006748 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006749 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006751
John McCall2d74de92009-12-01 22:10:20 +00006752 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006753 // This is a reference to a member without an explicitly-specified
6754 // template argument list. Optimize for this common case.
6755 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006756 Base.get() == OldBase &&
6757 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006758 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006759 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006760 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006761 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006762
John McCallb268a282010-08-23 23:25:46 +00006763 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006764 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006765 E->isArrow(),
6766 E->getOperatorLoc(),
6767 Qualifier,
6768 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006769 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006770 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006771 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006772 }
6773
John McCall6b51f282009-11-23 01:53:49 +00006774 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006775 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6776 E->getNumTemplateArgs(),
6777 TransArgs))
6778 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006779
John McCallb268a282010-08-23 23:25:46 +00006780 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006781 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006782 E->isArrow(),
6783 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006784 Qualifier,
6785 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006786 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006787 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006788 &TransArgs);
6789}
6790
6791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006793TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006794 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006795 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006796 QualType BaseType;
6797 if (!Old->isImplicitAccess()) {
6798 Base = getDerived().TransformExpr(Old->getBase());
6799 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006800 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006801 BaseType = ((Expr*) Base.get())->getType();
6802 } else {
6803 BaseType = getDerived().TransformType(Old->getBaseType());
6804 }
John McCall10eae182009-11-30 22:42:35 +00006805
6806 NestedNameSpecifier *Qualifier = 0;
6807 if (Old->getQualifier()) {
6808 Qualifier
6809 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006810 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006811 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006812 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006813 }
6814
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006815 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006816 Sema::LookupOrdinaryName);
6817
6818 // Transform all the decls.
6819 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6820 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006821 NamedDecl *InstD = static_cast<NamedDecl*>(
6822 getDerived().TransformDecl(Old->getMemberLoc(),
6823 *I));
John McCall84d87672009-12-10 09:41:52 +00006824 if (!InstD) {
6825 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6826 // This can happen because of dependent hiding.
6827 if (isa<UsingShadowDecl>(*I))
6828 continue;
6829 else
John McCallfaf5fb42010-08-26 23:41:50 +00006830 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006831 }
John McCall10eae182009-11-30 22:42:35 +00006832
6833 // Expand using declarations.
6834 if (isa<UsingDecl>(InstD)) {
6835 UsingDecl *UD = cast<UsingDecl>(InstD);
6836 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6837 E = UD->shadow_end(); I != E; ++I)
6838 R.addDecl(*I);
6839 continue;
6840 }
6841
6842 R.addDecl(InstD);
6843 }
6844
6845 R.resolveKind();
6846
Douglas Gregor9262f472010-04-27 18:19:34 +00006847 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006848 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006849 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006850 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006851 Old->getMemberLoc(),
6852 Old->getNamingClass()));
6853 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006854 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006855
Douglas Gregorda7be082010-04-27 16:10:10 +00006856 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006857 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006858
John McCall10eae182009-11-30 22:42:35 +00006859 TemplateArgumentListInfo TransArgs;
6860 if (Old->hasExplicitTemplateArgs()) {
6861 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6862 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006863 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6864 Old->getNumTemplateArgs(),
6865 TransArgs))
6866 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006867 }
John McCall38836f02010-01-15 08:34:02 +00006868
6869 // FIXME: to do this check properly, we will need to preserve the
6870 // first-qualifier-in-scope here, just in case we had a dependent
6871 // base (and therefore couldn't do the check) and a
6872 // nested-name-qualifier (and therefore could do the lookup).
6873 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006874
John McCallb268a282010-08-23 23:25:46 +00006875 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006876 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006877 Old->getOperatorLoc(),
6878 Old->isArrow(),
6879 Qualifier,
6880 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006881 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006882 R,
6883 (Old->hasExplicitTemplateArgs()
6884 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006885}
6886
6887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006888ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006889TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6890 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6891 if (SubExpr.isInvalid())
6892 return ExprError();
6893
6894 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006895 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006896
6897 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6898}
6899
6900template<typename Derived>
6901ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006902TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006903 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6904 if (Pattern.isInvalid())
6905 return ExprError();
6906
6907 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6908 return SemaRef.Owned(E);
6909
Douglas Gregorb8840002011-01-14 21:20:45 +00006910 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6911 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006912}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006913
6914template<typename Derived>
6915ExprResult
6916TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6917 // If E is not value-dependent, then nothing will change when we transform it.
6918 // Note: This is an instantiation-centric view.
6919 if (!E->isValueDependent())
6920 return SemaRef.Owned(E);
6921
6922 // Note: None of the implementations of TryExpandParameterPacks can ever
6923 // produce a diagnostic when given only a single unexpanded parameter pack,
6924 // so
6925 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6926 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006927 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006928 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006929 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6930 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006931 ShouldExpand, RetainExpansion,
6932 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006933 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006934
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006935 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006936 return SemaRef.Owned(E);
6937
6938 // We now know the length of the parameter pack, so build a new expression
6939 // that stores that length.
6940 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6941 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006942 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006943}
6944
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006945template<typename Derived>
6946ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00006947TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
6948 SubstNonTypeTemplateParmPackExpr *E) {
6949 // Default behavior is to do nothing with this transformation.
6950 return SemaRef.Owned(E);
6951}
6952
6953template<typename Derived>
6954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006955TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006956 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006957}
6958
Mike Stump11289f42009-09-09 15:08:12 +00006959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006961TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006962 TypeSourceInfo *EncodedTypeInfo
6963 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6964 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006965 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006966
Douglas Gregora16548e2009-08-11 05:31:07 +00006967 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006968 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006969 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006970
6971 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006972 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 E->getRParenLoc());
6974}
Mike Stump11289f42009-09-09 15:08:12 +00006975
Douglas Gregora16548e2009-08-11 05:31:07 +00006976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006978TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006979 // Transform arguments.
6980 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006981 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006982 Args.reserve(E->getNumArgs());
6983 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6984 &ArgChanged))
6985 return ExprError();
6986
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006987 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6988 // Class message: transform the receiver type.
6989 TypeSourceInfo *ReceiverTypeInfo
6990 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6991 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006992 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006993
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006994 // If nothing changed, just retain the existing message send.
6995 if (!getDerived().AlwaysRebuild() &&
6996 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006997 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006998
6999 // Build a new class message send.
7000 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7001 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007002 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007003 E->getMethodDecl(),
7004 E->getLeftLoc(),
7005 move_arg(Args),
7006 E->getRightLoc());
7007 }
7008
7009 // Instance message: transform the receiver
7010 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7011 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007012 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007013 = getDerived().TransformExpr(E->getInstanceReceiver());
7014 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007015 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007016
7017 // If nothing changed, just retain the existing message send.
7018 if (!getDerived().AlwaysRebuild() &&
7019 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007020 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007021
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007022 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007023 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007024 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007025 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007026 E->getMethodDecl(),
7027 E->getLeftLoc(),
7028 move_arg(Args),
7029 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007030}
7031
Mike Stump11289f42009-09-09 15:08:12 +00007032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007033ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007034TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007036}
7037
Mike Stump11289f42009-09-09 15:08:12 +00007038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007040TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007041 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007042}
7043
Mike Stump11289f42009-09-09 15:08:12 +00007044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007046TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007047 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007048 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007049 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007050 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007051
7052 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007053
Douglas Gregord51d90d2010-04-26 20:11:03 +00007054 // If nothing changed, just retain the existing expression.
7055 if (!getDerived().AlwaysRebuild() &&
7056 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007057 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007058
John McCallb268a282010-08-23 23:25:46 +00007059 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007060 E->getLocation(),
7061 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007062}
7063
Mike Stump11289f42009-09-09 15:08:12 +00007064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007066TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007067 // 'super' and types never change. Property never changes. Just
7068 // retain the existing expression.
7069 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007070 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007071
Douglas Gregor9faee212010-04-26 20:47:02 +00007072 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007073 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007074 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007075 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007076
Douglas Gregor9faee212010-04-26 20:47:02 +00007077 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007078
Douglas Gregor9faee212010-04-26 20:47:02 +00007079 // If nothing changed, just retain the existing expression.
7080 if (!getDerived().AlwaysRebuild() &&
7081 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007083
John McCallb7bd14f2010-12-02 01:19:52 +00007084 if (E->isExplicitProperty())
7085 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7086 E->getExplicitProperty(),
7087 E->getLocation());
7088
7089 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7090 E->getType(),
7091 E->getImplicitPropertyGetter(),
7092 E->getImplicitPropertySetter(),
7093 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007094}
7095
Mike Stump11289f42009-09-09 15:08:12 +00007096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007097ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007098TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007099 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007100 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007101 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007102 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007103
Douglas Gregord51d90d2010-04-26 20:11:03 +00007104 // If nothing changed, just retain the existing expression.
7105 if (!getDerived().AlwaysRebuild() &&
7106 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007107 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007108
John McCallb268a282010-08-23 23:25:46 +00007109 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007110 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007111}
7112
Mike Stump11289f42009-09-09 15:08:12 +00007113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007114ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007115TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007116 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007117 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007118 SubExprs.reserve(E->getNumSubExprs());
7119 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7120 SubExprs, &ArgumentChanged))
7121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007122
Douglas Gregora16548e2009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() &&
7124 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007125 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007126
Douglas Gregora16548e2009-08-11 05:31:07 +00007127 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7128 move_arg(SubExprs),
7129 E->getRParenLoc());
7130}
7131
Mike Stump11289f42009-09-09 15:08:12 +00007132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007135 SourceLocation CaretLoc(E->getExprLoc());
7136
7137 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7138 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7139 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7140 llvm::SmallVector<ParmVarDecl*, 4> Params;
7141 llvm::SmallVector<QualType, 4> ParamTypes;
7142
7143 // Parameter substitution.
Douglas Gregor476e3022011-01-19 21:32:01 +00007144 BlockDecl *BD = E->getBlockDecl();
7145 if (getDerived().TransformFunctionTypeParams(E->getLocStart(),
7146 BD->param_begin(),
7147 BD->param_size(), 0, ParamTypes,
7148 &Params))
7149 return true;
7150
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007151
7152 const FunctionType *BExprFunctionType = E->getFunctionType();
7153 QualType BExprResultType = BExprFunctionType->getResultType();
7154 if (!BExprResultType.isNull()) {
7155 if (!BExprResultType->isDependentType())
7156 CurBlock->ReturnType = BExprResultType;
7157 else if (BExprResultType != SemaRef.Context.DependentTy)
7158 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7159 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007160
7161 // If the return type has not been determined yet, leave it as a dependent
7162 // type; it'll get set when we process the body.
7163 if (CurBlock->ReturnType.isNull())
7164 CurBlock->ReturnType = getSema().Context.DependentTy;
7165
7166 // Don't allow returning a objc interface by value.
7167 if (CurBlock->ReturnType->isObjCObjectType()) {
7168 getSema().Diag(E->getLocStart(),
7169 diag::err_object_cannot_be_passed_returned_by_value)
7170 << 0 << CurBlock->ReturnType;
7171 return ExprError();
7172 }
John McCall3882ace2011-01-05 12:14:39 +00007173
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007174 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7175 CurBlock->ReturnType,
7176 ParamTypes.data(),
7177 ParamTypes.size(),
7178 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007179 0,
7180 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007181 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00007182
7183 // Set the parameters on the block decl.
7184 if (!Params.empty())
7185 CurBlock->TheDecl->setParams(Params.data(), Params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007186
7187 // If the return type wasn't explicitly set, it will have been marked as a
7188 // dependent type (DependentTy); clear out the return type setting so
7189 // we will deduce the return type when type-checking the block's body.
7190 if (CurBlock->ReturnType == getSema().Context.DependentTy)
7191 CurBlock->ReturnType = QualType();
7192
John McCall3882ace2011-01-05 12:14:39 +00007193 // Transform the body
7194 StmtResult Body = getDerived().TransformStmt(E->getBody());
7195 if (Body.isInvalid())
7196 return ExprError();
7197
John McCallb268a282010-08-23 23:25:46 +00007198 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007199}
7200
Mike Stump11289f42009-09-09 15:08:12 +00007201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007203TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007204 NestedNameSpecifier *Qualifier = 0;
7205
7206 ValueDecl *ND
7207 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7208 E->getDecl()));
7209 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007210 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007211
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007212 if (!getDerived().AlwaysRebuild() &&
7213 ND == E->getDecl()) {
7214 // Mark it referenced in the new context regardless.
7215 // FIXME: this is a bit instantiation-specific.
7216 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7217
John McCallc3007a22010-10-26 07:05:15 +00007218 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007219 }
7220
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007221 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007222 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007223 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007224}
Mike Stump11289f42009-09-09 15:08:12 +00007225
Douglas Gregora16548e2009-08-11 05:31:07 +00007226//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007227// Type reconstruction
7228//===----------------------------------------------------------------------===//
7229
Mike Stump11289f42009-09-09 15:08:12 +00007230template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007231QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7232 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007233 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007234 getDerived().getBaseEntity());
7235}
7236
Mike Stump11289f42009-09-09 15:08:12 +00007237template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007238QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7239 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007240 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007241 getDerived().getBaseEntity());
7242}
7243
Mike Stump11289f42009-09-09 15:08:12 +00007244template<typename Derived>
7245QualType
John McCall70dd5f62009-10-30 00:06:24 +00007246TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7247 bool WrittenAsLValue,
7248 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007249 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007250 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007251}
7252
7253template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007254QualType
John McCall70dd5f62009-10-30 00:06:24 +00007255TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7256 QualType ClassType,
7257 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007258 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007259 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007260}
7261
7262template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007263QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007264TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7265 ArrayType::ArraySizeModifier SizeMod,
7266 const llvm::APInt *Size,
7267 Expr *SizeExpr,
7268 unsigned IndexTypeQuals,
7269 SourceRange BracketsRange) {
7270 if (SizeExpr || !Size)
7271 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7272 IndexTypeQuals, BracketsRange,
7273 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007274
7275 QualType Types[] = {
7276 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7277 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7278 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007279 };
7280 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7281 QualType SizeType;
7282 for (unsigned I = 0; I != NumTypes; ++I)
7283 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7284 SizeType = Types[I];
7285 break;
7286 }
Mike Stump11289f42009-09-09 15:08:12 +00007287
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007288 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7289 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007290 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007291 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007292 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007293}
Mike Stump11289f42009-09-09 15:08:12 +00007294
Douglas Gregord6ff3322009-08-04 16:50:30 +00007295template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007296QualType
7297TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007298 ArrayType::ArraySizeModifier SizeMod,
7299 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007300 unsigned IndexTypeQuals,
7301 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007302 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007303 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007304}
7305
7306template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007307QualType
Mike Stump11289f42009-09-09 15:08:12 +00007308TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007309 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007310 unsigned IndexTypeQuals,
7311 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007312 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007313 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007314}
Mike Stump11289f42009-09-09 15:08:12 +00007315
Douglas Gregord6ff3322009-08-04 16:50:30 +00007316template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007317QualType
7318TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007319 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007320 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007321 unsigned IndexTypeQuals,
7322 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007323 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007324 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007325 IndexTypeQuals, BracketsRange);
7326}
7327
7328template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007329QualType
7330TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007331 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007332 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007333 unsigned IndexTypeQuals,
7334 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007335 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007336 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007337 IndexTypeQuals, BracketsRange);
7338}
7339
7340template<typename Derived>
7341QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007342 unsigned NumElements,
7343 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007344 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007345 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007346}
Mike Stump11289f42009-09-09 15:08:12 +00007347
Douglas Gregord6ff3322009-08-04 16:50:30 +00007348template<typename Derived>
7349QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7350 unsigned NumElements,
7351 SourceLocation AttributeLoc) {
7352 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7353 NumElements, true);
7354 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007355 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7356 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007357 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007358}
Mike Stump11289f42009-09-09 15:08:12 +00007359
Douglas Gregord6ff3322009-08-04 16:50:30 +00007360template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007361QualType
7362TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007363 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007364 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007365 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007366}
Mike Stump11289f42009-09-09 15:08:12 +00007367
Douglas Gregord6ff3322009-08-04 16:50:30 +00007368template<typename Derived>
7369QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007370 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007371 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007372 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007373 unsigned Quals,
7374 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007375 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007376 Quals,
7377 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007378 getDerived().getBaseEntity(),
7379 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007380}
Mike Stump11289f42009-09-09 15:08:12 +00007381
Douglas Gregord6ff3322009-08-04 16:50:30 +00007382template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007383QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7384 return SemaRef.Context.getFunctionNoProtoType(T);
7385}
7386
7387template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007388QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7389 assert(D && "no decl found");
7390 if (D->isInvalidDecl()) return QualType();
7391
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007392 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007393 TypeDecl *Ty;
7394 if (isa<UsingDecl>(D)) {
7395 UsingDecl *Using = cast<UsingDecl>(D);
7396 assert(Using->isTypeName() &&
7397 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7398
7399 // A valid resolved using typename decl points to exactly one type decl.
7400 assert(++Using->shadow_begin() == Using->shadow_end());
7401 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007402
John McCallb96ec562009-12-04 22:46:56 +00007403 } else {
7404 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7405 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7406 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7407 }
7408
7409 return SemaRef.Context.getTypeDeclType(Ty);
7410}
7411
7412template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007413QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7414 SourceLocation Loc) {
7415 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007416}
7417
7418template<typename Derived>
7419QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7420 return SemaRef.Context.getTypeOfType(Underlying);
7421}
7422
7423template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007424QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7425 SourceLocation Loc) {
7426 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007427}
7428
7429template<typename Derived>
7430QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007431 TemplateName Template,
7432 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007433 const TemplateArgumentListInfo &TemplateArgs) {
7434 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007435}
Mike Stump11289f42009-09-09 15:08:12 +00007436
Douglas Gregor1135c352009-08-06 05:28:30 +00007437template<typename Derived>
7438NestedNameSpecifier *
7439TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7440 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007441 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007442 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007443 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007444 CXXScopeSpec SS;
7445 // FIXME: The source location information is all wrong.
7446 SS.setRange(Range);
7447 SS.setScopeRep(Prefix);
7448 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007449 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007450 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007451 ObjectType,
7452 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007453 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007454}
7455
7456template<typename Derived>
7457NestedNameSpecifier *
7458TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7459 SourceRange Range,
7460 NamespaceDecl *NS) {
7461 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7462}
7463
7464template<typename Derived>
7465NestedNameSpecifier *
7466TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7467 SourceRange Range,
7468 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007469 QualType T) {
7470 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007471 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007472 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007473 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7474 T.getTypePtr());
7475 }
Mike Stump11289f42009-09-09 15:08:12 +00007476
Douglas Gregor1135c352009-08-06 05:28:30 +00007477 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7478 return 0;
7479}
Mike Stump11289f42009-09-09 15:08:12 +00007480
Douglas Gregor71dc5092009-08-06 06:41:21 +00007481template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007482TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007483TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7484 bool TemplateKW,
7485 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007486 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007487 Template);
7488}
7489
7490template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007491TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007492TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007493 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007494 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007495 QualType ObjectType,
7496 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007497 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007498 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007499 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007500 UnqualifiedId Name;
7501 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007502 Sema::TemplateTy Template;
7503 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7504 /*FIXME:*/getDerived().getBaseLocation(),
7505 SS,
7506 Name,
John McCallba7bf592010-08-24 05:47:05 +00007507 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007508 /*EnteringContext=*/false,
7509 Template);
John McCall31f82722010-11-12 08:19:04 +00007510 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007511}
Mike Stump11289f42009-09-09 15:08:12 +00007512
Douglas Gregora16548e2009-08-11 05:31:07 +00007513template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007514TemplateName
7515TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7516 OverloadedOperatorKind Operator,
7517 QualType ObjectType) {
7518 CXXScopeSpec SS;
7519 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7520 SS.setScopeRep(Qualifier);
7521 UnqualifiedId Name;
7522 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7523 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7524 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007525 Sema::TemplateTy Template;
7526 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007527 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007528 SS,
7529 Name,
John McCallba7bf592010-08-24 05:47:05 +00007530 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007531 /*EnteringContext=*/false,
7532 Template);
7533 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007534}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007535
Douglas Gregor71395fa2009-11-04 00:56:37 +00007536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007537ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007538TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7539 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007540 Expr *OrigCallee,
7541 Expr *First,
7542 Expr *Second) {
7543 Expr *Callee = OrigCallee->IgnoreParenCasts();
7544 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007545
Douglas Gregora16548e2009-08-11 05:31:07 +00007546 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007547 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007548 if (!First->getType()->isOverloadableType() &&
7549 !Second->getType()->isOverloadableType())
7550 return getSema().CreateBuiltinArraySubscriptExpr(First,
7551 Callee->getLocStart(),
7552 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007553 } else if (Op == OO_Arrow) {
7554 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007555 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7556 } else if (Second == 0 || isPostIncDec) {
7557 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007558 // The argument is not of overloadable type, so try to create a
7559 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007560 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007561 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007562
John McCallb268a282010-08-23 23:25:46 +00007563 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007564 }
7565 } else {
John McCallb268a282010-08-23 23:25:46 +00007566 if (!First->getType()->isOverloadableType() &&
7567 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007568 // Neither of the arguments is an overloadable type, so try to
7569 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007570 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007571 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007572 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007573 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007575
Douglas Gregora16548e2009-08-11 05:31:07 +00007576 return move(Result);
7577 }
7578 }
Mike Stump11289f42009-09-09 15:08:12 +00007579
7580 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007581 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007582 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007583
John McCallb268a282010-08-23 23:25:46 +00007584 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007585 assert(ULE->requiresADL());
7586
7587 // FIXME: Do we have to check
7588 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007589 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007590 } else {
John McCallb268a282010-08-23 23:25:46 +00007591 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007592 }
Mike Stump11289f42009-09-09 15:08:12 +00007593
Douglas Gregora16548e2009-08-11 05:31:07 +00007594 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007595 Expr *Args[2] = { First, Second };
7596 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007597
Douglas Gregora16548e2009-08-11 05:31:07 +00007598 // Create the overloaded operator invocation for unary operators.
7599 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007600 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007602 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007603 }
Mike Stump11289f42009-09-09 15:08:12 +00007604
Sebastian Redladba46e2009-10-29 20:17:01 +00007605 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007606 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007607 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007608 First,
7609 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007610
Douglas Gregora16548e2009-08-11 05:31:07 +00007611 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007612 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007613 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007614 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7615 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007617
Mike Stump11289f42009-09-09 15:08:12 +00007618 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007619}
Mike Stump11289f42009-09-09 15:08:12 +00007620
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007622ExprResult
John McCallb268a282010-08-23 23:25:46 +00007623TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007624 SourceLocation OperatorLoc,
7625 bool isArrow,
7626 NestedNameSpecifier *Qualifier,
7627 SourceRange QualifierRange,
7628 TypeSourceInfo *ScopeType,
7629 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007630 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007631 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007632 CXXScopeSpec SS;
7633 if (Qualifier) {
7634 SS.setRange(QualifierRange);
7635 SS.setScopeRep(Qualifier);
7636 }
7637
John McCallb268a282010-08-23 23:25:46 +00007638 QualType BaseType = Base->getType();
7639 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007640 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007641 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007642 !BaseType->getAs<PointerType>()->getPointeeType()
7643 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007644 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007645 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007646 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007647 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007648 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007649 /*FIXME?*/true);
7650 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007651
Douglas Gregor678f90d2010-02-25 01:56:36 +00007652 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007653 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7654 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7655 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7656 NameInfo.setNamedTypeInfo(DestroyedType);
7657
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007658 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007659
John McCallb268a282010-08-23 23:25:46 +00007660 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007661 OperatorLoc, isArrow,
7662 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007663 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007664 /*TemplateArgs*/ 0);
7665}
7666
Douglas Gregord6ff3322009-08-04 16:50:30 +00007667} // end namespace clang
7668
7669#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H