blob: 913edaa68d1a3ce3f95085998d7e9b174c4be58b [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +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.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
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//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregorf816bd72009-09-03 22:13:48 +0000388 /// \brief Transform the given declaration name.
389 ///
390 /// By default, transforms the types of conversion function, constructor,
391 /// and destructor names and then (if needed) rebuilds the declaration name.
392 /// Identifiers and selectors are returned unmodified. Sublcasses may
393 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000394 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000395 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000396
Douglas Gregord6ff3322009-08-04 16:50:30 +0000397 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000398 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000399 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000400 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000401 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000402 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000403 QualType ObjectType = QualType(),
404 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000405
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406 /// \brief Transform the given template argument.
407 ///
Mike Stump11289f42009-09-09 15:08:12 +0000408 /// By default, this operation transforms the type, expression, or
409 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000410 /// new template argument from the transformed result. Subclasses may
411 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000412 ///
413 /// Returns true if there was an error.
414 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
415 TemplateArgumentLoc &Output);
416
Douglas Gregor62e06f22010-12-20 17:31:10 +0000417 /// \brief Transform the given set of template arguments.
418 ///
419 /// By default, this operation transforms all of the template arguments
420 /// in the input set using \c TransformTemplateArgument(), and appends
421 /// the transformed arguments to the output list.
422 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000423 /// Note that this overload of \c TransformTemplateArguments() is merely
424 /// a convenience function. Subclasses that wish to override this behavior
425 /// should override the iterator-based member template version.
426 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000427 /// \param Inputs The set of template arguments to be transformed.
428 ///
429 /// \param NumInputs The number of template arguments in \p Inputs.
430 ///
431 /// \param Outputs The set of transformed template arguments output by this
432 /// routine.
433 ///
434 /// Returns true if an error occurred.
435 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
436 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000437 TemplateArgumentListInfo &Outputs) {
438 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
439 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000440
441 /// \brief Transform the given set of template arguments.
442 ///
443 /// By default, this operation transforms all of the template arguments
444 /// in the input set using \c TransformTemplateArgument(), and appends
445 /// the transformed arguments to the output list.
446 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000447 /// \param First An iterator to the first template argument.
448 ///
449 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000450 ///
451 /// \param Outputs The set of transformed template arguments output by this
452 /// routine.
453 ///
454 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000455 template<typename InputIterator>
456 bool TransformTemplateArguments(InputIterator First,
457 InputIterator Last,
458 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
John McCall0ad16662009-10-29 08:12:44 +0000460 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
461 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
462 TemplateArgumentLoc &ArgLoc);
463
John McCallbcd03502009-12-07 02:54:59 +0000464 /// \brief Fakes up a TypeSourceInfo for a type.
465 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
466 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000467 getDerived().getBaseLocation());
468 }
Mike Stump11289f42009-09-09 15:08:12 +0000469
John McCall550e0c22009-10-21 00:40:46 +0000470#define ABSTRACT_TYPELOC(CLASS, PARENT)
471#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000472 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000473#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000474
John McCall31f82722010-11-12 08:19:04 +0000475 QualType
476 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
477 TemplateSpecializationTypeLoc TL,
478 TemplateName Template);
479
480 QualType
481 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
482 DependentTemplateSpecializationTypeLoc TL,
483 NestedNameSpecifier *Prefix);
484
John McCall58f10c32010-03-11 09:03:00 +0000485 /// \brief Transforms the parameters of a function type into the
486 /// given vectors.
487 ///
488 /// The result vectors should be kept in sync; null entries in the
489 /// variables vector are acceptable.
490 ///
491 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000492 bool TransformFunctionTypeParams(SourceLocation Loc,
493 ParmVarDecl **Params, unsigned NumParams,
494 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000495 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000496 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000497
498 /// \brief Transforms a single function-type parameter. Return null
499 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000500 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
501 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000502
John McCall31f82722010-11-12 08:19:04 +0000503 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000504
John McCalldadc5752010-08-24 06:29:42 +0000505 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
506 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000507
Douglas Gregorebe10102009-08-20 07:17:43 +0000508#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000509 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000510#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000511 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000512#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000513#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000514
Douglas Gregord6ff3322009-08-04 16:50:30 +0000515 /// \brief Build a new pointer type given its pointee type.
516 ///
517 /// By default, performs semantic analysis when building the pointer type.
518 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000519 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520
521 /// \brief Build a new block pointer type given its pointee type.
522 ///
Mike Stump11289f42009-09-09 15:08:12 +0000523 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000524 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000525 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526
John McCall70dd5f62009-10-30 00:06:24 +0000527 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000528 ///
John McCall70dd5f62009-10-30 00:06:24 +0000529 /// By default, performs semantic analysis when building the
530 /// reference type. Subclasses may override this routine to provide
531 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000532 ///
John McCall70dd5f62009-10-30 00:06:24 +0000533 /// \param LValue whether the type was written with an lvalue sigil
534 /// or an rvalue sigil.
535 QualType RebuildReferenceType(QualType ReferentType,
536 bool LValue,
537 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000538
Douglas Gregord6ff3322009-08-04 16:50:30 +0000539 /// \brief Build a new member pointer type given the pointee type and the
540 /// class type it refers into.
541 ///
542 /// By default, performs semantic analysis when building the member pointer
543 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000544 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
545 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new array type given the element type, size
548 /// modifier, size of the array (if known), size expression, and index type
549 /// qualifiers.
550 ///
551 /// By default, performs semantic analysis when building the array type.
552 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000553 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000554 QualType RebuildArrayType(QualType ElementType,
555 ArrayType::ArraySizeModifier SizeMod,
556 const llvm::APInt *Size,
557 Expr *SizeExpr,
558 unsigned IndexTypeQuals,
559 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000560
Douglas Gregord6ff3322009-08-04 16:50:30 +0000561 /// \brief Build a new constant array type given the element type, size
562 /// modifier, (known) size of the array, and index type qualifiers.
563 ///
564 /// By default, performs semantic analysis when building the array type.
565 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000566 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000567 ArrayType::ArraySizeModifier SizeMod,
568 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000569 unsigned IndexTypeQuals,
570 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571
Douglas Gregord6ff3322009-08-04 16:50:30 +0000572 /// \brief Build a new incomplete array type given the element type, size
573 /// modifier, and index type qualifiers.
574 ///
575 /// By default, performs semantic analysis when building the array type.
576 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000577 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000579 unsigned IndexTypeQuals,
580 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000581
Mike Stump11289f42009-09-09 15:08:12 +0000582 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000583 /// size modifier, size expression, and index type qualifiers.
584 ///
585 /// By default, performs semantic analysis when building the array type.
586 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000587 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000588 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000589 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
592
Mike Stump11289f42009-09-09 15:08:12 +0000593 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 /// size modifier, size expression, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000600 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
603
604 /// \brief Build a new vector type given the element type and
605 /// number of elements.
606 ///
607 /// By default, performs semantic analysis when building the vector type.
608 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000609 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000610 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000611
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612 /// \brief Build a new extended vector type given the element type and
613 /// number of elements.
614 ///
615 /// By default, performs semantic analysis when building the vector type.
616 /// Subclasses may override this routine to provide different behavior.
617 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
618 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000619
620 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000621 /// given the element type and number of elements.
622 ///
623 /// By default, performs semantic analysis when building the vector type.
624 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000625 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000626 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000628
Douglas Gregord6ff3322009-08-04 16:50:30 +0000629 /// \brief Build a new function type.
630 ///
631 /// By default, performs semantic analysis when building the function type.
632 /// Subclasses may override this routine to provide different behavior.
633 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000634 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000635 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000636 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000637 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000638 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000639
John McCall550e0c22009-10-21 00:40:46 +0000640 /// \brief Build a new unprototyped function type.
641 QualType RebuildFunctionNoProtoType(QualType ResultType);
642
John McCallb96ec562009-12-04 22:46:56 +0000643 /// \brief Rebuild an unresolved typename type, given the decl that
644 /// the UnresolvedUsingTypenameDecl was transformed to.
645 QualType RebuildUnresolvedUsingType(Decl *D);
646
Douglas Gregord6ff3322009-08-04 16:50:30 +0000647 /// \brief Build a new typedef type.
648 QualType RebuildTypedefType(TypedefDecl *Typedef) {
649 return SemaRef.Context.getTypeDeclType(Typedef);
650 }
651
652 /// \brief Build a new class/struct/union type.
653 QualType RebuildRecordType(RecordDecl *Record) {
654 return SemaRef.Context.getTypeDeclType(Record);
655 }
656
657 /// \brief Build a new Enum type.
658 QualType RebuildEnumType(EnumDecl *Enum) {
659 return SemaRef.Context.getTypeDeclType(Enum);
660 }
John McCallfcc33b02009-09-05 00:15:47 +0000661
Mike Stump11289f42009-09-09 15:08:12 +0000662 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000663 ///
664 /// By default, performs semantic analysis when building the typeof type.
665 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000666 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667
Mike Stump11289f42009-09-09 15:08:12 +0000668 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000669 ///
670 /// By default, builds a new TypeOfType with the given underlying type.
671 QualType RebuildTypeOfType(QualType Underlying);
672
Mike Stump11289f42009-09-09 15:08:12 +0000673 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
675 /// By default, performs semantic analysis when building the decltype type.
676 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000677 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new template specialization type.
680 ///
681 /// By default, performs semantic analysis when building the template
682 /// specialization type. Subclasses may override this routine to provide
683 /// different behavior.
684 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000685 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000686 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000687
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000688 /// \brief Build a new parenthesized type.
689 ///
690 /// By default, builds a new ParenType type from the inner type.
691 /// Subclasses may override this routine to provide different behavior.
692 QualType RebuildParenType(QualType InnerType) {
693 return SemaRef.Context.getParenType(InnerType);
694 }
695
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 /// \brief Build a new qualified name type.
697 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000698 /// By default, builds a new ElaboratedType type from the keyword,
699 /// the nested-name-specifier and the named type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000701 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
702 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000703 NestedNameSpecifier *NNS, QualType Named) {
704 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000705 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706
707 /// \brief Build a new typename type that refers to a template-id.
708 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000709 /// By default, builds a new DependentNameType type from the
710 /// nested-name-specifier and the given type. Subclasses may override
711 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000712 QualType RebuildDependentTemplateSpecializationType(
713 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000714 NestedNameSpecifier *Qualifier,
715 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000716 const IdentifierInfo *Name,
717 SourceLocation NameLoc,
718 const TemplateArgumentListInfo &Args) {
719 // Rebuild the template name.
720 // TODO: avoid TemplateName abstraction
721 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000722 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000723 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000724
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000725 if (InstName.isNull())
726 return QualType();
727
John McCallc392f372010-06-11 00:33:02 +0000728 // If it's still dependent, make a dependent specialization.
729 if (InstName.getAsDependentTemplateName())
730 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000731 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000732
733 // Otherwise, make an elaborated type wrapping a non-dependent
734 // specialization.
735 QualType T =
736 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
737 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000738
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000739 // NOTE: NNS is already recorded in template specialization type T.
740 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000741 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742
743 /// \brief Build a new typename type that refers to an identifier.
744 ///
745 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000746 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000747 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000748 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000749 NestedNameSpecifier *NNS,
750 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000751 SourceLocation KeywordLoc,
752 SourceRange NNSRange,
753 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000754 CXXScopeSpec SS;
755 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 SS.setRange(NNSRange);
757
Douglas Gregore677daf2010-03-31 22:19:08 +0000758 if (NNS->isDependent()) {
759 // If the name is still dependent, just build a new dependent name type.
760 if (!SemaRef.computeDeclContext(SS))
761 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
762 }
763
Abramo Bagnara6150c882010-05-11 21:36:43 +0000764 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000765 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
766 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000767
768 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
769
Abramo Bagnarad7548482010-05-19 21:37:53 +0000770 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000771 // into a non-dependent elaborated-type-specifier. Find the tag we're
772 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000773 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000774 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
775 if (!DC)
776 return QualType();
777
John McCallbf8c5192010-05-27 06:40:31 +0000778 if (SemaRef.RequireCompleteDeclContext(SS, DC))
779 return QualType();
780
Douglas Gregore677daf2010-03-31 22:19:08 +0000781 TagDecl *Tag = 0;
782 SemaRef.LookupQualifiedName(Result, DC);
783 switch (Result.getResultKind()) {
784 case LookupResult::NotFound:
785 case LookupResult::NotFoundInCurrentInstantiation:
786 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000787
Douglas Gregore677daf2010-03-31 22:19:08 +0000788 case LookupResult::Found:
789 Tag = Result.getAsSingle<TagDecl>();
790 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000791
Douglas Gregore677daf2010-03-31 22:19:08 +0000792 case LookupResult::FoundOverloaded:
793 case LookupResult::FoundUnresolvedValue:
794 llvm_unreachable("Tag lookup cannot find non-tags");
795 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000796
Douglas Gregore677daf2010-03-31 22:19:08 +0000797 case LookupResult::Ambiguous:
798 // Let the LookupResult structure handle ambiguities.
799 return QualType();
800 }
801
802 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000803 // Check where the name exists but isn't a tag type and use that to emit
804 // better diagnostics.
805 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
806 SemaRef.LookupQualifiedName(Result, DC);
807 switch (Result.getResultKind()) {
808 case LookupResult::Found:
809 case LookupResult::FoundOverloaded:
810 case LookupResult::FoundUnresolvedValue: {
811 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
812 unsigned Kind = 0;
813 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
814 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
815 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
816 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
817 break;
818 }
819 default:
820 // FIXME: Would be nice to highlight just the source range.
821 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
822 << Kind << Id << DC;
823 break;
824 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000825 return QualType();
826 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000827
Abramo Bagnarad7548482010-05-19 21:37:53 +0000828 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
829 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000830 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
831 return QualType();
832 }
833
834 // Build the elaborated-type-specifier type.
835 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000836 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000837 }
Mike Stump11289f42009-09-09 15:08:12 +0000838
Douglas Gregor822d0302011-01-12 17:07:58 +0000839 /// \brief Build a new pack expansion type.
840 ///
841 /// By default, builds a new PackExpansionType type from the given pattern.
842 /// Subclasses may override this routine to provide different behavior.
843 QualType RebuildPackExpansionType(QualType Pattern,
844 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000845 SourceLocation EllipsisLoc,
846 llvm::Optional<unsigned> NumExpansions) {
847 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
848 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000849 }
850
Douglas Gregor1135c352009-08-06 05:28:30 +0000851 /// \brief Build a new nested-name-specifier given the prefix and an
852 /// identifier that names the next step in the nested-name-specifier.
853 ///
854 /// By default, performs semantic analysis when building the new
855 /// nested-name-specifier. Subclasses may override this routine to provide
856 /// different behavior.
857 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
858 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000859 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000860 QualType ObjectType,
861 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000862
863 /// \brief Build a new nested-name-specifier given the prefix and the
864 /// namespace named in the next step in the nested-name-specifier.
865 ///
866 /// By default, performs semantic analysis when building the new
867 /// nested-name-specifier. Subclasses may override this routine to provide
868 /// different behavior.
869 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
870 SourceRange Range,
871 NamespaceDecl *NS);
872
873 /// \brief Build a new nested-name-specifier given the prefix and the
874 /// type named in the next step in the nested-name-specifier.
875 ///
876 /// By default, performs semantic analysis when building the new
877 /// nested-name-specifier. Subclasses may override this routine to provide
878 /// different behavior.
879 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
880 SourceRange Range,
881 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000882 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000883
884 /// \brief Build a new template name given a nested name specifier, a flag
885 /// indicating whether the "template" keyword was provided, and the template
886 /// that the template name refers to.
887 ///
888 /// By default, builds the new template name directly. Subclasses may override
889 /// this routine to provide different behavior.
890 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
891 bool TemplateKW,
892 TemplateDecl *Template);
893
Douglas Gregor71dc5092009-08-06 06:41:21 +0000894 /// \brief Build a new template name given a nested name specifier and the
895 /// name that is referred to as a template.
896 ///
897 /// By default, performs semantic analysis to determine whether the name can
898 /// be resolved to a specific template, then builds the appropriate kind of
899 /// template name. Subclasses may override this routine to provide different
900 /// behavior.
901 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000902 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000903 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000904 QualType ObjectType,
905 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000906
Douglas Gregor71395fa2009-11-04 00:56:37 +0000907 /// \brief Build a new template name given a nested name specifier and the
908 /// overloaded operator name that is referred to as a template.
909 ///
910 /// By default, performs semantic analysis to determine whether the name can
911 /// be resolved to a specific template, then builds the appropriate kind of
912 /// template name. Subclasses may override this routine to provide different
913 /// behavior.
914 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
915 OverloadedOperatorKind Operator,
916 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000917
918 /// \brief Build a new template name given a template template parameter pack
919 /// and the
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
925 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
926 const TemplateArgument &ArgPack) {
927 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
928 }
929
Douglas Gregorebe10102009-08-20 07:17:43 +0000930 /// \brief Build a new compound statement.
931 ///
932 /// By default, performs semantic analysis to build the new statement.
933 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000934 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000935 MultiStmtArg Statements,
936 SourceLocation RBraceLoc,
937 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000938 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000939 IsStmtExpr);
940 }
941
942 /// \brief Build a new case statement.
943 ///
944 /// By default, performs semantic analysis to build the new statement.
945 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000946 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000947 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000948 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000949 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000950 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000951 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000952 ColonLoc);
953 }
Mike Stump11289f42009-09-09 15:08:12 +0000954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Attach the body to a new case statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000960 getSema().ActOnCaseStmtBody(S, Body);
961 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 }
Mike Stump11289f42009-09-09 15:08:12 +0000963
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 /// \brief Build a new default statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000968 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000969 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000970 Stmt *SubStmt) {
971 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 /*CurScope=*/0);
973 }
Mike Stump11289f42009-09-09 15:08:12 +0000974
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 /// \brief Build a new label statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000979 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
980 SourceLocation ColonLoc, Stmt *SubStmt) {
981 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 }
Mike Stump11289f42009-09-09 15:08:12 +0000983
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 /// \brief Build a new "if" statement.
985 ///
986 /// By default, performs semantic analysis to build the new statement.
987 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000988 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +0000989 VarDecl *CondVar, Stmt *Then,
990 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000991 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000992 }
Mike Stump11289f42009-09-09 15:08:12 +0000993
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 /// \brief Start building a new switch statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000998 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +0000999 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001000 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001001 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 }
Mike Stump11289f42009-09-09 15:08:12 +00001003
Douglas Gregorebe10102009-08-20 07:17:43 +00001004 /// \brief Attach the body to the switch statement.
1005 ///
1006 /// By default, performs semantic analysis to build the new statement.
1007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001008 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001009 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001010 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 }
1012
1013 /// \brief Build a new while statement.
1014 ///
1015 /// By default, performs semantic analysis to build the new statement.
1016 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001017 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1018 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001019 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001020 }
Mike Stump11289f42009-09-09 15:08:12 +00001021
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 /// \brief Build a new do-while statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001026 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001027 SourceLocation WhileLoc, SourceLocation LParenLoc,
1028 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001029 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1030 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 }
1032
1033 /// \brief Build a new for statement.
1034 ///
1035 /// By default, performs semantic analysis to build the new statement.
1036 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001037 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1038 Stmt *Init, Sema::FullExprArg Cond,
1039 VarDecl *CondVar, Sema::FullExprArg Inc,
1040 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001041 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001042 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001043 }
Mike Stump11289f42009-09-09 15:08:12 +00001044
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 /// \brief Build a new goto statement.
1046 ///
1047 /// By default, performs semantic analysis to build the new statement.
1048 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001049 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1050 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001051 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 }
1053
1054 /// \brief Build a new indirect goto statement.
1055 ///
1056 /// By default, performs semantic analysis to build the new statement.
1057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001058 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001059 SourceLocation StarLoc,
1060 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001061 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001062 }
Mike Stump11289f42009-09-09 15:08:12 +00001063
Douglas Gregorebe10102009-08-20 07:17:43 +00001064 /// \brief Build a new return statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001069 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Build a new declaration statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001076 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001077 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001078 SourceLocation EndLoc) {
1079 return getSema().Owned(
1080 new (getSema().Context) DeclStmt(
1081 DeclGroupRef::Create(getSema().Context,
1082 Decls, NumDecls),
1083 StartLoc, EndLoc));
1084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Anders Carlssonaaeef072010-01-24 05:50:09 +00001086 /// \brief Build a new inline asm statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001090 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001091 bool IsSimple,
1092 bool IsVolatile,
1093 unsigned NumOutputs,
1094 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001095 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001096 MultiExprArg Constraints,
1097 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001098 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001099 MultiExprArg Clobbers,
1100 SourceLocation RParenLoc,
1101 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001102 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001103 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001104 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001105 RParenLoc, MSAsm);
1106 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001107
1108 /// \brief Build a new Objective-C @try statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001114 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001115 Stmt *Finally) {
1116 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1117 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001118 }
1119
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001120 /// \brief Rebuild an Objective-C exception declaration.
1121 ///
1122 /// By default, performs semantic analysis to build the new declaration.
1123 /// Subclasses may override this routine to provide different behavior.
1124 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1125 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001126 return getSema().BuildObjCExceptionDecl(TInfo, T,
1127 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001128 ExceptionDecl->getLocation());
1129 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001131 /// \brief Build a new Objective-C @catch statement.
1132 ///
1133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001135 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001136 SourceLocation RParenLoc,
1137 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001138 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001139 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001140 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001141 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001142
Douglas Gregor306de2f2010-04-22 23:59:56 +00001143 /// \brief Build a new Objective-C @finally statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001147 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001148 Stmt *Body) {
1149 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001150 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001151
Douglas Gregor6148de72010-04-22 22:01:21 +00001152 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001156 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001157 Expr *Operand) {
1158 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001159 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001160
Douglas Gregor6148de72010-04-22 22:01:21 +00001161 /// \brief Build a new Objective-C @synchronized statement.
1162 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001165 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001166 Expr *Object,
1167 Stmt *Body) {
1168 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1169 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001170 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001171
1172 /// \brief Build a new Objective-C fast enumeration statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001176 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001177 SourceLocation LParenLoc,
1178 Stmt *Element,
1179 Expr *Collection,
1180 SourceLocation RParenLoc,
1181 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001182 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001183 Element,
1184 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001185 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001187 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001188
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 /// \brief Build a new C++ exception declaration.
1190 ///
1191 /// By default, performs semantic analysis to build the new decaration.
1192 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001193 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001194 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001195 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001196 SourceLocation Loc) {
1197 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 }
1199
1200 /// \brief Build a new C++ catch statement.
1201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001204 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001205 VarDecl *ExceptionDecl,
1206 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001207 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1208 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001209 }
Mike Stump11289f42009-09-09 15:08:12 +00001210
Douglas Gregorebe10102009-08-20 07:17:43 +00001211 /// \brief Build a new C++ try statement.
1212 ///
1213 /// By default, performs semantic analysis to build the new statement.
1214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001215 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001216 Stmt *TryBlock,
1217 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001218 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new expression that references a declaration.
1222 ///
1223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 LookupResult &R,
1227 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001228 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1229 }
1230
1231
1232 /// \brief Build a new expression that references a declaration.
1233 ///
1234 /// By default, performs semantic analysis to build the new expression.
1235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001236 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001237 SourceRange QualifierRange,
1238 ValueDecl *VD,
1239 const DeclarationNameInfo &NameInfo,
1240 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001241 CXXScopeSpec SS;
1242 SS.setScopeRep(Qualifier);
1243 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001244
1245 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001246
1247 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 }
Mike Stump11289f42009-09-09 15:08:12 +00001249
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001251 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 /// By default, performs semantic analysis to build the new expression.
1253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001254 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001256 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
1258
Douglas Gregorad8a3362009-09-04 17:36:40 +00001259 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001263 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001264 SourceLocation OperatorLoc,
1265 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001266 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001267 SourceRange QualifierRange,
1268 TypeSourceInfo *ScopeType,
1269 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001270 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001271 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001274 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001278 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001279 Expr *SubExpr) {
1280 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 }
Mike Stump11289f42009-09-09 15:08:12 +00001282
Douglas Gregor882211c2010-04-28 22:16:22 +00001283 /// \brief Build a new builtin offsetof expression.
1284 ///
1285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001287 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001288 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001289 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001290 unsigned NumComponents,
1291 SourceLocation RParenLoc) {
1292 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1293 NumComponents, RParenLoc);
1294 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001297 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// By default, performs semantic analysis to build the new expression.
1299 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001300 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001301 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001303 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 }
1305
Mike Stump11289f42009-09-09 15:08:12 +00001306 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001308 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001311 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001313 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001314 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001317
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 return move(Result);
1319 }
Mike Stump11289f42009-09-09 15:08:12 +00001320
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001322 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001325 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001327 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001329 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1330 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 RBracketLoc);
1332 }
1333
1334 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001335 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001338 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001340 SourceLocation RParenLoc,
1341 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001342 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001343 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 }
1345
1346 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001347 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001350 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001351 bool isArrow,
1352 NestedNameSpecifier *Qualifier,
1353 SourceRange QualifierRange,
1354 const DeclarationNameInfo &MemberNameInfo,
1355 ValueDecl *Member,
1356 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001357 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001358 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001359 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001360 // We have a reference to an unnamed field. This is always the
1361 // base of an anonymous struct/union member access, i.e. the
1362 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001363 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001364 assert(Member->getType()->isRecordType() &&
1365 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001366
John McCallb268a282010-08-23 23:25:46 +00001367 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001368 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001369 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001370
John McCall7decc9e2010-11-18 06:31:45 +00001371 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001372 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001373 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001374 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001375 cast<FieldDecl>(Member)->getType(),
1376 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001377 return getSema().Owned(ME);
1378 }
Mike Stump11289f42009-09-09 15:08:12 +00001379
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001380 CXXScopeSpec SS;
1381 if (Qualifier) {
1382 SS.setRange(QualifierRange);
1383 SS.setScopeRep(Qualifier);
1384 }
1385
John McCallb268a282010-08-23 23:25:46 +00001386 getSema().DefaultFunctionArrayConversion(Base);
1387 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001388
John McCall16df1e52010-03-30 21:47:33 +00001389 // FIXME: this involves duplicating earlier analysis in a lot of
1390 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001391 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001392 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001393 R.resolveKind();
1394
John McCallb268a282010-08-23 23:25:46 +00001395 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001396 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001397 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 }
Mike Stump11289f42009-09-09 15:08:12 +00001399
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001401 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001404 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001405 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001406 Expr *LHS, Expr *RHS) {
1407 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 }
1409
1410 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001411 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001414 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001415 SourceLocation QuestionLoc,
1416 Expr *LHS,
1417 SourceLocation ColonLoc,
1418 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001419 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1420 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 }
1422
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001424 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// By default, performs semantic analysis to build the new expression.
1426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001427 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001428 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001430 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001431 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001432 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 }
Mike Stump11289f42009-09-09 15:08:12 +00001434
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001436 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001439 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001442 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001443 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001444 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 }
Mike Stump11289f42009-09-09 15:08:12 +00001446
Douglas Gregora16548e2009-08-11 05:31:07 +00001447 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001448 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 SourceLocation OpLoc,
1453 SourceLocation AccessorLoc,
1454 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001455
John McCall10eae182009-11-30 22:42:35 +00001456 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001457 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001458 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001459 OpLoc, /*IsArrow*/ false,
1460 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001461 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001462 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 }
Mike Stump11289f42009-09-09 15:08:12 +00001464
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001466 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 /// By default, performs semantic analysis to build the new expression.
1468 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001469 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001471 SourceLocation RBraceLoc,
1472 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001473 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001474 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1475 if (Result.isInvalid() || ResultTy->isDependentType())
1476 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001477
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 // Patch in the result type we were given, which may have been computed
1479 // when the initial InitListExpr was built.
1480 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1481 ILE->setType(ResultTy);
1482 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
Mike Stump11289f42009-09-09 15:08:12 +00001484
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001486 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001489 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 MultiExprArg ArrayExprs,
1491 SourceLocation EqualOrColonLoc,
1492 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001493 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001496 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001499
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 ArrayExprs.release();
1501 return move(Result);
1502 }
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001505 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 /// By default, builds the implicit value initialization without performing
1507 /// any semantic analysis. Subclasses may override this routine to provide
1508 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001509 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1511 }
Mike Stump11289f42009-09-09 15:08:12 +00001512
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001514 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001517 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001518 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001519 SourceLocation RParenLoc) {
1520 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001521 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001522 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 }
1524
1525 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001529 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 MultiExprArg SubExprs,
1531 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001532 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001533 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
Mike Stump11289f42009-09-09 15:08:12 +00001535
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001537 ///
1538 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001539 /// rather than attempting to map the label statement itself.
1540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001541 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001542 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001543 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 }
Mike Stump11289f42009-09-09 15:08:12 +00001545
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001547 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001550 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001551 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001553 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 }
Mike Stump11289f42009-09-09 15:08:12 +00001555
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// \brief Build a new __builtin_choose_expr expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001560 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001561 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 SourceLocation RParenLoc) {
1563 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001564 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 RParenLoc);
1566 }
Mike Stump11289f42009-09-09 15:08:12 +00001567
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 /// \brief Build a new overloaded operator call expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// The semantic analysis provides the behavior of template instantiation,
1572 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001573 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 /// argument-dependent lookup, etc. Subclasses may override this routine to
1575 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001576 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001578 Expr *Callee,
1579 Expr *First,
1580 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001581
1582 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// reinterpret_cast.
1584 ///
1585 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001586 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001588 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 Stmt::StmtClass Class,
1590 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001591 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 SourceLocation RAngleLoc,
1593 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001594 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 SourceLocation RParenLoc) {
1596 switch (Class) {
1597 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001598 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001599 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001600 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001601
1602 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001603 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001604 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001605 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001608 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001609 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001610 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001612
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001614 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001615 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001616 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001617
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 default:
1619 assert(false && "Invalid C++ named cast");
1620 break;
1621 }
Mike Stump11289f42009-09-09 15:08:12 +00001622
John McCallfaf5fb42010-08-26 23:41:50 +00001623 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 }
Mike Stump11289f42009-09-09 15:08:12 +00001625
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// \brief Build a new C++ static_cast expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001630 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001632 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 SourceLocation RAngleLoc,
1634 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001635 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001637 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001638 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001639 SourceRange(LAngleLoc, RAngleLoc),
1640 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 }
1642
1643 /// \brief Build a new C++ dynamic_cast expression.
1644 ///
1645 /// By default, performs semantic analysis to build the new expression.
1646 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001647 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001649 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 SourceLocation RAngleLoc,
1651 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001652 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001654 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001655 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001656 SourceRange(LAngleLoc, RAngleLoc),
1657 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
1659
1660 /// \brief Build a new C++ reinterpret_cast expression.
1661 ///
1662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001664 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001666 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 SourceLocation RAngleLoc,
1668 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001669 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001671 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001672 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001673 SourceRange(LAngleLoc, RAngleLoc),
1674 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 }
1676
1677 /// \brief Build a new C++ const_cast expression.
1678 ///
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001681 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001683 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 SourceLocation RAngleLoc,
1685 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001686 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001688 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001689 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001690 SourceRange(LAngleLoc, RAngleLoc),
1691 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001692 }
Mike Stump11289f42009-09-09 15:08:12 +00001693
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 /// \brief Build a new C++ functional-style cast expression.
1695 ///
1696 /// By default, performs semantic analysis to build the new expression.
1697 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001698 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1699 SourceLocation LParenLoc,
1700 Expr *Sub,
1701 SourceLocation RParenLoc) {
1702 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001703 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 RParenLoc);
1705 }
Mike Stump11289f42009-09-09 15:08:12 +00001706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 /// \brief Build a new C++ typeid(type) expression.
1708 ///
1709 /// By default, performs semantic analysis to build the new expression.
1710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001711 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001712 SourceLocation TypeidLoc,
1713 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001715 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001716 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 }
Mike Stump11289f42009-09-09 15:08:12 +00001718
Francois Pichet9f4f2072010-09-08 12:20:18 +00001719
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 /// \brief Build a new C++ typeid(expr) expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001724 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001725 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001726 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001728 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001729 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001730 }
1731
Francois Pichet9f4f2072010-09-08 12:20:18 +00001732 /// \brief Build a new C++ __uuidof(type) expression.
1733 ///
1734 /// By default, performs semantic analysis to build the new expression.
1735 /// Subclasses may override this routine to provide different behavior.
1736 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1737 SourceLocation TypeidLoc,
1738 TypeSourceInfo *Operand,
1739 SourceLocation RParenLoc) {
1740 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1741 RParenLoc);
1742 }
1743
1744 /// \brief Build a new C++ __uuidof(expr) expression.
1745 ///
1746 /// By default, performs semantic analysis to build the new expression.
1747 /// Subclasses may override this routine to provide different behavior.
1748 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1749 SourceLocation TypeidLoc,
1750 Expr *Operand,
1751 SourceLocation RParenLoc) {
1752 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1753 RParenLoc);
1754 }
1755
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 /// \brief Build a new C++ "this" expression.
1757 ///
1758 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001759 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001761 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001762 QualType ThisType,
1763 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001765 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1766 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 }
1768
1769 /// \brief Build a new C++ throw expression.
1770 ///
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001773 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001774 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ default-argument expression.
1778 ///
1779 /// By default, builds a new default-argument expression, which does not
1780 /// require any semantic analysis. Subclasses may override this routine to
1781 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001783 ParmVarDecl *Param) {
1784 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1785 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
1788 /// \brief Build a new C++ zero-initialization expression.
1789 ///
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001792 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1793 SourceLocation LParenLoc,
1794 SourceLocation RParenLoc) {
1795 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001796 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001797 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 }
Mike Stump11289f42009-09-09 15:08:12 +00001799
Douglas Gregora16548e2009-08-11 05:31:07 +00001800 /// \brief Build a new C++ "new" expression.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001804 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001805 bool UseGlobal,
1806 SourceLocation PlacementLParen,
1807 MultiExprArg PlacementArgs,
1808 SourceLocation PlacementRParen,
1809 SourceRange TypeIdParens,
1810 QualType AllocatedType,
1811 TypeSourceInfo *AllocatedTypeInfo,
1812 Expr *ArraySize,
1813 SourceLocation ConstructorLParen,
1814 MultiExprArg ConstructorArgs,
1815 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001816 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001817 PlacementLParen,
1818 move(PlacementArgs),
1819 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001820 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001821 AllocatedType,
1822 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001823 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 ConstructorLParen,
1825 move(ConstructorArgs),
1826 ConstructorRParen);
1827 }
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregora16548e2009-08-11 05:31:07 +00001829 /// \brief Build a new C++ "delete" expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001833 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 bool IsGlobalDelete,
1835 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001836 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001837 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001838 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 /// \brief Build a new unary type trait expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001845 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001846 SourceLocation StartLoc,
1847 TypeSourceInfo *T,
1848 SourceLocation RParenLoc) {
1849 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 }
1851
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001852 /// \brief Build a new binary type trait expression.
1853 ///
1854 /// By default, performs semantic analysis to build the new expression.
1855 /// Subclasses may override this routine to provide different behavior.
1856 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1857 SourceLocation StartLoc,
1858 TypeSourceInfo *LhsT,
1859 TypeSourceInfo *RhsT,
1860 SourceLocation RParenLoc) {
1861 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1862 }
1863
Mike Stump11289f42009-09-09 15:08:12 +00001864 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001865 /// expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001871 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001872 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001873 CXXScopeSpec SS;
1874 SS.setRange(QualifierRange);
1875 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001876
1877 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001878 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001879 *TemplateArgs);
1880
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001881 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new template-id expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001888 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001889 LookupResult &R,
1890 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001891 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001892 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new object-construction expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001899 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001900 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001901 CXXConstructorDecl *Constructor,
1902 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001903 MultiExprArg Args,
1904 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001905 CXXConstructExpr::ConstructionKind ConstructKind,
1906 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001907 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001908 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001909 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001910 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001911
Douglas Gregordb121ba2009-12-14 16:27:04 +00001912 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001913 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001914 RequiresZeroInit, ConstructKind,
1915 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 }
1917
1918 /// \brief Build a new object-construction expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001922 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1923 SourceLocation LParenLoc,
1924 MultiExprArg Args,
1925 SourceLocation RParenLoc) {
1926 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 LParenLoc,
1928 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 RParenLoc);
1930 }
1931
1932 /// \brief Build a new object-construction expression.
1933 ///
1934 /// By default, performs semantic analysis to build the new expression.
1935 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001936 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1937 SourceLocation LParenLoc,
1938 MultiExprArg Args,
1939 SourceLocation RParenLoc) {
1940 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 LParenLoc,
1942 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 RParenLoc);
1944 }
Mike Stump11289f42009-09-09 15:08:12 +00001945
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 /// \brief Build a new member reference expression.
1947 ///
1948 /// By default, performs semantic analysis to build the new expression.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001951 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 bool IsArrow,
1953 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001954 NestedNameSpecifier *Qualifier,
1955 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001956 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001957 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001958 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001960 SS.setRange(QualifierRange);
1961 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001962
John McCallb268a282010-08-23 23:25:46 +00001963 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001964 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001965 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001966 MemberNameInfo,
1967 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001968 }
1969
John McCall10eae182009-11-30 22:42:35 +00001970 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001974 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001975 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001976 SourceLocation OperatorLoc,
1977 bool IsArrow,
1978 NestedNameSpecifier *Qualifier,
1979 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001980 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001981 LookupResult &R,
1982 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001983 CXXScopeSpec SS;
1984 SS.setRange(QualifierRange);
1985 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001986
John McCallb268a282010-08-23 23:25:46 +00001987 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001988 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001989 SS, FirstQualifierInScope,
1990 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001991 }
Mike Stump11289f42009-09-09 15:08:12 +00001992
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001993 /// \brief Build a new noexcept expression.
1994 ///
1995 /// By default, performs semantic analysis to build the new expression.
1996 /// Subclasses may override this routine to provide different behavior.
1997 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1998 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1999 }
2000
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002001 /// \brief Build a new expression to compute the length of a parameter pack.
2002 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2003 SourceLocation PackLoc,
2004 SourceLocation RParenLoc,
2005 unsigned Length) {
2006 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2007 OperatorLoc, Pack, PackLoc,
2008 RParenLoc, Length);
2009 }
2010
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// \brief Build a new Objective-C @encode expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002015 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002016 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002018 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002020 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002021
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002022 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002023 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002024 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002025 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002026 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002027 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002028 MultiExprArg Args,
2029 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002030 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2031 ReceiverTypeInfo->getType(),
2032 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002033 Sel, Method, LBracLoc, SelectorLoc,
2034 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002035 }
2036
2037 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002038 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002039 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002040 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002041 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002042 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 MultiExprArg Args,
2044 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002045 return SemaRef.BuildInstanceMessage(Receiver,
2046 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002048 Sel, Method, LBracLoc, SelectorLoc,
2049 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002050 }
2051
Douglas Gregord51d90d2010-04-26 20:11:03 +00002052 /// \brief Build a new Objective-C ivar reference expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002057 SourceLocation IvarLoc,
2058 bool IsArrow, bool IsFreeIvar) {
2059 // FIXME: We lose track of the IsFreeIvar bit.
2060 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002061 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002062 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2063 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002065 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002066 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002067 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002068 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002069 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002070
Douglas Gregord51d90d2010-04-26 20:11:03 +00002071 if (Result.get())
2072 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002073
John McCallb268a282010-08-23 23:25:46 +00002074 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002075 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002076 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002077 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002078 /*TemplateArgs=*/0);
2079 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002080
2081 /// \brief Build a new Objective-C property reference expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002085 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002086 ObjCPropertyDecl *Property,
2087 SourceLocation PropertyLoc) {
2088 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002089 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002090 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2091 Sema::LookupMemberName);
2092 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002093 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002094 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002095 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002096 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002097 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002098
Douglas Gregor9faee212010-04-26 20:47:02 +00002099 if (Result.get())
2100 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002101
John McCallb268a282010-08-23 23:25:46 +00002102 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002103 /*FIXME:*/PropertyLoc, IsArrow,
2104 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002105 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002106 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002107 /*TemplateArgs=*/0);
2108 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002109
John McCallb7bd14f2010-12-02 01:19:52 +00002110 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002111 ///
2112 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002113 /// Subclasses may override this routine to provide different behavior.
2114 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2115 ObjCMethodDecl *Getter,
2116 ObjCMethodDecl *Setter,
2117 SourceLocation PropertyLoc) {
2118 // Since these expressions can only be value-dependent, we do not
2119 // need to perform semantic analysis again.
2120 return Owned(
2121 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2122 VK_LValue, OK_ObjCProperty,
2123 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002124 }
2125
Douglas Gregord51d90d2010-04-26 20:11:03 +00002126 /// \brief Build a new Objective-C "isa" expression.
2127 ///
2128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002130 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002131 bool IsArrow) {
2132 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002133 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002134 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2135 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002136 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002137 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002138 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002139 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002140 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002141
Douglas Gregord51d90d2010-04-26 20:11:03 +00002142 if (Result.get())
2143 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002144
John McCallb268a282010-08-23 23:25:46 +00002145 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002146 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002147 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 /*TemplateArgs=*/0);
2150 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002151
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 /// \brief Build a new shuffle vector expression.
2153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002157 MultiExprArg SubExprs,
2158 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002160 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2162 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2163 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2164 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 // Build a reference to the __builtin_shufflevector builtin
2167 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002168 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002170 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002171 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002172
2173 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 unsigned NumSubExprs = SubExprs.size();
2175 Expr **Subs = (Expr **)SubExprs.release();
2176 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2177 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002178 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002179 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002181 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002186 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002189 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 }
John McCall31f82722010-11-12 08:19:04 +00002191
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002192 /// \brief Build a new template argument pack expansion.
2193 ///
2194 /// By default, performs semantic analysis to build a new pack expansion
2195 /// for a template argument. Subclasses may override this routine to provide
2196 /// different behavior.
2197 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002198 SourceLocation EllipsisLoc,
2199 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002200 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002201 case TemplateArgument::Expression: {
2202 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002203 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2204 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002205 if (Result.isInvalid())
2206 return TemplateArgumentLoc();
2207
2208 return TemplateArgumentLoc(Result.get(), Result.get());
2209 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002210
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002211 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002212 return TemplateArgumentLoc(TemplateArgument(
2213 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002214 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002215 Pattern.getTemplateQualifierRange(),
2216 Pattern.getTemplateNameLoc(),
2217 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002218
2219 case TemplateArgument::Null:
2220 case TemplateArgument::Integral:
2221 case TemplateArgument::Declaration:
2222 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002223 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002224 llvm_unreachable("Pack expansion pattern has no parameter packs");
2225
2226 case TemplateArgument::Type:
2227 if (TypeSourceInfo *Expansion
2228 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002229 EllipsisLoc,
2230 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002231 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2232 Expansion);
2233 break;
2234 }
2235
2236 return TemplateArgumentLoc();
2237 }
2238
Douglas Gregor968f23a2011-01-03 19:31:53 +00002239 /// \brief Build a new expression pack expansion.
2240 ///
2241 /// By default, performs semantic analysis to build a new pack expansion
2242 /// for an expression. Subclasses may override this routine to provide
2243 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002244 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2245 llvm::Optional<unsigned> NumExpansions) {
2246 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002247 }
2248
John McCall31f82722010-11-12 08:19:04 +00002249private:
2250 QualType TransformTypeInObjectScope(QualType T,
2251 QualType ObjectType,
2252 NamedDecl *FirstQualifierInScope,
2253 NestedNameSpecifier *Prefix);
2254
2255 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2256 QualType ObjectType,
2257 NamedDecl *FirstQualifierInScope,
2258 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002259};
Douglas Gregora16548e2009-08-11 05:31:07 +00002260
Douglas Gregorebe10102009-08-20 07:17:43 +00002261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002262StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002263 if (!S)
2264 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002265
Douglas Gregorebe10102009-08-20 07:17:43 +00002266 switch (S->getStmtClass()) {
2267 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002268
Douglas Gregorebe10102009-08-20 07:17:43 +00002269 // Transform individual statement nodes
2270#define STMT(Node, Parent) \
2271 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002272#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002273#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002274#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregorebe10102009-08-20 07:17:43 +00002276 // Transform expressions by calling TransformExpr.
2277#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002278#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002279#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002280#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002281 {
John McCalldadc5752010-08-24 06:29:42 +00002282 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002283 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002284 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002285
John McCallb268a282010-08-23 23:25:46 +00002286 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002287 }
Mike Stump11289f42009-09-09 15:08:12 +00002288 }
2289
John McCallc3007a22010-10-26 07:05:15 +00002290 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002291}
Mike Stump11289f42009-09-09 15:08:12 +00002292
2293
Douglas Gregore922c772009-08-04 22:27:00 +00002294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002295ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 if (!E)
2297 return SemaRef.Owned(E);
2298
2299 switch (E->getStmtClass()) {
2300 case Stmt::NoStmtClass: break;
2301#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002302#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002303#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002304 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002305#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002306 }
2307
John McCallc3007a22010-10-26 07:05:15 +00002308 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002309}
2310
2311template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002312bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2313 unsigned NumInputs,
2314 bool IsCall,
2315 llvm::SmallVectorImpl<Expr *> &Outputs,
2316 bool *ArgChanged) {
2317 for (unsigned I = 0; I != NumInputs; ++I) {
2318 // If requested, drop call arguments that need to be dropped.
2319 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2320 if (ArgChanged)
2321 *ArgChanged = true;
2322
2323 break;
2324 }
2325
Douglas Gregor968f23a2011-01-03 19:31:53 +00002326 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2327 Expr *Pattern = Expansion->getPattern();
2328
2329 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2330 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2331 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2332
2333 // Determine whether the set of unexpanded parameter packs can and should
2334 // be expanded.
2335 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002336 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002337 llvm::Optional<unsigned> OrigNumExpansions
2338 = Expansion->getNumExpansions();
2339 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002340 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2341 Pattern->getSourceRange(),
2342 Unexpanded.data(),
2343 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002344 Expand, RetainExpansion,
2345 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002346 return true;
2347
2348 if (!Expand) {
2349 // The transform has determined that we should perform a simple
2350 // transformation on the pack expansion, producing another pack
2351 // expansion.
2352 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2353 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2354 if (OutPattern.isInvalid())
2355 return true;
2356
2357 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002358 Expansion->getEllipsisLoc(),
2359 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002360 if (Out.isInvalid())
2361 return true;
2362
2363 if (ArgChanged)
2364 *ArgChanged = true;
2365 Outputs.push_back(Out.get());
2366 continue;
2367 }
2368
2369 // The transform has determined that we should perform an elementwise
2370 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002371 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002372 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2373 ExprResult Out = getDerived().TransformExpr(Pattern);
2374 if (Out.isInvalid())
2375 return true;
2376
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002377 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002378 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2379 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002380 if (Out.isInvalid())
2381 return true;
2382 }
2383
Douglas Gregor968f23a2011-01-03 19:31:53 +00002384 if (ArgChanged)
2385 *ArgChanged = true;
2386 Outputs.push_back(Out.get());
2387 }
2388
2389 continue;
2390 }
2391
Douglas Gregora3efea12011-01-03 19:04:46 +00002392 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2393 if (Result.isInvalid())
2394 return true;
2395
2396 if (Result.get() != Inputs[I] && ArgChanged)
2397 *ArgChanged = true;
2398
2399 Outputs.push_back(Result.get());
2400 }
2401
2402 return false;
2403}
2404
2405template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002406NestedNameSpecifier *
2407TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002408 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002409 QualType ObjectType,
2410 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002411 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002412
Douglas Gregorebe10102009-08-20 07:17:43 +00002413 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002414 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002415 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002416 ObjectType,
2417 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002418 if (!Prefix)
2419 return 0;
2420 }
Mike Stump11289f42009-09-09 15:08:12 +00002421
Douglas Gregor1135c352009-08-06 05:28:30 +00002422 switch (NNS->getKind()) {
2423 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002424 if (Prefix) {
2425 // The object type and qualifier-in-scope really apply to the
2426 // leftmost entity.
2427 ObjectType = QualType();
2428 FirstQualifierInScope = 0;
2429 }
2430
Mike Stump11289f42009-09-09 15:08:12 +00002431 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002432 "Identifier nested-name-specifier with no prefix or object type");
2433 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2434 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002435 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002436
2437 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002438 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002439 ObjectType,
2440 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002441
Douglas Gregor1135c352009-08-06 05:28:30 +00002442 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002443 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002444 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002445 getDerived().TransformDecl(Range.getBegin(),
2446 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002447 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002448 Prefix == NNS->getPrefix() &&
2449 NS == NNS->getAsNamespace())
2450 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002451
Douglas Gregor1135c352009-08-06 05:28:30 +00002452 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2453 }
Mike Stump11289f42009-09-09 15:08:12 +00002454
Douglas Gregor1135c352009-08-06 05:28:30 +00002455 case NestedNameSpecifier::Global:
2456 // There is no meaningful transformation that one could perform on the
2457 // global scope.
2458 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002459
Douglas Gregor1135c352009-08-06 05:28:30 +00002460 case NestedNameSpecifier::TypeSpecWithTemplate:
2461 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002462 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002463 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2464 ObjectType,
2465 FirstQualifierInScope,
2466 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002467 if (T.isNull())
2468 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002469
Douglas Gregor1135c352009-08-06 05:28:30 +00002470 if (!getDerived().AlwaysRebuild() &&
2471 Prefix == NNS->getPrefix() &&
2472 T == QualType(NNS->getAsType(), 0))
2473 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002474
2475 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2476 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002477 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002478 }
2479 }
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregor1135c352009-08-06 05:28:30 +00002481 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002482 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002483}
2484
2485template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002486DeclarationNameInfo
2487TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002488::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002489 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002490 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002491 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002492
2493 switch (Name.getNameKind()) {
2494 case DeclarationName::Identifier:
2495 case DeclarationName::ObjCZeroArgSelector:
2496 case DeclarationName::ObjCOneArgSelector:
2497 case DeclarationName::ObjCMultiArgSelector:
2498 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002499 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002500 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002501 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002502
Douglas Gregorf816bd72009-09-03 22:13:48 +00002503 case DeclarationName::CXXConstructorName:
2504 case DeclarationName::CXXDestructorName:
2505 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002506 TypeSourceInfo *NewTInfo;
2507 CanQualType NewCanTy;
2508 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002509 NewTInfo = getDerived().TransformType(OldTInfo);
2510 if (!NewTInfo)
2511 return DeclarationNameInfo();
2512 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002513 }
2514 else {
2515 NewTInfo = 0;
2516 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002517 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002518 if (NewT.isNull())
2519 return DeclarationNameInfo();
2520 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2521 }
Mike Stump11289f42009-09-09 15:08:12 +00002522
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002523 DeclarationName NewName
2524 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2525 NewCanTy);
2526 DeclarationNameInfo NewNameInfo(NameInfo);
2527 NewNameInfo.setName(NewName);
2528 NewNameInfo.setNamedTypeInfo(NewTInfo);
2529 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002530 }
Mike Stump11289f42009-09-09 15:08:12 +00002531 }
2532
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002533 assert(0 && "Unknown name kind.");
2534 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002535}
2536
2537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002538TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002539TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002540 QualType ObjectType,
2541 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002542 SourceLocation Loc = getDerived().getBaseLocation();
2543
Douglas Gregor71dc5092009-08-06 06:41:21 +00002544 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002545 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002546 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002547 /*FIXME*/ SourceRange(Loc),
2548 ObjectType,
2549 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002550 if (!NNS)
2551 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002552
Douglas Gregor71dc5092009-08-06 06:41:21 +00002553 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002554 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002555 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002556 if (!TransTemplate)
2557 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002558
Douglas Gregor71dc5092009-08-06 06:41:21 +00002559 if (!getDerived().AlwaysRebuild() &&
2560 NNS == QTN->getQualifier() &&
2561 TransTemplate == Template)
2562 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregor71dc5092009-08-06 06:41:21 +00002564 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2565 TransTemplate);
2566 }
Mike Stump11289f42009-09-09 15:08:12 +00002567
John McCalle66edc12009-11-24 19:00:30 +00002568 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002569 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002570 }
Mike Stump11289f42009-09-09 15:08:12 +00002571
Douglas Gregor71dc5092009-08-06 06:41:21 +00002572 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002573 NestedNameSpecifier *NNS = DTN->getQualifier();
2574 if (NNS) {
2575 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2576 /*FIXME:*/SourceRange(Loc),
2577 ObjectType,
2578 FirstQualifierInScope);
2579 if (!NNS) return TemplateName();
2580
2581 // These apply to the scope specifier, not the template.
2582 ObjectType = QualType();
2583 FirstQualifierInScope = 0;
2584 }
Mike Stump11289f42009-09-09 15:08:12 +00002585
Douglas Gregor71dc5092009-08-06 06:41:21 +00002586 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002587 NNS == DTN->getQualifier() &&
2588 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002589 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002590
Douglas Gregora5614c52010-09-08 23:56:00 +00002591 if (DTN->isIdentifier()) {
2592 // FIXME: Bad range
2593 SourceRange QualifierRange(getDerived().getBaseLocation());
2594 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2595 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002596 ObjectType,
2597 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002598 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002599
2600 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002601 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002602 }
Mike Stump11289f42009-09-09 15:08:12 +00002603
Douglas Gregor71dc5092009-08-06 06:41:21 +00002604 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002605 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002606 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002607 if (!TransTemplate)
2608 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002609
Douglas Gregor71dc5092009-08-06 06:41:21 +00002610 if (!getDerived().AlwaysRebuild() &&
2611 TransTemplate == Template)
2612 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002613
Douglas Gregor71dc5092009-08-06 06:41:21 +00002614 return TemplateName(TransTemplate);
2615 }
Mike Stump11289f42009-09-09 15:08:12 +00002616
Douglas Gregor5590be02011-01-15 06:45:20 +00002617 if (SubstTemplateTemplateParmPackStorage *SubstPack
2618 = Name.getAsSubstTemplateTemplateParmPack()) {
2619 TemplateTemplateParmDecl *TransParam
2620 = cast_or_null<TemplateTemplateParmDecl>(
2621 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2622 if (!TransParam)
2623 return TemplateName();
2624
2625 if (!getDerived().AlwaysRebuild() &&
2626 TransParam == SubstPack->getParameterPack())
2627 return Name;
2628
2629 return getDerived().RebuildTemplateName(TransParam,
2630 SubstPack->getArgumentPack());
2631 }
2632
John McCalle66edc12009-11-24 19:00:30 +00002633 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002634 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002635 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002636}
2637
2638template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002639void TreeTransform<Derived>::InventTemplateArgumentLoc(
2640 const TemplateArgument &Arg,
2641 TemplateArgumentLoc &Output) {
2642 SourceLocation Loc = getDerived().getBaseLocation();
2643 switch (Arg.getKind()) {
2644 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002645 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002646 break;
2647
2648 case TemplateArgument::Type:
2649 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002650 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002651
John McCall0ad16662009-10-29 08:12:44 +00002652 break;
2653
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002654 case TemplateArgument::Template:
2655 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2656 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002657
2658 case TemplateArgument::TemplateExpansion:
2659 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2660 break;
2661
John McCall0ad16662009-10-29 08:12:44 +00002662 case TemplateArgument::Expression:
2663 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2664 break;
2665
2666 case TemplateArgument::Declaration:
2667 case TemplateArgument::Integral:
2668 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002669 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002670 break;
2671 }
2672}
2673
2674template<typename Derived>
2675bool TreeTransform<Derived>::TransformTemplateArgument(
2676 const TemplateArgumentLoc &Input,
2677 TemplateArgumentLoc &Output) {
2678 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002679 switch (Arg.getKind()) {
2680 case TemplateArgument::Null:
2681 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002682 Output = Input;
2683 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002684
Douglas Gregore922c772009-08-04 22:27:00 +00002685 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002686 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002687 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002688 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002689
2690 DI = getDerived().TransformType(DI);
2691 if (!DI) return true;
2692
2693 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2694 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002695 }
Mike Stump11289f42009-09-09 15:08:12 +00002696
Douglas Gregore922c772009-08-04 22:27:00 +00002697 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002698 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002699 DeclarationName Name;
2700 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2701 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002702 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002703 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002704 if (!D) return true;
2705
John McCall0d07eb32009-10-29 18:45:58 +00002706 Expr *SourceExpr = Input.getSourceDeclExpression();
2707 if (SourceExpr) {
2708 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002709 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002710 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002711 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002712 }
2713
2714 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002715 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002716 }
Mike Stump11289f42009-09-09 15:08:12 +00002717
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002718 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002719 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002720 TemplateName Template
2721 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2722 if (Template.isNull())
2723 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002724
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002725 Output = TemplateArgumentLoc(TemplateArgument(Template),
2726 Input.getTemplateQualifierRange(),
2727 Input.getTemplateNameLoc());
2728 return false;
2729 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002730
2731 case TemplateArgument::TemplateExpansion:
2732 llvm_unreachable("Caller should expand pack expansions");
2733
Douglas Gregore922c772009-08-04 22:27:00 +00002734 case TemplateArgument::Expression: {
2735 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002736 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002737 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002738
John McCall0ad16662009-10-29 08:12:44 +00002739 Expr *InputExpr = Input.getSourceExpression();
2740 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2741
John McCalldadc5752010-08-24 06:29:42 +00002742 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002743 = getDerived().TransformExpr(InputExpr);
2744 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002745 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002746 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002747 }
Mike Stump11289f42009-09-09 15:08:12 +00002748
Douglas Gregore922c772009-08-04 22:27:00 +00002749 case TemplateArgument::Pack: {
2750 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2751 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002752 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002753 AEnd = Arg.pack_end();
2754 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002755
John McCall0ad16662009-10-29 08:12:44 +00002756 // FIXME: preserve source information here when we start
2757 // caring about parameter packs.
2758
John McCall0d07eb32009-10-29 18:45:58 +00002759 TemplateArgumentLoc InputArg;
2760 TemplateArgumentLoc OutputArg;
2761 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2762 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002763 return true;
2764
John McCall0d07eb32009-10-29 18:45:58 +00002765 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002766 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002767
2768 TemplateArgument *TransformedArgsPtr
2769 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2770 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2771 TransformedArgsPtr);
2772 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2773 TransformedArgs.size()),
2774 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002775 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002776 }
2777 }
Mike Stump11289f42009-09-09 15:08:12 +00002778
Douglas Gregore922c772009-08-04 22:27:00 +00002779 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002780 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002781}
2782
Douglas Gregorfe921a72010-12-20 23:36:19 +00002783/// \brief Iterator adaptor that invents template argument location information
2784/// for each of the template arguments in its underlying iterator.
2785template<typename Derived, typename InputIterator>
2786class TemplateArgumentLocInventIterator {
2787 TreeTransform<Derived> &Self;
2788 InputIterator Iter;
2789
2790public:
2791 typedef TemplateArgumentLoc value_type;
2792 typedef TemplateArgumentLoc reference;
2793 typedef typename std::iterator_traits<InputIterator>::difference_type
2794 difference_type;
2795 typedef std::input_iterator_tag iterator_category;
2796
2797 class pointer {
2798 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002799
Douglas Gregorfe921a72010-12-20 23:36:19 +00002800 public:
2801 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2802
2803 const TemplateArgumentLoc *operator->() const { return &Arg; }
2804 };
2805
2806 TemplateArgumentLocInventIterator() { }
2807
2808 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2809 InputIterator Iter)
2810 : Self(Self), Iter(Iter) { }
2811
2812 TemplateArgumentLocInventIterator &operator++() {
2813 ++Iter;
2814 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002815 }
2816
Douglas Gregorfe921a72010-12-20 23:36:19 +00002817 TemplateArgumentLocInventIterator operator++(int) {
2818 TemplateArgumentLocInventIterator Old(*this);
2819 ++(*this);
2820 return Old;
2821 }
2822
2823 reference operator*() const {
2824 TemplateArgumentLoc Result;
2825 Self.InventTemplateArgumentLoc(*Iter, Result);
2826 return Result;
2827 }
2828
2829 pointer operator->() const { return pointer(**this); }
2830
2831 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2832 const TemplateArgumentLocInventIterator &Y) {
2833 return X.Iter == Y.Iter;
2834 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002835
Douglas Gregorfe921a72010-12-20 23:36:19 +00002836 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2837 const TemplateArgumentLocInventIterator &Y) {
2838 return X.Iter != Y.Iter;
2839 }
2840};
2841
Douglas Gregor42cafa82010-12-20 17:42:22 +00002842template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002843template<typename InputIterator>
2844bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2845 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002846 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002847 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002848 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002849 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002850
2851 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2852 // Unpack argument packs, which we translate them into separate
2853 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002854 // FIXME: We could do much better if we could guarantee that the
2855 // TemplateArgumentLocInfo for the pack expansion would be usable for
2856 // all of the template arguments in the argument pack.
2857 typedef TemplateArgumentLocInventIterator<Derived,
2858 TemplateArgument::pack_iterator>
2859 PackLocIterator;
2860 if (TransformTemplateArguments(PackLocIterator(*this,
2861 In.getArgument().pack_begin()),
2862 PackLocIterator(*this,
2863 In.getArgument().pack_end()),
2864 Outputs))
2865 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002866
2867 continue;
2868 }
2869
2870 if (In.getArgument().isPackExpansion()) {
2871 // We have a pack expansion, for which we will be substituting into
2872 // the pattern.
2873 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002874 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002875 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002876 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2877 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002878
2879 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2880 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2881 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2882
2883 // Determine whether the set of unexpanded parameter packs can and should
2884 // be expanded.
2885 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002886 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002887 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002888 if (getDerived().TryExpandParameterPacks(Ellipsis,
2889 Pattern.getSourceRange(),
2890 Unexpanded.data(),
2891 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002892 Expand,
2893 RetainExpansion,
2894 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002895 return true;
2896
2897 if (!Expand) {
2898 // The transform has determined that we should perform a simple
2899 // transformation on the pack expansion, producing another pack
2900 // expansion.
2901 TemplateArgumentLoc OutPattern;
2902 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2903 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2904 return true;
2905
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002906 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2907 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002908 if (Out.getArgument().isNull())
2909 return true;
2910
2911 Outputs.addArgument(Out);
2912 continue;
2913 }
2914
2915 // The transform has determined that we should perform an elementwise
2916 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002917 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2919
2920 if (getDerived().TransformTemplateArgument(Pattern, Out))
2921 return true;
2922
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002923 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002924 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2925 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002926 if (Out.getArgument().isNull())
2927 return true;
2928 }
2929
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002930 Outputs.addArgument(Out);
2931 }
2932
Douglas Gregor48d24112011-01-10 20:53:55 +00002933 // If we're supposed to retain a pack expansion, do so by temporarily
2934 // forgetting the partially-substituted parameter pack.
2935 if (RetainExpansion) {
2936 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2937
2938 if (getDerived().TransformTemplateArgument(Pattern, Out))
2939 return true;
2940
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002941 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2942 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002943 if (Out.getArgument().isNull())
2944 return true;
2945
2946 Outputs.addArgument(Out);
2947 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002948
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002949 continue;
2950 }
2951
2952 // The simple case:
2953 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002954 return true;
2955
2956 Outputs.addArgument(Out);
2957 }
2958
2959 return false;
2960
2961}
2962
Douglas Gregord6ff3322009-08-04 16:50:30 +00002963//===----------------------------------------------------------------------===//
2964// Type transformation
2965//===----------------------------------------------------------------------===//
2966
2967template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002968QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002969 if (getDerived().AlreadyTransformed(T))
2970 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002971
John McCall550e0c22009-10-21 00:40:46 +00002972 // Temporary workaround. All of these transformations should
2973 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002974 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2975 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002976
John McCall31f82722010-11-12 08:19:04 +00002977 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 if (!NewDI)
2980 return QualType();
2981
2982 return NewDI->getType();
2983}
2984
2985template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002986TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002987 if (getDerived().AlreadyTransformed(DI->getType()))
2988 return DI;
2989
2990 TypeLocBuilder TLB;
2991
2992 TypeLoc TL = DI->getTypeLoc();
2993 TLB.reserve(TL.getFullDataSize());
2994
John McCall31f82722010-11-12 08:19:04 +00002995 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002996 if (Result.isNull())
2997 return 0;
2998
John McCallbcd03502009-12-07 02:54:59 +00002999 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003000}
3001
3002template<typename Derived>
3003QualType
John McCall31f82722010-11-12 08:19:04 +00003004TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003005 switch (T.getTypeLocClass()) {
3006#define ABSTRACT_TYPELOC(CLASS, PARENT)
3007#define TYPELOC(CLASS, PARENT) \
3008 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003009 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003010#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003011 }
Mike Stump11289f42009-09-09 15:08:12 +00003012
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003013 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003014 return QualType();
3015}
3016
3017/// FIXME: By default, this routine adds type qualifiers only to types
3018/// that can have qualifiers, and silently suppresses those qualifiers
3019/// that are not permitted (e.g., qualifiers on reference or function
3020/// types). This is the right thing for template instantiation, but
3021/// probably not for other clients.
3022template<typename Derived>
3023QualType
3024TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003025 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003026 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003027
John McCall31f82722010-11-12 08:19:04 +00003028 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003029 if (Result.isNull())
3030 return QualType();
3031
3032 // Silently suppress qualifiers if the result type can't be qualified.
3033 // FIXME: this is the right thing for template instantiation, but
3034 // probably not for other clients.
3035 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003036 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003037
John McCallcb0f89a2010-06-05 06:41:15 +00003038 if (!Quals.empty()) {
3039 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3040 TLB.push<QualifiedTypeLoc>(Result);
3041 // No location information to preserve.
3042 }
John McCall550e0c22009-10-21 00:40:46 +00003043
3044 return Result;
3045}
3046
John McCall31f82722010-11-12 08:19:04 +00003047/// \brief Transforms a type that was written in a scope specifier,
3048/// given an object type, the results of unqualified lookup, and
3049/// an already-instantiated prefix.
3050///
3051/// The object type is provided iff the scope specifier qualifies the
3052/// member of a dependent member-access expression. The prefix is
3053/// provided iff the the scope specifier in which this appears has a
3054/// prefix.
3055///
3056/// This is private to TreeTransform.
3057template<typename Derived>
3058QualType
3059TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3060 QualType ObjectType,
3061 NamedDecl *UnqualLookup,
3062 NestedNameSpecifier *Prefix) {
3063 if (getDerived().AlreadyTransformed(T))
3064 return T;
3065
3066 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003067 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003068
3069 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3070 UnqualLookup, Prefix);
3071 if (!TSI) return QualType();
3072 return TSI->getType();
3073}
3074
3075template<typename Derived>
3076TypeSourceInfo *
3077TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3078 QualType ObjectType,
3079 NamedDecl *UnqualLookup,
3080 NestedNameSpecifier *Prefix) {
3081 // TODO: in some cases, we might be some verification to do here.
3082 if (ObjectType.isNull())
3083 return getDerived().TransformType(TSI);
3084
3085 QualType T = TSI->getType();
3086 if (getDerived().AlreadyTransformed(T))
3087 return TSI;
3088
3089 TypeLocBuilder TLB;
3090 QualType Result;
3091
3092 if (isa<TemplateSpecializationType>(T)) {
3093 TemplateSpecializationTypeLoc TL
3094 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3095
3096 TemplateName Template =
3097 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3098 ObjectType, UnqualLookup);
3099 if (Template.isNull()) return 0;
3100
3101 Result = getDerived()
3102 .TransformTemplateSpecializationType(TLB, TL, Template);
3103 } else if (isa<DependentTemplateSpecializationType>(T)) {
3104 DependentTemplateSpecializationTypeLoc TL
3105 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3106
3107 Result = getDerived()
3108 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3109 } else {
3110 // Nothing special needs to be done for these.
3111 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3112 }
3113
3114 if (Result.isNull()) return 0;
3115 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3116}
3117
John McCall550e0c22009-10-21 00:40:46 +00003118template <class TyLoc> static inline
3119QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3120 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3121 NewT.setNameLoc(T.getNameLoc());
3122 return T.getType();
3123}
3124
John McCall550e0c22009-10-21 00:40:46 +00003125template<typename Derived>
3126QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003127 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003128 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3129 NewT.setBuiltinLoc(T.getBuiltinLoc());
3130 if (T.needsExtraLocalData())
3131 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3132 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003133}
Mike Stump11289f42009-09-09 15:08:12 +00003134
Douglas Gregord6ff3322009-08-04 16:50:30 +00003135template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003136QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003137 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003138 // FIXME: recurse?
3139 return TransformTypeSpecType(TLB, T);
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>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003144 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003145 QualType PointeeType
3146 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003147 if (PointeeType.isNull())
3148 return QualType();
3149
3150 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003151 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003152 // A dependent pointer type 'T *' has is being transformed such
3153 // that an Objective-C class type is being replaced for 'T'. The
3154 // resulting pointer type is an ObjCObjectPointerType, not a
3155 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003156 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003157
John McCall8b07ec22010-05-15 11:32:37 +00003158 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3159 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003160 return Result;
3161 }
John McCall31f82722010-11-12 08:19:04 +00003162
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003163 if (getDerived().AlwaysRebuild() ||
3164 PointeeType != TL.getPointeeLoc().getType()) {
3165 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3166 if (Result.isNull())
3167 return QualType();
3168 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003169
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003170 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3171 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003172 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003173}
Mike Stump11289f42009-09-09 15:08:12 +00003174
3175template<typename Derived>
3176QualType
John McCall550e0c22009-10-21 00:40:46 +00003177TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003178 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003179 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003180 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3181 if (PointeeType.isNull())
3182 return QualType();
3183
3184 QualType Result = TL.getType();
3185 if (getDerived().AlwaysRebuild() ||
3186 PointeeType != TL.getPointeeLoc().getType()) {
3187 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003188 TL.getSigilLoc());
3189 if (Result.isNull())
3190 return QualType();
3191 }
3192
Douglas Gregor049211a2010-04-22 16:50:51 +00003193 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003194 NewT.setSigilLoc(TL.getSigilLoc());
3195 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003196}
3197
John McCall70dd5f62009-10-30 00:06:24 +00003198/// Transforms a reference type. Note that somewhat paradoxically we
3199/// don't care whether the type itself is an l-value type or an r-value
3200/// type; we only care if the type was *written* as an l-value type
3201/// or an r-value type.
3202template<typename Derived>
3203QualType
3204TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003205 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003206 const ReferenceType *T = TL.getTypePtr();
3207
3208 // Note that this works with the pointee-as-written.
3209 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3210 if (PointeeType.isNull())
3211 return QualType();
3212
3213 QualType Result = TL.getType();
3214 if (getDerived().AlwaysRebuild() ||
3215 PointeeType != T->getPointeeTypeAsWritten()) {
3216 Result = getDerived().RebuildReferenceType(PointeeType,
3217 T->isSpelledAsLValue(),
3218 TL.getSigilLoc());
3219 if (Result.isNull())
3220 return QualType();
3221 }
3222
3223 // r-value references can be rebuilt as l-value references.
3224 ReferenceTypeLoc NewTL;
3225 if (isa<LValueReferenceType>(Result))
3226 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3227 else
3228 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3229 NewTL.setSigilLoc(TL.getSigilLoc());
3230
3231 return Result;
3232}
3233
Mike Stump11289f42009-09-09 15:08:12 +00003234template<typename Derived>
3235QualType
John McCall550e0c22009-10-21 00:40:46 +00003236TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003237 LValueReferenceTypeLoc TL) {
3238 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003239}
3240
Mike Stump11289f42009-09-09 15:08:12 +00003241template<typename Derived>
3242QualType
John McCall550e0c22009-10-21 00:40:46 +00003243TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003244 RValueReferenceTypeLoc TL) {
3245 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246}
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003249QualType
John McCall550e0c22009-10-21 00:40:46 +00003250TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003251 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003252 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003253
3254 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255 if (PointeeType.isNull())
3256 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003257
John McCall550e0c22009-10-21 00:40:46 +00003258 // TODO: preserve source information for this.
3259 QualType ClassType
3260 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003261 if (ClassType.isNull())
3262 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003263
John McCall550e0c22009-10-21 00:40:46 +00003264 QualType Result = TL.getType();
3265 if (getDerived().AlwaysRebuild() ||
3266 PointeeType != T->getPointeeType() ||
3267 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003268 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3269 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003270 if (Result.isNull())
3271 return QualType();
3272 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003273
John McCall550e0c22009-10-21 00:40:46 +00003274 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3275 NewTL.setSigilLoc(TL.getSigilLoc());
3276
3277 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003278}
3279
Mike Stump11289f42009-09-09 15:08:12 +00003280template<typename Derived>
3281QualType
John McCall550e0c22009-10-21 00:40:46 +00003282TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003283 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003284 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003285 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003286 if (ElementType.isNull())
3287 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003288
John McCall550e0c22009-10-21 00:40:46 +00003289 QualType Result = TL.getType();
3290 if (getDerived().AlwaysRebuild() ||
3291 ElementType != T->getElementType()) {
3292 Result = getDerived().RebuildConstantArrayType(ElementType,
3293 T->getSizeModifier(),
3294 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003295 T->getIndexTypeCVRQualifiers(),
3296 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003297 if (Result.isNull())
3298 return QualType();
3299 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003300
John McCall550e0c22009-10-21 00:40:46 +00003301 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3302 NewTL.setLBracketLoc(TL.getLBracketLoc());
3303 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003304
John McCall550e0c22009-10-21 00:40:46 +00003305 Expr *Size = TL.getSizeExpr();
3306 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003307 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003308 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3309 }
3310 NewTL.setSizeExpr(Size);
3311
3312 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313}
Mike Stump11289f42009-09-09 15:08:12 +00003314
Douglas Gregord6ff3322009-08-04 16:50:30 +00003315template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003317 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003318 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003319 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003320 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003321 if (ElementType.isNull())
3322 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003323
John McCall550e0c22009-10-21 00:40:46 +00003324 QualType Result = TL.getType();
3325 if (getDerived().AlwaysRebuild() ||
3326 ElementType != T->getElementType()) {
3327 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003329 T->getIndexTypeCVRQualifiers(),
3330 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003331 if (Result.isNull())
3332 return QualType();
3333 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003334
John McCall550e0c22009-10-21 00:40:46 +00003335 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3336 NewTL.setLBracketLoc(TL.getLBracketLoc());
3337 NewTL.setRBracketLoc(TL.getRBracketLoc());
3338 NewTL.setSizeExpr(0);
3339
3340 return Result;
3341}
3342
3343template<typename Derived>
3344QualType
3345TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003346 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003347 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003348 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3349 if (ElementType.isNull())
3350 return QualType();
3351
3352 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003353 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003354
John McCalldadc5752010-08-24 06:29:42 +00003355 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003356 = getDerived().TransformExpr(T->getSizeExpr());
3357 if (SizeResult.isInvalid())
3358 return QualType();
3359
John McCallb268a282010-08-23 23:25:46 +00003360 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003361
3362 QualType Result = TL.getType();
3363 if (getDerived().AlwaysRebuild() ||
3364 ElementType != T->getElementType() ||
3365 Size != T->getSizeExpr()) {
3366 Result = getDerived().RebuildVariableArrayType(ElementType,
3367 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003368 Size,
John McCall550e0c22009-10-21 00:40:46 +00003369 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003370 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003371 if (Result.isNull())
3372 return QualType();
3373 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003374
John McCall550e0c22009-10-21 00:40:46 +00003375 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3376 NewTL.setLBracketLoc(TL.getLBracketLoc());
3377 NewTL.setRBracketLoc(TL.getRBracketLoc());
3378 NewTL.setSizeExpr(Size);
3379
3380 return Result;
3381}
3382
3383template<typename Derived>
3384QualType
3385TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003386 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003387 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003388 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3389 if (ElementType.isNull())
3390 return QualType();
3391
3392 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003393 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003394
John McCall33ddac02011-01-19 10:06:00 +00003395 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3396 Expr *origSize = TL.getSizeExpr();
3397 if (!origSize) origSize = T->getSizeExpr();
3398
3399 ExprResult sizeResult
3400 = getDerived().TransformExpr(origSize);
3401 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003402 return QualType();
3403
John McCall33ddac02011-01-19 10:06:00 +00003404 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003405
3406 QualType Result = TL.getType();
3407 if (getDerived().AlwaysRebuild() ||
3408 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003409 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003410 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3411 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003412 size,
John McCall550e0c22009-10-21 00:40:46 +00003413 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003414 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003415 if (Result.isNull())
3416 return QualType();
3417 }
John McCall550e0c22009-10-21 00:40:46 +00003418
3419 // We might have any sort of array type now, but fortunately they
3420 // all have the same location layout.
3421 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3422 NewTL.setLBracketLoc(TL.getLBracketLoc());
3423 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003424 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003425
3426 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003427}
Mike Stump11289f42009-09-09 15:08:12 +00003428
3429template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003430QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003431 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003432 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003433 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003434
3435 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003436 QualType ElementType = getDerived().TransformType(T->getElementType());
3437 if (ElementType.isNull())
3438 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregore922c772009-08-04 22:27:00 +00003440 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003441 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003442
John McCalldadc5752010-08-24 06:29:42 +00003443 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003444 if (Size.isInvalid())
3445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003446
John McCall550e0c22009-10-21 00:40:46 +00003447 QualType Result = TL.getType();
3448 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003449 ElementType != T->getElementType() ||
3450 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003451 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003452 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003453 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003454 if (Result.isNull())
3455 return QualType();
3456 }
John McCall550e0c22009-10-21 00:40:46 +00003457
3458 // Result might be dependent or not.
3459 if (isa<DependentSizedExtVectorType>(Result)) {
3460 DependentSizedExtVectorTypeLoc NewTL
3461 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3462 NewTL.setNameLoc(TL.getNameLoc());
3463 } else {
3464 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3465 NewTL.setNameLoc(TL.getNameLoc());
3466 }
3467
3468 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003469}
Mike Stump11289f42009-09-09 15:08:12 +00003470
3471template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003472QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003473 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003474 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003475 QualType ElementType = getDerived().TransformType(T->getElementType());
3476 if (ElementType.isNull())
3477 return QualType();
3478
John McCall550e0c22009-10-21 00:40:46 +00003479 QualType Result = TL.getType();
3480 if (getDerived().AlwaysRebuild() ||
3481 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003482 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003483 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003484 if (Result.isNull())
3485 return QualType();
3486 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003487
John McCall550e0c22009-10-21 00:40:46 +00003488 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3489 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003490
John McCall550e0c22009-10-21 00:40:46 +00003491 return Result;
3492}
3493
3494template<typename Derived>
3495QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003496 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003497 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003498 QualType ElementType = getDerived().TransformType(T->getElementType());
3499 if (ElementType.isNull())
3500 return QualType();
3501
3502 QualType Result = TL.getType();
3503 if (getDerived().AlwaysRebuild() ||
3504 ElementType != T->getElementType()) {
3505 Result = getDerived().RebuildExtVectorType(ElementType,
3506 T->getNumElements(),
3507 /*FIXME*/ SourceLocation());
3508 if (Result.isNull())
3509 return QualType();
3510 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003511
John McCall550e0c22009-10-21 00:40:46 +00003512 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3513 NewTL.setNameLoc(TL.getNameLoc());
3514
3515 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003516}
Mike Stump11289f42009-09-09 15:08:12 +00003517
3518template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003519ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003520TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3521 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003522 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003523 TypeSourceInfo *NewDI = 0;
3524
3525 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3526 // If we're substituting into a pack expansion type and we know the
3527 TypeLoc OldTL = OldDI->getTypeLoc();
3528 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3529
3530 TypeLocBuilder TLB;
3531 TypeLoc NewTL = OldDI->getTypeLoc();
3532 TLB.reserve(NewTL.getFullDataSize());
3533
3534 QualType Result = getDerived().TransformType(TLB,
3535 OldExpansionTL.getPatternLoc());
3536 if (Result.isNull())
3537 return 0;
3538
3539 Result = RebuildPackExpansionType(Result,
3540 OldExpansionTL.getPatternLoc().getSourceRange(),
3541 OldExpansionTL.getEllipsisLoc(),
3542 NumExpansions);
3543 if (Result.isNull())
3544 return 0;
3545
3546 PackExpansionTypeLoc NewExpansionTL
3547 = TLB.push<PackExpansionTypeLoc>(Result);
3548 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3549 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3550 } else
3551 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003552 if (!NewDI)
3553 return 0;
3554
3555 if (NewDI == OldDI)
3556 return OldParm;
3557 else
3558 return ParmVarDecl::Create(SemaRef.Context,
3559 OldParm->getDeclContext(),
3560 OldParm->getLocation(),
3561 OldParm->getIdentifier(),
3562 NewDI->getType(),
3563 NewDI,
3564 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003565 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003566 /* DefArg */ NULL);
3567}
3568
3569template<typename Derived>
3570bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003571 TransformFunctionTypeParams(SourceLocation Loc,
3572 ParmVarDecl **Params, unsigned NumParams,
3573 const QualType *ParamTypes,
3574 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3575 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3576 for (unsigned i = 0; i != NumParams; ++i) {
3577 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003578 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003579 if (OldParm->isParameterPack()) {
3580 // We have a function parameter pack that may need to be expanded.
3581 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003582
Douglas Gregor5499af42011-01-05 23:12:31 +00003583 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003584 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3585 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3586 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3587 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003588
3589 // Determine whether we should expand the parameter packs.
3590 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003591 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003592 llvm::Optional<unsigned> OrigNumExpansions
3593 = ExpansionTL.getTypePtr()->getNumExpansions();
3594 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003595 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3596 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003597 Unexpanded.data(),
3598 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003599 ShouldExpand,
3600 RetainExpansion,
3601 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003602 return true;
3603 }
3604
3605 if (ShouldExpand) {
3606 // Expand the function parameter pack into multiple, separate
3607 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003608 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003609 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003610 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3611 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003612 = getDerived().TransformFunctionTypeParam(OldParm,
3613 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003614 if (!NewParm)
3615 return true;
3616
Douglas Gregordd472162011-01-07 00:20:55 +00003617 OutParamTypes.push_back(NewParm->getType());
3618 if (PVars)
3619 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003620 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003621
3622 // If we're supposed to retain a pack expansion, do so by temporarily
3623 // forgetting the partially-substituted parameter pack.
3624 if (RetainExpansion) {
3625 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3626 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003627 = getDerived().TransformFunctionTypeParam(OldParm,
3628 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003629 if (!NewParm)
3630 return true;
3631
3632 OutParamTypes.push_back(NewParm->getType());
3633 if (PVars)
3634 PVars->push_back(NewParm);
3635 }
3636
Douglas Gregor5499af42011-01-05 23:12:31 +00003637 // We're done with the pack expansion.
3638 continue;
3639 }
3640
3641 // We'll substitute the parameter now without expanding the pack
3642 // expansion.
3643 }
3644
3645 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003646 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3647 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003648 if (!NewParm)
3649 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003650
Douglas Gregordd472162011-01-07 00:20:55 +00003651 OutParamTypes.push_back(NewParm->getType());
3652 if (PVars)
3653 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003654 continue;
3655 }
John McCall58f10c32010-03-11 09:03:00 +00003656
3657 // Deal with the possibility that we don't have a parameter
3658 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003659 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003660 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003661 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003662 if (const PackExpansionType *Expansion
3663 = dyn_cast<PackExpansionType>(OldType)) {
3664 // We have a function parameter pack that may need to be expanded.
3665 QualType Pattern = Expansion->getPattern();
3666 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3667 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3668
3669 // Determine whether we should expand the parameter packs.
3670 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003671 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003672 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003673 Unexpanded.data(),
3674 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003675 ShouldExpand,
3676 RetainExpansion,
3677 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003678 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003679 }
3680
3681 if (ShouldExpand) {
3682 // Expand the function parameter pack into multiple, separate
3683 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003684 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003685 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3686 QualType NewType = getDerived().TransformType(Pattern);
3687 if (NewType.isNull())
3688 return true;
John McCall58f10c32010-03-11 09:03:00 +00003689
Douglas Gregordd472162011-01-07 00:20:55 +00003690 OutParamTypes.push_back(NewType);
3691 if (PVars)
3692 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003693 }
3694
3695 // We're done with the pack expansion.
3696 continue;
3697 }
3698
Douglas Gregor48d24112011-01-10 20:53:55 +00003699 // If we're supposed to retain a pack expansion, do so by temporarily
3700 // forgetting the partially-substituted parameter pack.
3701 if (RetainExpansion) {
3702 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3703 QualType NewType = getDerived().TransformType(Pattern);
3704 if (NewType.isNull())
3705 return true;
3706
3707 OutParamTypes.push_back(NewType);
3708 if (PVars)
3709 PVars->push_back(0);
3710 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003711
Douglas Gregor5499af42011-01-05 23:12:31 +00003712 // We'll substitute the parameter now without expanding the pack
3713 // expansion.
3714 OldType = Expansion->getPattern();
3715 IsPackExpansion = true;
3716 }
3717
3718 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3719 QualType NewType = getDerived().TransformType(OldType);
3720 if (NewType.isNull())
3721 return true;
3722
3723 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003724 NewType = getSema().Context.getPackExpansionType(NewType,
3725 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003726
Douglas Gregordd472162011-01-07 00:20:55 +00003727 OutParamTypes.push_back(NewType);
3728 if (PVars)
3729 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003730 }
3731
3732 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003733 }
John McCall58f10c32010-03-11 09:03:00 +00003734
3735template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003736QualType
John McCall550e0c22009-10-21 00:40:46 +00003737TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003738 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003739 // Transform the parameters and return type.
3740 //
3741 // We instantiate in source order, with the return type first followed by
3742 // the parameters, because users tend to expect this (even if they shouldn't
3743 // rely on it!).
3744 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003745 // When the function has a trailing return type, we instantiate the
3746 // parameters before the return type, since the return type can then refer
3747 // to the parameters themselves (via decltype, sizeof, etc.).
3748 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003749 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003750 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003751 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003752
Douglas Gregor7fb25412010-10-01 18:44:50 +00003753 QualType ResultType;
3754
3755 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003756 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3757 TL.getParmArray(),
3758 TL.getNumArgs(),
3759 TL.getTypePtr()->arg_type_begin(),
3760 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003761 return QualType();
3762
3763 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3764 if (ResultType.isNull())
3765 return QualType();
3766 }
3767 else {
3768 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3769 if (ResultType.isNull())
3770 return QualType();
3771
Douglas Gregordd472162011-01-07 00:20:55 +00003772 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3773 TL.getParmArray(),
3774 TL.getNumArgs(),
3775 TL.getTypePtr()->arg_type_begin(),
3776 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003777 return QualType();
3778 }
3779
John McCall550e0c22009-10-21 00:40:46 +00003780 QualType Result = TL.getType();
3781 if (getDerived().AlwaysRebuild() ||
3782 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003783 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003784 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3785 Result = getDerived().RebuildFunctionProtoType(ResultType,
3786 ParamTypes.data(),
3787 ParamTypes.size(),
3788 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003789 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003790 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003791 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003792 if (Result.isNull())
3793 return QualType();
3794 }
Mike Stump11289f42009-09-09 15:08:12 +00003795
John McCall550e0c22009-10-21 00:40:46 +00003796 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3797 NewTL.setLParenLoc(TL.getLParenLoc());
3798 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003799 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003800 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3801 NewTL.setArg(i, ParamDecls[i]);
3802
3803 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003804}
Mike Stump11289f42009-09-09 15:08:12 +00003805
Douglas Gregord6ff3322009-08-04 16:50:30 +00003806template<typename Derived>
3807QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003808 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003809 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003810 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003811 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3812 if (ResultType.isNull())
3813 return QualType();
3814
3815 QualType Result = TL.getType();
3816 if (getDerived().AlwaysRebuild() ||
3817 ResultType != T->getResultType())
3818 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3819
3820 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3821 NewTL.setLParenLoc(TL.getLParenLoc());
3822 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003823 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003824
3825 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003826}
Mike Stump11289f42009-09-09 15:08:12 +00003827
John McCallb96ec562009-12-04 22:46:56 +00003828template<typename Derived> QualType
3829TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003830 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003831 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003832 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003833 if (!D)
3834 return QualType();
3835
3836 QualType Result = TL.getType();
3837 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3838 Result = getDerived().RebuildUnresolvedUsingType(D);
3839 if (Result.isNull())
3840 return QualType();
3841 }
3842
3843 // We might get an arbitrary type spec type back. We should at
3844 // least always get a type spec type, though.
3845 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3846 NewTL.setNameLoc(TL.getNameLoc());
3847
3848 return Result;
3849}
3850
Douglas Gregord6ff3322009-08-04 16:50:30 +00003851template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003852QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003853 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003854 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003855 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003856 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3857 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003858 if (!Typedef)
3859 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003860
John McCall550e0c22009-10-21 00:40:46 +00003861 QualType Result = TL.getType();
3862 if (getDerived().AlwaysRebuild() ||
3863 Typedef != T->getDecl()) {
3864 Result = getDerived().RebuildTypedefType(Typedef);
3865 if (Result.isNull())
3866 return QualType();
3867 }
Mike Stump11289f42009-09-09 15:08:12 +00003868
John McCall550e0c22009-10-21 00:40:46 +00003869 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3870 NewTL.setNameLoc(TL.getNameLoc());
3871
3872 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003873}
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregord6ff3322009-08-04 16:50:30 +00003875template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003876QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003877 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003878 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003879 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003880
John McCalldadc5752010-08-24 06:29:42 +00003881 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882 if (E.isInvalid())
3883 return QualType();
3884
John McCall550e0c22009-10-21 00:40:46 +00003885 QualType Result = TL.getType();
3886 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003887 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003888 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003889 if (Result.isNull())
3890 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003891 }
John McCall550e0c22009-10-21 00:40:46 +00003892 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003893
John McCall550e0c22009-10-21 00:40:46 +00003894 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003895 NewTL.setTypeofLoc(TL.getTypeofLoc());
3896 NewTL.setLParenLoc(TL.getLParenLoc());
3897 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003898
3899 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003900}
Mike Stump11289f42009-09-09 15:08:12 +00003901
3902template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003903QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003904 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003905 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3906 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3907 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003908 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003909
John McCall550e0c22009-10-21 00:40:46 +00003910 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003911 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3912 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003913 if (Result.isNull())
3914 return QualType();
3915 }
Mike Stump11289f42009-09-09 15:08:12 +00003916
John McCall550e0c22009-10-21 00:40:46 +00003917 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003918 NewTL.setTypeofLoc(TL.getTypeofLoc());
3919 NewTL.setLParenLoc(TL.getLParenLoc());
3920 NewTL.setRParenLoc(TL.getRParenLoc());
3921 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003922
3923 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003924}
Mike Stump11289f42009-09-09 15:08:12 +00003925
3926template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003927QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003928 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003929 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003930
Douglas Gregore922c772009-08-04 22:27:00 +00003931 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003932 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003933
John McCalldadc5752010-08-24 06:29:42 +00003934 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003935 if (E.isInvalid())
3936 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003937
John McCall550e0c22009-10-21 00:40:46 +00003938 QualType Result = TL.getType();
3939 if (getDerived().AlwaysRebuild() ||
3940 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003941 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003942 if (Result.isNull())
3943 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003944 }
John McCall550e0c22009-10-21 00:40:46 +00003945 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003946
John McCall550e0c22009-10-21 00:40:46 +00003947 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3948 NewTL.setNameLoc(TL.getNameLoc());
3949
3950 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003951}
3952
3953template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003954QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003955 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003956 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003957 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003958 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3959 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003960 if (!Record)
3961 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003962
John McCall550e0c22009-10-21 00:40:46 +00003963 QualType Result = TL.getType();
3964 if (getDerived().AlwaysRebuild() ||
3965 Record != T->getDecl()) {
3966 Result = getDerived().RebuildRecordType(Record);
3967 if (Result.isNull())
3968 return QualType();
3969 }
Mike Stump11289f42009-09-09 15:08:12 +00003970
John McCall550e0c22009-10-21 00:40:46 +00003971 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3972 NewTL.setNameLoc(TL.getNameLoc());
3973
3974 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003975}
Mike Stump11289f42009-09-09 15:08:12 +00003976
3977template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003978QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003979 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003980 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003981 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003982 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3983 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003984 if (!Enum)
3985 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003986
John McCall550e0c22009-10-21 00:40:46 +00003987 QualType Result = TL.getType();
3988 if (getDerived().AlwaysRebuild() ||
3989 Enum != T->getDecl()) {
3990 Result = getDerived().RebuildEnumType(Enum);
3991 if (Result.isNull())
3992 return QualType();
3993 }
Mike Stump11289f42009-09-09 15:08:12 +00003994
John McCall550e0c22009-10-21 00:40:46 +00003995 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3996 NewTL.setNameLoc(TL.getNameLoc());
3997
3998 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003999}
John McCallfcc33b02009-09-05 00:15:47 +00004000
John McCalle78aac42010-03-10 03:28:59 +00004001template<typename Derived>
4002QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4003 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004004 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004005 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4006 TL.getTypePtr()->getDecl());
4007 if (!D) return QualType();
4008
4009 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4010 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4011 return T;
4012}
4013
Douglas Gregord6ff3322009-08-04 16:50:30 +00004014template<typename Derived>
4015QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004016 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004017 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004018 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004019}
4020
Mike Stump11289f42009-09-09 15:08:12 +00004021template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004022QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004023 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004024 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004025 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004026}
4027
4028template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004029QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4030 TypeLocBuilder &TLB,
4031 SubstTemplateTypeParmPackTypeLoc TL) {
4032 return TransformTypeSpecType(TLB, TL);
4033}
4034
4035template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004036QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004037 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004038 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004039 const TemplateSpecializationType *T = TL.getTypePtr();
4040
Mike Stump11289f42009-09-09 15:08:12 +00004041 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004042 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043 if (Template.isNull())
4044 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004045
John McCall31f82722010-11-12 08:19:04 +00004046 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4047}
4048
Douglas Gregorfe921a72010-12-20 23:36:19 +00004049namespace {
4050 /// \brief Simple iterator that traverses the template arguments in a
4051 /// container that provides a \c getArgLoc() member function.
4052 ///
4053 /// This iterator is intended to be used with the iterator form of
4054 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4055 template<typename ArgLocContainer>
4056 class TemplateArgumentLocContainerIterator {
4057 ArgLocContainer *Container;
4058 unsigned Index;
4059
4060 public:
4061 typedef TemplateArgumentLoc value_type;
4062 typedef TemplateArgumentLoc reference;
4063 typedef int difference_type;
4064 typedef std::input_iterator_tag iterator_category;
4065
4066 class pointer {
4067 TemplateArgumentLoc Arg;
4068
4069 public:
4070 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4071
4072 const TemplateArgumentLoc *operator->() const {
4073 return &Arg;
4074 }
4075 };
4076
4077
4078 TemplateArgumentLocContainerIterator() {}
4079
4080 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4081 unsigned Index)
4082 : Container(&Container), Index(Index) { }
4083
4084 TemplateArgumentLocContainerIterator &operator++() {
4085 ++Index;
4086 return *this;
4087 }
4088
4089 TemplateArgumentLocContainerIterator operator++(int) {
4090 TemplateArgumentLocContainerIterator Old(*this);
4091 ++(*this);
4092 return Old;
4093 }
4094
4095 TemplateArgumentLoc operator*() const {
4096 return Container->getArgLoc(Index);
4097 }
4098
4099 pointer operator->() const {
4100 return pointer(Container->getArgLoc(Index));
4101 }
4102
4103 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004104 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004105 return X.Container == Y.Container && X.Index == Y.Index;
4106 }
4107
4108 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004109 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004110 return !(X == Y);
4111 }
4112 };
4113}
4114
4115
John McCall31f82722010-11-12 08:19:04 +00004116template <typename Derived>
4117QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4118 TypeLocBuilder &TLB,
4119 TemplateSpecializationTypeLoc TL,
4120 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004121 TemplateArgumentListInfo NewTemplateArgs;
4122 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4123 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004124 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4125 ArgIterator;
4126 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4127 ArgIterator(TL, TL.getNumArgs()),
4128 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004129 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004130
John McCall0ad16662009-10-29 08:12:44 +00004131 // FIXME: maybe don't rebuild if all the template arguments are the same.
4132
4133 QualType Result =
4134 getDerived().RebuildTemplateSpecializationType(Template,
4135 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004136 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004137
4138 if (!Result.isNull()) {
4139 TemplateSpecializationTypeLoc NewTL
4140 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4141 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4142 NewTL.setLAngleLoc(TL.getLAngleLoc());
4143 NewTL.setRAngleLoc(TL.getRAngleLoc());
4144 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4145 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004146 }
Mike Stump11289f42009-09-09 15:08:12 +00004147
John McCall0ad16662009-10-29 08:12:44 +00004148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004149}
Mike Stump11289f42009-09-09 15:08:12 +00004150
4151template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004152QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004153TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004154 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004155 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004156
4157 NestedNameSpecifier *NNS = 0;
4158 // NOTE: the qualifier in an ElaboratedType is optional.
4159 if (T->getQualifier() != 0) {
4160 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004161 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004162 if (!NNS)
4163 return QualType();
4164 }
Mike Stump11289f42009-09-09 15:08:12 +00004165
John McCall31f82722010-11-12 08:19:04 +00004166 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4167 if (NamedT.isNull())
4168 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004169
John McCall550e0c22009-10-21 00:40:46 +00004170 QualType Result = TL.getType();
4171 if (getDerived().AlwaysRebuild() ||
4172 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004173 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004174 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4175 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004176 if (Result.isNull())
4177 return QualType();
4178 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004179
Abramo Bagnara6150c882010-05-11 21:36:43 +00004180 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004181 NewTL.setKeywordLoc(TL.getKeywordLoc());
4182 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004183
4184 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004185}
Mike Stump11289f42009-09-09 15:08:12 +00004186
4187template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004188QualType TreeTransform<Derived>::TransformAttributedType(
4189 TypeLocBuilder &TLB,
4190 AttributedTypeLoc TL) {
4191 const AttributedType *oldType = TL.getTypePtr();
4192 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4193 if (modifiedType.isNull())
4194 return QualType();
4195
4196 QualType result = TL.getType();
4197
4198 // FIXME: dependent operand expressions?
4199 if (getDerived().AlwaysRebuild() ||
4200 modifiedType != oldType->getModifiedType()) {
4201 // TODO: this is really lame; we should really be rebuilding the
4202 // equivalent type from first principles.
4203 QualType equivalentType
4204 = getDerived().TransformType(oldType->getEquivalentType());
4205 if (equivalentType.isNull())
4206 return QualType();
4207 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4208 modifiedType,
4209 equivalentType);
4210 }
4211
4212 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4213 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4214 if (TL.hasAttrOperand())
4215 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4216 if (TL.hasAttrExprOperand())
4217 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4218 else if (TL.hasAttrEnumOperand())
4219 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4220
4221 return result;
4222}
4223
4224template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004225QualType
4226TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4227 ParenTypeLoc TL) {
4228 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4229 if (Inner.isNull())
4230 return QualType();
4231
4232 QualType Result = TL.getType();
4233 if (getDerived().AlwaysRebuild() ||
4234 Inner != TL.getInnerLoc().getType()) {
4235 Result = getDerived().RebuildParenType(Inner);
4236 if (Result.isNull())
4237 return QualType();
4238 }
4239
4240 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4241 NewTL.setLParenLoc(TL.getLParenLoc());
4242 NewTL.setRParenLoc(TL.getRParenLoc());
4243 return Result;
4244}
4245
4246template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004247QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004248 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004249 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004250
Douglas Gregord6ff3322009-08-04 16:50:30 +00004251 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004252 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004253 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004254 if (!NNS)
4255 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004256
John McCallc392f372010-06-11 00:33:02 +00004257 QualType Result
4258 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4259 T->getIdentifier(),
4260 TL.getKeywordLoc(),
4261 TL.getQualifierRange(),
4262 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004263 if (Result.isNull())
4264 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004265
Abramo Bagnarad7548482010-05-19 21:37:53 +00004266 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4267 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004268 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4269
Abramo Bagnarad7548482010-05-19 21:37:53 +00004270 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4271 NewTL.setKeywordLoc(TL.getKeywordLoc());
4272 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004273 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004274 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4275 NewTL.setKeywordLoc(TL.getKeywordLoc());
4276 NewTL.setQualifierRange(TL.getQualifierRange());
4277 NewTL.setNameLoc(TL.getNameLoc());
4278 }
John McCall550e0c22009-10-21 00:40:46 +00004279 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004280}
Mike Stump11289f42009-09-09 15:08:12 +00004281
Douglas Gregord6ff3322009-08-04 16:50:30 +00004282template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004283QualType TreeTransform<Derived>::
4284 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004285 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004286 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004287
4288 NestedNameSpecifier *NNS
4289 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004290 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004291 if (!NNS)
4292 return QualType();
4293
John McCall31f82722010-11-12 08:19:04 +00004294 return getDerived()
4295 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4296}
4297
4298template<typename Derived>
4299QualType TreeTransform<Derived>::
4300 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4301 DependentTemplateSpecializationTypeLoc TL,
4302 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004303 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004304
John McCallc392f372010-06-11 00:33:02 +00004305 TemplateArgumentListInfo NewTemplateArgs;
4306 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4307 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004308
4309 typedef TemplateArgumentLocContainerIterator<
4310 DependentTemplateSpecializationTypeLoc> ArgIterator;
4311 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4312 ArgIterator(TL, TL.getNumArgs()),
4313 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004314 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004315
Douglas Gregora5614c52010-09-08 23:56:00 +00004316 QualType Result
4317 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4318 NNS,
4319 TL.getQualifierRange(),
4320 T->getIdentifier(),
4321 TL.getNameLoc(),
4322 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004323 if (Result.isNull())
4324 return QualType();
4325
4326 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4327 QualType NamedT = ElabT->getNamedType();
4328
4329 // Copy information relevant to the template specialization.
4330 TemplateSpecializationTypeLoc NamedTL
4331 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4332 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4333 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4334 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4335 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4336
4337 // Copy information relevant to the elaborated type.
4338 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4339 NewTL.setKeywordLoc(TL.getKeywordLoc());
4340 NewTL.setQualifierRange(TL.getQualifierRange());
4341 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004342 TypeLoc NewTL(Result, TL.getOpaqueData());
4343 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004344 }
4345 return Result;
4346}
4347
4348template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004349QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4350 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004351 QualType Pattern
4352 = getDerived().TransformType(TLB, TL.getPatternLoc());
4353 if (Pattern.isNull())
4354 return QualType();
4355
4356 QualType Result = TL.getType();
4357 if (getDerived().AlwaysRebuild() ||
4358 Pattern != TL.getPatternLoc().getType()) {
4359 Result = getDerived().RebuildPackExpansionType(Pattern,
4360 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004361 TL.getEllipsisLoc(),
4362 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004363 if (Result.isNull())
4364 return QualType();
4365 }
4366
4367 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4368 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4369 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004370}
4371
4372template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004373QualType
4374TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004375 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004376 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004377 TLB.pushFullCopy(TL);
4378 return TL.getType();
4379}
4380
4381template<typename Derived>
4382QualType
4383TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004384 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004385 // ObjCObjectType is never dependent.
4386 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004387 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004388}
Mike Stump11289f42009-09-09 15:08:12 +00004389
4390template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004391QualType
4392TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004393 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004394 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004395 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004396 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004397}
4398
Douglas Gregord6ff3322009-08-04 16:50:30 +00004399//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004400// Statement transformation
4401//===----------------------------------------------------------------------===//
4402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004403StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004404TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004405 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004406}
4407
4408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004409StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004410TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4411 return getDerived().TransformCompoundStmt(S, false);
4412}
4413
4414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004415StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004416TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004417 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004418 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004419 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004420 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004421 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4422 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004423 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004424 if (Result.isInvalid()) {
4425 // Immediately fail if this was a DeclStmt, since it's very
4426 // likely that this will cause problems for future statements.
4427 if (isa<DeclStmt>(*B))
4428 return StmtError();
4429
4430 // Otherwise, just keep processing substatements and fail later.
4431 SubStmtInvalid = true;
4432 continue;
4433 }
Mike Stump11289f42009-09-09 15:08:12 +00004434
Douglas Gregorebe10102009-08-20 07:17:43 +00004435 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4436 Statements.push_back(Result.takeAs<Stmt>());
4437 }
Mike Stump11289f42009-09-09 15:08:12 +00004438
John McCall1ababa62010-08-27 19:56:05 +00004439 if (SubStmtInvalid)
4440 return StmtError();
4441
Douglas Gregorebe10102009-08-20 07:17:43 +00004442 if (!getDerived().AlwaysRebuild() &&
4443 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004444 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004445
4446 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4447 move_arg(Statements),
4448 S->getRBracLoc(),
4449 IsStmtExpr);
4450}
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregorebe10102009-08-20 07:17:43 +00004452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004453StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004454TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004455 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004456 {
4457 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004458 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004459
Eli Friedman06577382009-11-19 03:14:00 +00004460 // Transform the left-hand case value.
4461 LHS = getDerived().TransformExpr(S->getLHS());
4462 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004463 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004464
Eli Friedman06577382009-11-19 03:14:00 +00004465 // Transform the right-hand case value (for the GNU case-range extension).
4466 RHS = getDerived().TransformExpr(S->getRHS());
4467 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004468 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004469 }
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregorebe10102009-08-20 07:17:43 +00004471 // Build the case statement.
4472 // Case statements are always rebuilt so that they will attached to their
4473 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004474 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004475 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004476 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004477 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004478 S->getColonLoc());
4479 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004480 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004481
Douglas Gregorebe10102009-08-20 07:17:43 +00004482 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004483 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004484 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004485 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregorebe10102009-08-20 07:17:43 +00004487 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004488 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004489}
4490
4491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004492StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004493TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004494 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004495 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004496 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004497 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregorebe10102009-08-20 07:17:43 +00004499 // Default statements are always rebuilt
4500 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004501 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004502}
Mike Stump11289f42009-09-09 15:08:12 +00004503
Douglas Gregorebe10102009-08-20 07:17:43 +00004504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004505StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004506TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004507 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004508 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004509 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004510
Chris Lattnercab02a62011-02-17 20:34:02 +00004511 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4512 S->getDecl());
4513 if (!LD)
4514 return StmtError();
4515
4516
Douglas Gregorebe10102009-08-20 07:17:43 +00004517 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004518 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004519 cast<LabelDecl>(LD), SourceLocation(),
4520 SubStmt.get());
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) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004759 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4760 S->getLabel());
4761 if (!LD)
4762 return StmtError();
4763
Douglas Gregorebe10102009-08-20 07:17:43 +00004764 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004765 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004766 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004767}
4768
4769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004770StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004771TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004772 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004774 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 if (!getDerived().AlwaysRebuild() &&
4777 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004778 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004779
4780 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004781 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004782}
4783
4784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004785StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004786TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004787 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004788}
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregorebe10102009-08-20 07:17:43 +00004790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004792TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004793 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004794}
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregorebe10102009-08-20 07:17:43 +00004796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004798TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004799 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004800 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004801 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004802
Mike Stump11289f42009-09-09 15:08:12 +00004803 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004804 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004805 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004806}
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregorebe10102009-08-20 07:17:43 +00004808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004809StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004810TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004811 bool DeclChanged = false;
4812 llvm::SmallVector<Decl *, 4> Decls;
4813 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4814 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004815 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4816 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004817 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004818 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 if (Transformed != *D)
4821 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 Decls.push_back(Transformed);
4824 }
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregorebe10102009-08-20 07:17:43 +00004826 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004827 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004828
4829 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004830 S->getStartLoc(), S->getEndLoc());
4831}
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregorebe10102009-08-20 07:17:43 +00004833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004834StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004835TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004836
John McCall37ad5512010-08-23 06:44:23 +00004837 ASTOwningVector<Expr*> Constraints(getSema());
4838 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004839 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004840
John McCalldadc5752010-08-24 06:29:42 +00004841 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004842 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004843
4844 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004845
Anders Carlssonaaeef072010-01-24 05:50:09 +00004846 // Go through the outputs.
4847 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004848 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004849
Anders Carlssonaaeef072010-01-24 05:50:09 +00004850 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004851 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004852
Anders Carlssonaaeef072010-01-24 05:50:09 +00004853 // Transform the output expr.
4854 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004855 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004856 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004857 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004858
Anders Carlssonaaeef072010-01-24 05:50:09 +00004859 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004860
John McCallb268a282010-08-23 23:25:46 +00004861 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004862 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004863
Anders Carlssonaaeef072010-01-24 05:50:09 +00004864 // Go through the inputs.
4865 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004866 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004867
Anders Carlssonaaeef072010-01-24 05:50:09 +00004868 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004869 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004870
Anders Carlssonaaeef072010-01-24 05:50:09 +00004871 // Transform the input expr.
4872 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004873 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004874 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004875 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004876
Anders Carlssonaaeef072010-01-24 05:50:09 +00004877 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004878
John McCallb268a282010-08-23 23:25:46 +00004879 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004880 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004881
Anders Carlssonaaeef072010-01-24 05:50:09 +00004882 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004883 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004884
4885 // Go through the clobbers.
4886 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004887 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004888
4889 // No need to transform the asm string literal.
4890 AsmString = SemaRef.Owned(S->getAsmString());
4891
4892 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4893 S->isSimple(),
4894 S->isVolatile(),
4895 S->getNumOutputs(),
4896 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004897 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004898 move_arg(Constraints),
4899 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004900 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004901 move_arg(Clobbers),
4902 S->getRParenLoc(),
4903 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004904}
4905
4906
4907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004908StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004909TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004910 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004911 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004912 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004913 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004914
Douglas Gregor96c79492010-04-23 22:50:49 +00004915 // Transform the @catch statements (if present).
4916 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004917 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004918 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004919 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004920 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004921 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004922 if (Catch.get() != S->getCatchStmt(I))
4923 AnyCatchChanged = true;
4924 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004925 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004926
Douglas Gregor306de2f2010-04-22 23:59:56 +00004927 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004928 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004929 if (S->getFinallyStmt()) {
4930 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4931 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004932 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004933 }
4934
4935 // If nothing changed, just retain this statement.
4936 if (!getDerived().AlwaysRebuild() &&
4937 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004938 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004939 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004940 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004941
Douglas Gregor306de2f2010-04-22 23:59:56 +00004942 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004943 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4944 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004945}
Mike Stump11289f42009-09-09 15:08:12 +00004946
Douglas Gregorebe10102009-08-20 07:17:43 +00004947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004948StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004949TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004950 // Transform the @catch parameter, if there is one.
4951 VarDecl *Var = 0;
4952 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4953 TypeSourceInfo *TSInfo = 0;
4954 if (FromVar->getTypeSourceInfo()) {
4955 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4956 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004957 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004958 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004959
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004960 QualType T;
4961 if (TSInfo)
4962 T = TSInfo->getType();
4963 else {
4964 T = getDerived().TransformType(FromVar->getType());
4965 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004966 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004967 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004968
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004969 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4970 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004971 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004972 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004973
John McCalldadc5752010-08-24 06:29:42 +00004974 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004975 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004976 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004977
4978 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004979 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004980 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004981}
Mike Stump11289f42009-09-09 15:08:12 +00004982
Douglas Gregorebe10102009-08-20 07:17:43 +00004983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004984StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004985TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004986 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004987 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004988 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004990
Douglas Gregor306de2f2010-04-22 23:59:56 +00004991 // If nothing changed, just retain this statement.
4992 if (!getDerived().AlwaysRebuild() &&
4993 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004994 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004995
4996 // Build a new statement.
4997 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004998 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004999}
Mike Stump11289f42009-09-09 15:08:12 +00005000
Douglas Gregorebe10102009-08-20 07:17:43 +00005001template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005002StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005003TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005004 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005005 if (S->getThrowExpr()) {
5006 Operand = getDerived().TransformExpr(S->getThrowExpr());
5007 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005009 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005010
Douglas Gregor2900c162010-04-22 21:44:01 +00005011 if (!getDerived().AlwaysRebuild() &&
5012 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005013 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005014
John McCallb268a282010-08-23 23:25:46 +00005015 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005016}
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregorebe10102009-08-20 07:17:43 +00005018template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005019StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005020TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005021 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005022 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005023 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005024 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005025 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005026
Douglas Gregor6148de72010-04-22 22:01:21 +00005027 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005028 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005029 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005030 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005031
Douglas Gregor6148de72010-04-22 22:01:21 +00005032 // If nothing change, just retain the current statement.
5033 if (!getDerived().AlwaysRebuild() &&
5034 Object.get() == S->getSynchExpr() &&
5035 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005036 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005037
5038 // Build a new statement.
5039 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005040 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005041}
5042
5043template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005044StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005045TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005046 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005047 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005048 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005049 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005050 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005051
Douglas Gregorf68a5082010-04-22 23:10:45 +00005052 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005053 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005054 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005055 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005056
Douglas Gregorf68a5082010-04-22 23:10:45 +00005057 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005058 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005059 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005060 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005061
Douglas Gregorf68a5082010-04-22 23:10:45 +00005062 // If nothing changed, just retain this statement.
5063 if (!getDerived().AlwaysRebuild() &&
5064 Element.get() == S->getElement() &&
5065 Collection.get() == S->getCollection() &&
5066 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005067 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005068
Douglas Gregorf68a5082010-04-22 23:10:45 +00005069 // Build a new statement.
5070 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5071 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005072 Element.get(),
5073 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005074 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005075 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005076}
5077
5078
5079template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005080StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005081TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5082 // Transform the exception declaration, if any.
5083 VarDecl *Var = 0;
5084 if (S->getExceptionDecl()) {
5085 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005086 TypeSourceInfo *T = getDerived().TransformType(
5087 ExceptionDecl->getTypeSourceInfo());
5088 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005091 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005092 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005093 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005094 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005095 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005096 }
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregorebe10102009-08-20 07:17:43 +00005098 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005099 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005100 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005101 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005102
Douglas Gregorebe10102009-08-20 07:17:43 +00005103 if (!getDerived().AlwaysRebuild() &&
5104 !Var &&
5105 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005106 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005107
5108 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5109 Var,
John McCallb268a282010-08-23 23:25:46 +00005110 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005111}
Mike Stump11289f42009-09-09 15:08:12 +00005112
Douglas Gregorebe10102009-08-20 07:17:43 +00005113template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005114StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005115TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5116 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005117 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005118 = getDerived().TransformCompoundStmt(S->getTryBlock());
5119 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005120 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005121
Douglas Gregorebe10102009-08-20 07:17:43 +00005122 // Transform the handlers.
5123 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005124 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005125 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005126 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5128 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005129 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregorebe10102009-08-20 07:17:43 +00005131 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5132 Handlers.push_back(Handler.takeAs<Stmt>());
5133 }
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregorebe10102009-08-20 07:17:43 +00005135 if (!getDerived().AlwaysRebuild() &&
5136 TryBlock.get() == S->getTryBlock() &&
5137 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005138 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005139
John McCallb268a282010-08-23 23:25:46 +00005140 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005141 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005142}
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregorebe10102009-08-20 07:17:43 +00005144//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005145// Expression transformation
5146//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005149TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005150 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005151}
Mike Stump11289f42009-09-09 15:08:12 +00005152
5153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005155TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005156 NestedNameSpecifier *Qualifier = 0;
5157 if (E->getQualifier()) {
5158 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005159 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005160 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005162 }
John McCallce546572009-12-08 09:08:17 +00005163
5164 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005165 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5166 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005167 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005169
John McCall815039a2010-08-17 21:27:17 +00005170 DeclarationNameInfo NameInfo = E->getNameInfo();
5171 if (NameInfo.getName()) {
5172 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5173 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005174 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005175 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005176
5177 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005178 Qualifier == E->getQualifier() &&
5179 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005180 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005181 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005182
5183 // Mark it referenced in the new context regardless.
5184 // FIXME: this is a bit instantiation-specific.
5185 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5186
John McCallc3007a22010-10-26 07:05:15 +00005187 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005188 }
John McCallce546572009-12-08 09:08:17 +00005189
5190 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005191 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005192 TemplateArgs = &TransArgs;
5193 TransArgs.setLAngleLoc(E->getLAngleLoc());
5194 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005195 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5196 E->getNumTemplateArgs(),
5197 TransArgs))
5198 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005199 }
5200
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005201 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005202 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005203}
Mike Stump11289f42009-09-09 15:08:12 +00005204
Douglas Gregora16548e2009-08-11 05:31:07 +00005205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005208 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005209}
Mike Stump11289f42009-09-09 15:08:12 +00005210
Douglas Gregora16548e2009-08-11 05:31:07 +00005211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005212ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005213TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005214 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005215}
Mike Stump11289f42009-09-09 15:08:12 +00005216
Douglas Gregora16548e2009-08-11 05:31:07 +00005217template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005218ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005219TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005220 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005221}
Mike Stump11289f42009-09-09 15:08:12 +00005222
Douglas Gregora16548e2009-08-11 05:31:07 +00005223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005225TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005226 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005227}
Mike Stump11289f42009-09-09 15:08:12 +00005228
Douglas Gregora16548e2009-08-11 05:31:07 +00005229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005231TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005232 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005233}
5234
5235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005237TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005238 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005243 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005244
John McCallb268a282010-08-23 23:25:46 +00005245 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 E->getRParen());
5247}
5248
Mike Stump11289f42009-09-09 15:08:12 +00005249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005251TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005252 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005253 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005257 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5260 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005261 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005262}
Mike Stump11289f42009-09-09 15:08:12 +00005263
Douglas Gregora16548e2009-08-11 05:31:07 +00005264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005266TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5267 // Transform the type.
5268 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5269 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Douglas Gregor882211c2010-04-28 22:16:22 +00005272 // Transform all of the components into components similar to what the
5273 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005274 // FIXME: It would be slightly more efficient in the non-dependent case to
5275 // just map FieldDecls, rather than requiring the rebuilder to look for
5276 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005277 // template code that we don't care.
5278 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005279 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005280 typedef OffsetOfExpr::OffsetOfNode Node;
5281 llvm::SmallVector<Component, 4> Components;
5282 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5283 const Node &ON = E->getComponent(I);
5284 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005285 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005286 Comp.LocStart = ON.getRange().getBegin();
5287 Comp.LocEnd = ON.getRange().getEnd();
5288 switch (ON.getKind()) {
5289 case Node::Array: {
5290 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005291 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005292 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005293 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005294
Douglas Gregor882211c2010-04-28 22:16:22 +00005295 ExprChanged = ExprChanged || Index.get() != FromIndex;
5296 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005297 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005298 break;
5299 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005300
Douglas Gregor882211c2010-04-28 22:16:22 +00005301 case Node::Field:
5302 case Node::Identifier:
5303 Comp.isBrackets = false;
5304 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005305 if (!Comp.U.IdentInfo)
5306 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005307
Douglas Gregor882211c2010-04-28 22:16:22 +00005308 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005309
Douglas Gregord1702062010-04-29 00:18:15 +00005310 case Node::Base:
5311 // Will be recomputed during the rebuild.
5312 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005313 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005314
Douglas Gregor882211c2010-04-28 22:16:22 +00005315 Components.push_back(Comp);
5316 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
Douglas Gregor882211c2010-04-28 22:16:22 +00005318 // If nothing changed, retain the existing expression.
5319 if (!getDerived().AlwaysRebuild() &&
5320 Type == E->getTypeSourceInfo() &&
5321 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005322 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregor882211c2010-04-28 22:16:22 +00005324 // Build a new offsetof expression.
5325 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5326 Components.data(), Components.size(),
5327 E->getRParenLoc());
5328}
5329
5330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005331ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005332TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5333 assert(getDerived().AlreadyTransformed(E->getType()) &&
5334 "opaque value expression requires transformation");
5335 return SemaRef.Owned(E);
5336}
5337
5338template<typename Derived>
5339ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005340TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005342 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005343
John McCallbcd03502009-12-07 02:54:59 +00005344 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005345 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall4c98fd82009-11-04 07:28:41 +00005348 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005349 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005350
John McCall4c98fd82009-11-04 07:28:41 +00005351 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005352 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005353 E->getSourceRange());
5354 }
Mike Stump11289f42009-09-09 15:08:12 +00005355
John McCalldadc5752010-08-24 06:29:42 +00005356 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005357 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 // C++0x [expr.sizeof]p1:
5359 // The operand is either an expression, which is an unevaluated operand
5360 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005361 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005362
Douglas Gregora16548e2009-08-11 05:31:07 +00005363 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5364 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregora16548e2009-08-11 05:31:07 +00005367 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005368 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 }
Mike Stump11289f42009-09-09 15:08:12 +00005370
John McCallb268a282010-08-23 23:25:46 +00005371 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 E->isSizeOf(),
5373 E->getSourceRange());
5374}
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregora16548e2009-08-11 05:31:07 +00005376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005378TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005379 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005380 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005381 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005382
John McCalldadc5752010-08-24 06:29:42 +00005383 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005384 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005386
5387
Douglas Gregora16548e2009-08-11 05:31:07 +00005388 if (!getDerived().AlwaysRebuild() &&
5389 LHS.get() == E->getLHS() &&
5390 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005391 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005392
John McCallb268a282010-08-23 23:25:46 +00005393 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005395 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 E->getRBracketLoc());
5397}
Mike Stump11289f42009-09-09 15:08:12 +00005398
5399template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005400ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005401TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005402 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005403 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005405 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005406
5407 // Transform arguments.
5408 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005409 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005410 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5411 &ArgChanged))
5412 return ExprError();
5413
Douglas Gregora16548e2009-08-11 05:31:07 +00005414 if (!getDerived().AlwaysRebuild() &&
5415 Callee.get() == E->getCallee() &&
5416 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005417 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregora16548e2009-08-11 05:31:07 +00005419 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005420 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005421 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005422 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 E->getRParenLoc());
5425}
Mike Stump11289f42009-09-09 15:08:12 +00005426
5427template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005428ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005429TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005430 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005431 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005434 NestedNameSpecifier *Qualifier = 0;
5435 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005436 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005437 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005438 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005439 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005440 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005441 }
Mike Stump11289f42009-09-09 15:08:12 +00005442
Eli Friedman2cfcef62009-12-04 06:40:45 +00005443 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005444 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5445 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005448
John McCall16df1e52010-03-30 21:47:33 +00005449 NamedDecl *FoundDecl = E->getFoundDecl();
5450 if (FoundDecl == E->getMemberDecl()) {
5451 FoundDecl = Member;
5452 } else {
5453 FoundDecl = cast_or_null<NamedDecl>(
5454 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5455 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005456 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005457 }
5458
Douglas Gregora16548e2009-08-11 05:31:07 +00005459 if (!getDerived().AlwaysRebuild() &&
5460 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005461 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005462 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005463 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005464 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005465
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005466 // Mark it referenced in the new context regardless.
5467 // FIXME: this is a bit instantiation-specific.
5468 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005469 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005470 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005471
John McCall6b51f282009-11-23 01:53:49 +00005472 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005473 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005474 TransArgs.setLAngleLoc(E->getLAngleLoc());
5475 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005476 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5477 E->getNumTemplateArgs(),
5478 TransArgs))
5479 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005480 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005481
Douglas Gregora16548e2009-08-11 05:31:07 +00005482 // FIXME: Bogus source location for the operator
5483 SourceLocation FakeOperatorLoc
5484 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5485
John McCall38836f02010-01-15 08:34:02 +00005486 // FIXME: to do this check properly, we will need to preserve the
5487 // first-qualifier-in-scope here, just in case we had a dependent
5488 // base (and therefore couldn't do the check) and a
5489 // nested-name-qualifier (and therefore could do the lookup).
5490 NamedDecl *FirstQualifierInScope = 0;
5491
John McCallb268a282010-08-23 23:25:46 +00005492 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005493 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005494 Qualifier,
5495 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005496 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005497 Member,
John McCall16df1e52010-03-30 21:47:33 +00005498 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005499 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005500 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005501 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005502}
Mike Stump11289f42009-09-09 15:08:12 +00005503
Douglas Gregora16548e2009-08-11 05:31:07 +00005504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005505ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005506TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005507 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005510
John McCalldadc5752010-08-24 06:29:42 +00005511 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregora16548e2009-08-11 05:31:07 +00005515 if (!getDerived().AlwaysRebuild() &&
5516 LHS.get() == E->getLHS() &&
5517 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005518 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005521 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005522}
5523
Mike Stump11289f42009-09-09 15:08:12 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005526TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005527 CompoundAssignOperator *E) {
5528 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005529}
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005532ExprResult TreeTransform<Derived>::
5533TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5534 // Just rebuild the common and RHS expressions and see whether we
5535 // get any changes.
5536
5537 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5538 if (commonExpr.isInvalid())
5539 return ExprError();
5540
5541 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5542 if (rhs.isInvalid())
5543 return ExprError();
5544
5545 if (!getDerived().AlwaysRebuild() &&
5546 commonExpr.get() == e->getCommon() &&
5547 rhs.get() == e->getFalseExpr())
5548 return SemaRef.Owned(e);
5549
5550 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5551 e->getQuestionLoc(),
5552 0,
5553 e->getColonLoc(),
5554 rhs.get());
5555}
5556
5557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005559TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005560 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005563
John McCalldadc5752010-08-24 06:29:42 +00005564 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005565 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005566 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
John McCalldadc5752010-08-24 06:29:42 +00005568 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005570 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 if (!getDerived().AlwaysRebuild() &&
5573 Cond.get() == E->getCond() &&
5574 LHS.get() == E->getLHS() &&
5575 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005576 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005577
John McCallb268a282010-08-23 23:25:46 +00005578 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005579 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005580 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005581 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005582 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005583}
Mike Stump11289f42009-09-09 15:08:12 +00005584
5585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005587TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005588 // Implicit casts are eliminated during transformation, since they
5589 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005590 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005591}
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregora16548e2009-08-11 05:31:07 +00005593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005594ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005595TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005596 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5597 if (!Type)
5598 return ExprError();
5599
John McCalldadc5752010-08-24 06:29:42 +00005600 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005601 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005604
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005606 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005607 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005608 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005609
John McCall97513962010-01-15 18:39:57 +00005610 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005611 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005612 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005613 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005614}
Mike Stump11289f42009-09-09 15:08:12 +00005615
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005617ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005618TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005619 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5620 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5621 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005623
John McCalldadc5752010-08-24 06:29:42 +00005624 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005626 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005627
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005629 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005630 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005631 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005632
John McCall5d7aa7f2010-01-19 22:33:45 +00005633 // Note: the expression type doesn't necessarily match the
5634 // type-as-written, but that's okay, because it should always be
5635 // derivable from the initializer.
5636
John McCalle15bbff2010-01-18 19:35:47 +00005637 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005639 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005640}
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregora16548e2009-08-11 05:31:07 +00005642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005644TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregora16548e2009-08-11 05:31:07 +00005649 if (!getDerived().AlwaysRebuild() &&
5650 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005651 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregora16548e2009-08-11 05:31:07 +00005653 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005654 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005656 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 E->getAccessorLoc(),
5658 E->getAccessor());
5659}
Mike Stump11289f42009-09-09 15:08:12 +00005660
Douglas Gregora16548e2009-08-11 05:31:07 +00005661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005663TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005665
John McCall37ad5512010-08-23 06:44:23 +00005666 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005667 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5668 Inits, &InitChanged))
5669 return ExprError();
5670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005672 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005675 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005676}
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregora16548e2009-08-11 05:31:07 +00005678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005680TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregorebe10102009-08-20 07:17:43 +00005683 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005684 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005686 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregorebe10102009-08-20 07:17:43 +00005688 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005689 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005690 bool ExprChanged = false;
5691 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5692 DEnd = E->designators_end();
5693 D != DEnd; ++D) {
5694 if (D->isFieldDesignator()) {
5695 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5696 D->getDotLoc(),
5697 D->getFieldLoc()));
5698 continue;
5699 }
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005702 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
5706 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregora16548e2009-08-11 05:31:07 +00005709 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5710 ArrayExprs.push_back(Index.release());
5711 continue;
5712 }
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005715 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005716 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5717 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005718 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005719
John McCalldadc5752010-08-24 06:29:42 +00005720 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005722 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005723
5724 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 End.get(),
5726 D->getLBracketLoc(),
5727 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregora16548e2009-08-11 05:31:07 +00005729 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5730 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005731
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 ArrayExprs.push_back(Start.release());
5733 ArrayExprs.push_back(End.release());
5734 }
Mike Stump11289f42009-09-09 15:08:12 +00005735
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 if (!getDerived().AlwaysRebuild() &&
5737 Init.get() == E->getInit() &&
5738 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005739 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5742 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005743 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005744}
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005747ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005748TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005749 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005750 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005751
Douglas Gregor3da3c062009-10-28 00:29:27 +00005752 // FIXME: Will we ever have proper type location here? Will we actually
5753 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 QualType T = getDerived().TransformType(E->getType());
5755 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005756 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregora16548e2009-08-11 05:31:07 +00005758 if (!getDerived().AlwaysRebuild() &&
5759 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005760 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregora16548e2009-08-11 05:31:07 +00005762 return getDerived().RebuildImplicitValueInitExpr(T);
5763}
Mike Stump11289f42009-09-09 15:08:12 +00005764
Douglas Gregora16548e2009-08-11 05:31:07 +00005765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005766ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005767TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005768 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5769 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005771
John McCalldadc5752010-08-24 06:29:42 +00005772 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005775
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005777 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005779 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005780
John McCallb268a282010-08-23 23:25:46 +00005781 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005782 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005783}
5784
5785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005787TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005789 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005790 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5791 &ArgumentChanged))
5792 return ExprError();
5793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5795 move_arg(Inits),
5796 E->getRParenLoc());
5797}
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregora16548e2009-08-11 05:31:07 +00005799/// \brief Transform an address-of-label expression.
5800///
5801/// By default, the transformation of an address-of-label expression always
5802/// rebuilds the expression, so that the label identifier can be resolved to
5803/// the corresponding label statement by semantic analysis.
5804template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005805ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005806TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005807 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
5808 E->getLabel());
5809 if (!LD)
5810 return ExprError();
5811
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005813 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00005814}
Mike Stump11289f42009-09-09 15:08:12 +00005815
5816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005817ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005818TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005819 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5821 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005823
Douglas Gregora16548e2009-08-11 05:31:07 +00005824 if (!getDerived().AlwaysRebuild() &&
5825 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005826 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005827
5828 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005829 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 E->getRParenLoc());
5831}
Mike Stump11289f42009-09-09 15:08:12 +00005832
Douglas Gregora16548e2009-08-11 05:31:07 +00005833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005835TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005836 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005839
John McCalldadc5752010-08-24 06:29:42 +00005840 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005842 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005843
John McCalldadc5752010-08-24 06:29:42 +00005844 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005845 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005846 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005847
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 if (!getDerived().AlwaysRebuild() &&
5849 Cond.get() == E->getCond() &&
5850 LHS.get() == E->getLHS() &&
5851 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005852 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregora16548e2009-08-11 05:31:07 +00005854 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005855 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 E->getRParenLoc());
5857}
Mike Stump11289f42009-09-09 15:08:12 +00005858
Douglas Gregora16548e2009-08-11 05:31:07 +00005859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005860ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005861TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005862 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005863}
5864
5865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005867TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005868 switch (E->getOperator()) {
5869 case OO_New:
5870 case OO_Delete:
5871 case OO_Array_New:
5872 case OO_Array_Delete:
5873 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005874 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005875
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005876 case OO_Call: {
5877 // This is a call to an object's operator().
5878 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5879
5880 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005881 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005882 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005883 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005884
5885 // FIXME: Poor location information
5886 SourceLocation FakeLParenLoc
5887 = SemaRef.PP.getLocForEndOfToken(
5888 static_cast<Expr *>(Object.get())->getLocEnd());
5889
5890 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005891 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005892 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5893 Args))
5894 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005895
John McCallb268a282010-08-23 23:25:46 +00005896 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005897 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005898 E->getLocEnd());
5899 }
5900
5901#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5902 case OO_##Name:
5903#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5904#include "clang/Basic/OperatorKinds.def"
5905 case OO_Subscript:
5906 // Handled below.
5907 break;
5908
5909 case OO_Conditional:
5910 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005912
5913 case OO_None:
5914 case NUM_OVERLOADED_OPERATORS:
5915 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005916 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005917 }
5918
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
John McCalldadc5752010-08-24 06:29:42 +00005923 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005925 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005926
John McCalldadc5752010-08-24 06:29:42 +00005927 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 if (E->getNumArgs() == 2) {
5929 Second = getDerived().TransformExpr(E->getArg(1));
5930 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005931 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005932 }
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 if (!getDerived().AlwaysRebuild() &&
5935 Callee.get() == E->getCallee() &&
5936 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005937 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005938 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005939
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5941 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005942 Callee.get(),
5943 First.get(),
5944 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005945}
Mike Stump11289f42009-09-09 15:08:12 +00005946
Douglas Gregora16548e2009-08-11 05:31:07 +00005947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005949TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5950 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005951}
Mike Stump11289f42009-09-09 15:08:12 +00005952
Douglas Gregora16548e2009-08-11 05:31:07 +00005953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005954ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00005955TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
5956 // Transform the callee.
5957 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5958 if (Callee.isInvalid())
5959 return ExprError();
5960
5961 // Transform exec config.
5962 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
5963 if (EC.isInvalid())
5964 return ExprError();
5965
5966 // Transform arguments.
5967 bool ArgChanged = false;
5968 ASTOwningVector<Expr*> Args(SemaRef);
5969 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5970 &ArgChanged))
5971 return ExprError();
5972
5973 if (!getDerived().AlwaysRebuild() &&
5974 Callee.get() == E->getCallee() &&
5975 !ArgChanged)
5976 return SemaRef.Owned(E);
5977
5978 // FIXME: Wrong source location information for the '('.
5979 SourceLocation FakeLParenLoc
5980 = ((Expr *)Callee.get())->getSourceRange().getBegin();
5981 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
5982 move_arg(Args),
5983 E->getRParenLoc(), EC.get());
5984}
5985
5986template<typename Derived>
5987ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005988TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005989 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5990 if (!Type)
5991 return ExprError();
5992
John McCalldadc5752010-08-24 06:29:42 +00005993 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005994 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005995 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005996 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005997
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005999 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006000 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006001 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregora16548e2009-08-11 05:31:07 +00006003 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006004 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006005 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6006 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6007 SourceLocation FakeRParenLoc
6008 = SemaRef.PP.getLocForEndOfToken(
6009 E->getSubExpr()->getSourceRange().getEnd());
6010 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006011 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006012 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006013 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 FakeRAngleLoc,
6015 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006016 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 FakeRParenLoc);
6018}
Mike Stump11289f42009-09-09 15:08:12 +00006019
Douglas Gregora16548e2009-08-11 05:31:07 +00006020template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006021ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006022TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6023 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006024}
Mike Stump11289f42009-09-09 15:08:12 +00006025
6026template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006027ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006028TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6029 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006030}
6031
Douglas Gregora16548e2009-08-11 05:31:07 +00006032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006033ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006034TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006035 CXXReinterpretCastExpr *E) {
6036 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006037}
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregora16548e2009-08-11 05:31:07 +00006039template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006040ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006041TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6042 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006043}
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregora16548e2009-08-11 05:31:07 +00006045template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006046ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006047TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006048 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006049 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6050 if (!Type)
6051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006052
John McCalldadc5752010-08-24 06:29:42 +00006053 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006054 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregora16548e2009-08-11 05:31:07 +00006058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006059 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006060 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006061 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006062
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006063 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006064 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006065 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 E->getRParenLoc());
6067}
Mike Stump11289f42009-09-09 15:08:12 +00006068
Douglas Gregora16548e2009-08-11 05:31:07 +00006069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006072 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006073 TypeSourceInfo *TInfo
6074 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6075 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006077
Douglas Gregora16548e2009-08-11 05:31:07 +00006078 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006079 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006080 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006081
Douglas Gregor9da64192010-04-26 22:37:10 +00006082 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6083 E->getLocStart(),
6084 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 E->getLocEnd());
6086 }
Mike Stump11289f42009-09-09 15:08:12 +00006087
Douglas Gregora16548e2009-08-11 05:31:07 +00006088 // We don't know whether the expression is potentially evaluated until
6089 // after we perform semantic analysis, so the expression is potentially
6090 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006091 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006092 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006093
John McCalldadc5752010-08-24 06:29:42 +00006094 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006095 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006097
Douglas Gregora16548e2009-08-11 05:31:07 +00006098 if (!getDerived().AlwaysRebuild() &&
6099 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006100 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregor9da64192010-04-26 22:37:10 +00006102 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6103 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006104 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 E->getLocEnd());
6106}
6107
6108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006109ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006110TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6111 if (E->isTypeOperand()) {
6112 TypeSourceInfo *TInfo
6113 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6114 if (!TInfo)
6115 return ExprError();
6116
6117 if (!getDerived().AlwaysRebuild() &&
6118 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006119 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006120
6121 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6122 E->getLocStart(),
6123 TInfo,
6124 E->getLocEnd());
6125 }
6126
6127 // We don't know whether the expression is potentially evaluated until
6128 // after we perform semantic analysis, so the expression is potentially
6129 // potentially evaluated.
6130 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6131
6132 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6133 if (SubExpr.isInvalid())
6134 return ExprError();
6135
6136 if (!getDerived().AlwaysRebuild() &&
6137 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006138 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006139
6140 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6141 E->getLocStart(),
6142 SubExpr.get(),
6143 E->getLocEnd());
6144}
6145
6146template<typename Derived>
6147ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006148TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006149 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006150}
Mike Stump11289f42009-09-09 15:08:12 +00006151
Douglas Gregora16548e2009-08-11 05:31:07 +00006152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006153ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006154TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006155 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006156 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006157}
Mike Stump11289f42009-09-09 15:08:12 +00006158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006162 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6163 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6164 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006166 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006168
Douglas Gregorb15af892010-01-07 23:12:05 +00006169 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006170}
Mike Stump11289f42009-09-09 15:08:12 +00006171
Douglas Gregora16548e2009-08-11 05:31:07 +00006172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006174TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006175 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006177 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006178
Douglas Gregora16548e2009-08-11 05:31:07 +00006179 if (!getDerived().AlwaysRebuild() &&
6180 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006181 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006182
John McCallb268a282010-08-23 23:25:46 +00006183 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006184}
Mike Stump11289f42009-09-09 15:08:12 +00006185
Douglas Gregora16548e2009-08-11 05:31:07 +00006186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006189 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006190 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6191 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006192 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006194
Chandler Carruth794da4c2010-02-08 06:42:49 +00006195 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006196 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006197 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006198
Douglas Gregor033f6752009-12-23 23:03:06 +00006199 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006200}
Mike Stump11289f42009-09-09 15:08:12 +00006201
Douglas Gregora16548e2009-08-11 05:31:07 +00006202template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006203ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006204TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6205 CXXScalarValueInitExpr *E) {
6206 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6207 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006209
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006211 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006212 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006213
Douglas Gregor2b88c112010-09-08 00:15:04 +00006214 return getDerived().RebuildCXXScalarValueInitExpr(T,
6215 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006216 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006217}
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregora16548e2009-08-11 05:31:07 +00006219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006220ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006221TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006222 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006223 TypeSourceInfo *AllocTypeInfo
6224 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6225 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006227
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006229 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006230 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006232
Douglas Gregora16548e2009-08-11 05:31:07 +00006233 // Transform the placement arguments (if any).
6234 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006235 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006236 if (getDerived().TransformExprs(E->getPlacementArgs(),
6237 E->getNumPlacementArgs(), true,
6238 PlacementArgs, &ArgumentChanged))
6239 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006240
Douglas Gregorebe10102009-08-20 07:17:43 +00006241 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006242 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006243 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6244 ConstructorArgs, &ArgumentChanged))
6245 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006246
Douglas Gregord2d9da02010-02-26 00:38:10 +00006247 // Transform constructor, new operator, and delete operator.
6248 CXXConstructorDecl *Constructor = 0;
6249 if (E->getConstructor()) {
6250 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006251 getDerived().TransformDecl(E->getLocStart(),
6252 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006253 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006254 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006255 }
6256
6257 FunctionDecl *OperatorNew = 0;
6258 if (E->getOperatorNew()) {
6259 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006260 getDerived().TransformDecl(E->getLocStart(),
6261 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006262 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006263 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006264 }
6265
6266 FunctionDecl *OperatorDelete = 0;
6267 if (E->getOperatorDelete()) {
6268 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006269 getDerived().TransformDecl(E->getLocStart(),
6270 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006271 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006272 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006273 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006274
Douglas Gregora16548e2009-08-11 05:31:07 +00006275 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006276 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006277 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006278 Constructor == E->getConstructor() &&
6279 OperatorNew == E->getOperatorNew() &&
6280 OperatorDelete == E->getOperatorDelete() &&
6281 !ArgumentChanged) {
6282 // Mark any declarations we need as referenced.
6283 // FIXME: instantiation-specific.
6284 if (Constructor)
6285 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6286 if (OperatorNew)
6287 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6288 if (OperatorDelete)
6289 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006290 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006291 }
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregor0744ef62010-09-07 21:49:58 +00006293 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006294 if (!ArraySize.get()) {
6295 // If no array size was specified, but the new expression was
6296 // instantiated with an array type (e.g., "new T" where T is
6297 // instantiated with "int[4]"), extract the outer bound from the
6298 // array type as our array size. We do this with constant and
6299 // dependently-sized array types.
6300 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6301 if (!ArrayT) {
6302 // Do nothing
6303 } else if (const ConstantArrayType *ConsArrayT
6304 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006305 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006306 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6307 ConsArrayT->getSize(),
6308 SemaRef.Context.getSizeType(),
6309 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006310 AllocType = ConsArrayT->getElementType();
6311 } else if (const DependentSizedArrayType *DepArrayT
6312 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6313 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006314 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006315 AllocType = DepArrayT->getElementType();
6316 }
6317 }
6318 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006319
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6321 E->isGlobalNew(),
6322 /*FIXME:*/E->getLocStart(),
6323 move_arg(PlacementArgs),
6324 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006325 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006326 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006327 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006328 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006329 /*FIXME:*/E->getLocStart(),
6330 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006331 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006332}
Mike Stump11289f42009-09-09 15:08:12 +00006333
Douglas Gregora16548e2009-08-11 05:31:07 +00006334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006336TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006337 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006338 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregord2d9da02010-02-26 00:38:10 +00006341 // Transform the delete operator, if known.
6342 FunctionDecl *OperatorDelete = 0;
6343 if (E->getOperatorDelete()) {
6344 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006345 getDerived().TransformDecl(E->getLocStart(),
6346 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006347 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006348 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006349 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006350
Douglas Gregora16548e2009-08-11 05:31:07 +00006351 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006352 Operand.get() == E->getArgument() &&
6353 OperatorDelete == E->getOperatorDelete()) {
6354 // Mark any declarations we need as referenced.
6355 // FIXME: instantiation-specific.
6356 if (OperatorDelete)
6357 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006358
6359 if (!E->getArgument()->isTypeDependent()) {
6360 QualType Destroyed = SemaRef.Context.getBaseElementType(
6361 E->getDestroyedType());
6362 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6363 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6364 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6365 SemaRef.LookupDestructor(Record));
6366 }
6367 }
6368
John McCallc3007a22010-10-26 07:05:15 +00006369 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006370 }
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregora16548e2009-08-11 05:31:07 +00006372 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6373 E->isGlobalDelete(),
6374 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006375 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006376}
Mike Stump11289f42009-09-09 15:08:12 +00006377
Douglas Gregora16548e2009-08-11 05:31:07 +00006378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006379ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006380TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006381 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006382 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006383 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006384 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006385
John McCallba7bf592010-08-24 05:47:05 +00006386 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006387 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006388 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006389 E->getOperatorLoc(),
6390 E->isArrow()? tok::arrow : tok::period,
6391 ObjectTypePtr,
6392 MayBePseudoDestructor);
6393 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006394 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006395
John McCallba7bf592010-08-24 05:47:05 +00006396 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006397 NestedNameSpecifier *Qualifier = E->getQualifier();
6398 if (Qualifier) {
6399 Qualifier
6400 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6401 E->getQualifierRange(),
6402 ObjectType);
6403 if (!Qualifier)
6404 return ExprError();
6405 }
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregor678f90d2010-02-25 01:56:36 +00006407 PseudoDestructorTypeStorage Destroyed;
6408 if (E->getDestroyedTypeInfo()) {
6409 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006410 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6411 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006412 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006413 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006414 Destroyed = DestroyedTypeInfo;
6415 } else if (ObjectType->isDependentType()) {
6416 // We aren't likely to be able to resolve the identifier down to a type
6417 // now anyway, so just retain the identifier.
6418 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6419 E->getDestroyedTypeLoc());
6420 } else {
6421 // Look for a destructor known with the given name.
6422 CXXScopeSpec SS;
6423 if (Qualifier) {
6424 SS.setScopeRep(Qualifier);
6425 SS.setRange(E->getQualifierRange());
6426 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006427
John McCallba7bf592010-08-24 05:47:05 +00006428 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006429 *E->getDestroyedTypeIdentifier(),
6430 E->getDestroyedTypeLoc(),
6431 /*Scope=*/0,
6432 SS, ObjectTypePtr,
6433 false);
6434 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006435 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006436
Douglas Gregor678f90d2010-02-25 01:56:36 +00006437 Destroyed
6438 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6439 E->getDestroyedTypeLoc());
6440 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006441
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006442 TypeSourceInfo *ScopeTypeInfo = 0;
6443 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006444 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006445 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006446 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006447 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006448
John McCallb268a282010-08-23 23:25:46 +00006449 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006450 E->getOperatorLoc(),
6451 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006452 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006453 E->getQualifierRange(),
6454 ScopeTypeInfo,
6455 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006456 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006457 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006458}
Mike Stump11289f42009-09-09 15:08:12 +00006459
Douglas Gregorad8a3362009-09-04 17:36:40 +00006460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006461ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006462TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006463 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006464 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6465
6466 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6467 Sema::LookupOrdinaryName);
6468
6469 // Transform all the decls.
6470 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6471 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006472 NamedDecl *InstD = static_cast<NamedDecl*>(
6473 getDerived().TransformDecl(Old->getNameLoc(),
6474 *I));
John McCall84d87672009-12-10 09:41:52 +00006475 if (!InstD) {
6476 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6477 // This can happen because of dependent hiding.
6478 if (isa<UsingShadowDecl>(*I))
6479 continue;
6480 else
John McCallfaf5fb42010-08-26 23:41:50 +00006481 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006482 }
John McCalle66edc12009-11-24 19:00:30 +00006483
6484 // Expand using declarations.
6485 if (isa<UsingDecl>(InstD)) {
6486 UsingDecl *UD = cast<UsingDecl>(InstD);
6487 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6488 E = UD->shadow_end(); I != E; ++I)
6489 R.addDecl(*I);
6490 continue;
6491 }
6492
6493 R.addDecl(InstD);
6494 }
6495
6496 // Resolve a kind, but don't do any further analysis. If it's
6497 // ambiguous, the callee needs to deal with it.
6498 R.resolveKind();
6499
6500 // Rebuild the nested-name qualifier, if present.
6501 CXXScopeSpec SS;
6502 NestedNameSpecifier *Qualifier = 0;
6503 if (Old->getQualifier()) {
6504 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006505 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006506 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006507 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006508
John McCalle66edc12009-11-24 19:00:30 +00006509 SS.setScopeRep(Qualifier);
6510 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006511 }
6512
Douglas Gregor9262f472010-04-27 18:19:34 +00006513 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006514 CXXRecordDecl *NamingClass
6515 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6516 Old->getNameLoc(),
6517 Old->getNamingClass()));
6518 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006519 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006520
Douglas Gregorda7be082010-04-27 16:10:10 +00006521 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006522 }
6523
6524 // If we have no template arguments, it's a normal declaration name.
6525 if (!Old->hasExplicitTemplateArgs())
6526 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6527
6528 // If we have template arguments, rebuild them, then rebuild the
6529 // templateid expression.
6530 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006531 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6532 Old->getNumTemplateArgs(),
6533 TransArgs))
6534 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006535
6536 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6537 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006538}
Mike Stump11289f42009-09-09 15:08:12 +00006539
Douglas Gregora16548e2009-08-11 05:31:07 +00006540template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006541ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006542TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006543 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6544 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregora16548e2009-08-11 05:31:07 +00006547 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006548 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006549 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006550
Mike Stump11289f42009-09-09 15:08:12 +00006551 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006552 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006553 T,
6554 E->getLocEnd());
6555}
Mike Stump11289f42009-09-09 15:08:12 +00006556
Douglas Gregora16548e2009-08-11 05:31:07 +00006557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006558ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006559TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6560 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6561 if (!LhsT)
6562 return ExprError();
6563
6564 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6565 if (!RhsT)
6566 return ExprError();
6567
6568 if (!getDerived().AlwaysRebuild() &&
6569 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6570 return SemaRef.Owned(E);
6571
6572 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6573 E->getLocStart(),
6574 LhsT, RhsT,
6575 E->getLocEnd());
6576}
6577
6578template<typename Derived>
6579ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006580TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006581 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006583 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006584 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006587
John McCall31f82722010-11-12 08:19:04 +00006588 // TODO: If this is a conversion-function-id, verify that the
6589 // destination type name (if present) resolves the same way after
6590 // instantiation as it did in the local scope.
6591
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006592 DeclarationNameInfo NameInfo
6593 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6594 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006596
John McCalle66edc12009-11-24 19:00:30 +00006597 if (!E->hasExplicitTemplateArgs()) {
6598 if (!getDerived().AlwaysRebuild() &&
6599 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006600 // Note: it is sufficient to compare the Name component of NameInfo:
6601 // if name has not changed, DNLoc has not changed either.
6602 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006603 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006604
John McCalle66edc12009-11-24 19:00:30 +00006605 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6606 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006607 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006608 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006609 }
John McCall6b51f282009-11-23 01:53:49 +00006610
6611 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006612 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6613 E->getNumTemplateArgs(),
6614 TransArgs))
6615 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006616
John McCalle66edc12009-11-24 19:00:30 +00006617 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6618 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006619 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006620 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006621}
6622
6623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006624ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006625TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006626 // CXXConstructExprs are always implicit, so when we have a
6627 // 1-argument construction we just transform that argument.
6628 if (E->getNumArgs() == 1 ||
6629 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6630 return getDerived().TransformExpr(E->getArg(0));
6631
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6633
6634 QualType T = getDerived().TransformType(E->getType());
6635 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006636 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006637
6638 CXXConstructorDecl *Constructor
6639 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006640 getDerived().TransformDecl(E->getLocStart(),
6641 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006642 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006644
Douglas Gregora16548e2009-08-11 05:31:07 +00006645 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006646 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006647 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6648 &ArgumentChanged))
6649 return ExprError();
6650
Douglas Gregora16548e2009-08-11 05:31:07 +00006651 if (!getDerived().AlwaysRebuild() &&
6652 T == E->getType() &&
6653 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006654 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006655 // Mark the constructor as referenced.
6656 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006657 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006658 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006659 }
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregordb121ba2009-12-14 16:27:04 +00006661 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6662 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006663 move_arg(Args),
6664 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006665 E->getConstructionKind(),
6666 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006667}
Mike Stump11289f42009-09-09 15:08:12 +00006668
Douglas Gregora16548e2009-08-11 05:31:07 +00006669/// \brief Transform a C++ temporary-binding expression.
6670///
Douglas Gregor363b1512009-12-24 18:51:59 +00006671/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6672/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006673template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006674ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006675TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006676 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006677}
Mike Stump11289f42009-09-09 15:08:12 +00006678
John McCall5d413782010-12-06 08:20:24 +00006679/// \brief Transform a C++ expression that contains cleanups that should
6680/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006681///
John McCall5d413782010-12-06 08:20:24 +00006682/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006683/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006684template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006685ExprResult
John McCall5d413782010-12-06 08:20:24 +00006686TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006687 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006688}
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregora16548e2009-08-11 05:31:07 +00006690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006692TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006693 CXXTemporaryObjectExpr *E) {
6694 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6695 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregora16548e2009-08-11 05:31:07 +00006698 CXXConstructorDecl *Constructor
6699 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006700 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006701 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006702 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006704
Douglas Gregora16548e2009-08-11 05:31:07 +00006705 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006706 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006708 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6709 &ArgumentChanged))
6710 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006711
Douglas Gregora16548e2009-08-11 05:31:07 +00006712 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006713 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006715 !ArgumentChanged) {
6716 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006717 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006718 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006719 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006720
6721 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6722 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006724 E->getLocEnd());
6725}
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006728ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006729TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006730 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006731 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6732 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregora16548e2009-08-11 05:31:07 +00006735 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006736 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006737 Args.reserve(E->arg_size());
6738 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6739 &ArgumentChanged))
6740 return ExprError();
6741
Douglas Gregora16548e2009-08-11 05:31:07 +00006742 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006743 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006745 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006746
Douglas Gregora16548e2009-08-11 05:31:07 +00006747 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006748 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006749 E->getLParenLoc(),
6750 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006751 E->getRParenLoc());
6752}
Mike Stump11289f42009-09-09 15:08:12 +00006753
Douglas Gregora16548e2009-08-11 05:31:07 +00006754template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006755ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006756TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006757 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006758 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006759 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006760 Expr *OldBase;
6761 QualType BaseType;
6762 QualType ObjectType;
6763 if (!E->isImplicitAccess()) {
6764 OldBase = E->getBase();
6765 Base = getDerived().TransformExpr(OldBase);
6766 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006768
John McCall2d74de92009-12-01 22:10:20 +00006769 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006770 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006771 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006772 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006773 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006774 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006775 ObjectTy,
6776 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006777 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006779
John McCallba7bf592010-08-24 05:47:05 +00006780 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006781 BaseType = ((Expr*) Base.get())->getType();
6782 } else {
6783 OldBase = 0;
6784 BaseType = getDerived().TransformType(E->getBaseType());
6785 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6786 }
Mike Stump11289f42009-09-09 15:08:12 +00006787
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006788 // Transform the first part of the nested-name-specifier that qualifies
6789 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006790 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006791 = getDerived().TransformFirstQualifierInScope(
6792 E->getFirstQualifierFoundInScope(),
6793 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006794
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006795 NestedNameSpecifier *Qualifier = 0;
6796 if (E->getQualifier()) {
6797 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6798 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006799 ObjectType,
6800 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006801 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006802 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006803 }
Mike Stump11289f42009-09-09 15:08:12 +00006804
John McCall31f82722010-11-12 08:19:04 +00006805 // TODO: If this is a conversion-function-id, verify that the
6806 // destination type name (if present) resolves the same way after
6807 // instantiation as it did in the local scope.
6808
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006809 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006810 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006811 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006813
John McCall2d74de92009-12-01 22:10:20 +00006814 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006815 // This is a reference to a member without an explicitly-specified
6816 // template argument list. Optimize for this common case.
6817 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006818 Base.get() == OldBase &&
6819 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006820 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006821 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006822 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006823 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006824
John McCallb268a282010-08-23 23:25:46 +00006825 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006826 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006827 E->isArrow(),
6828 E->getOperatorLoc(),
6829 Qualifier,
6830 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006831 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006832 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006833 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006834 }
6835
John McCall6b51f282009-11-23 01:53:49 +00006836 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006837 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6838 E->getNumTemplateArgs(),
6839 TransArgs))
6840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006841
John McCallb268a282010-08-23 23:25:46 +00006842 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006843 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006844 E->isArrow(),
6845 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006846 Qualifier,
6847 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006848 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006849 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006850 &TransArgs);
6851}
6852
6853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006855TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006856 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006857 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006858 QualType BaseType;
6859 if (!Old->isImplicitAccess()) {
6860 Base = getDerived().TransformExpr(Old->getBase());
6861 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006862 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006863 BaseType = ((Expr*) Base.get())->getType();
6864 } else {
6865 BaseType = getDerived().TransformType(Old->getBaseType());
6866 }
John McCall10eae182009-11-30 22:42:35 +00006867
6868 NestedNameSpecifier *Qualifier = 0;
6869 if (Old->getQualifier()) {
6870 Qualifier
6871 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006872 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006873 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006874 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006875 }
6876
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006877 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006878 Sema::LookupOrdinaryName);
6879
6880 // Transform all the decls.
6881 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6882 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006883 NamedDecl *InstD = static_cast<NamedDecl*>(
6884 getDerived().TransformDecl(Old->getMemberLoc(),
6885 *I));
John McCall84d87672009-12-10 09:41:52 +00006886 if (!InstD) {
6887 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6888 // This can happen because of dependent hiding.
6889 if (isa<UsingShadowDecl>(*I))
6890 continue;
6891 else
John McCallfaf5fb42010-08-26 23:41:50 +00006892 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006893 }
John McCall10eae182009-11-30 22:42:35 +00006894
6895 // Expand using declarations.
6896 if (isa<UsingDecl>(InstD)) {
6897 UsingDecl *UD = cast<UsingDecl>(InstD);
6898 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6899 E = UD->shadow_end(); I != E; ++I)
6900 R.addDecl(*I);
6901 continue;
6902 }
6903
6904 R.addDecl(InstD);
6905 }
6906
6907 R.resolveKind();
6908
Douglas Gregor9262f472010-04-27 18:19:34 +00006909 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006910 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006911 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006912 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006913 Old->getMemberLoc(),
6914 Old->getNamingClass()));
6915 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006916 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006917
Douglas Gregorda7be082010-04-27 16:10:10 +00006918 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006919 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006920
John McCall10eae182009-11-30 22:42:35 +00006921 TemplateArgumentListInfo TransArgs;
6922 if (Old->hasExplicitTemplateArgs()) {
6923 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6924 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006925 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6926 Old->getNumTemplateArgs(),
6927 TransArgs))
6928 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006929 }
John McCall38836f02010-01-15 08:34:02 +00006930
6931 // FIXME: to do this check properly, we will need to preserve the
6932 // first-qualifier-in-scope here, just in case we had a dependent
6933 // base (and therefore couldn't do the check) and a
6934 // nested-name-qualifier (and therefore could do the lookup).
6935 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006936
John McCallb268a282010-08-23 23:25:46 +00006937 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006938 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006939 Old->getOperatorLoc(),
6940 Old->isArrow(),
6941 Qualifier,
6942 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006943 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006944 R,
6945 (Old->hasExplicitTemplateArgs()
6946 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006947}
6948
6949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006950ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006951TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6952 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6953 if (SubExpr.isInvalid())
6954 return ExprError();
6955
6956 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006957 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006958
6959 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6960}
6961
6962template<typename Derived>
6963ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006964TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006965 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6966 if (Pattern.isInvalid())
6967 return ExprError();
6968
6969 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6970 return SemaRef.Owned(E);
6971
Douglas Gregorb8840002011-01-14 21:20:45 +00006972 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
6973 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006974}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006975
6976template<typename Derived>
6977ExprResult
6978TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6979 // If E is not value-dependent, then nothing will change when we transform it.
6980 // Note: This is an instantiation-centric view.
6981 if (!E->isValueDependent())
6982 return SemaRef.Owned(E);
6983
6984 // Note: None of the implementations of TryExpandParameterPacks can ever
6985 // produce a diagnostic when given only a single unexpanded parameter pack,
6986 // so
6987 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6988 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006989 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006990 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006991 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6992 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006993 ShouldExpand, RetainExpansion,
6994 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006995 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006996
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006997 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006998 return SemaRef.Owned(E);
6999
7000 // We now know the length of the parameter pack, so build a new expression
7001 // that stores that length.
7002 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7003 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007004 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007005}
7006
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007007template<typename Derived>
7008ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007009TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7010 SubstNonTypeTemplateParmPackExpr *E) {
7011 // Default behavior is to do nothing with this transformation.
7012 return SemaRef.Owned(E);
7013}
7014
7015template<typename Derived>
7016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007017TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007018 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007019}
7020
Mike Stump11289f42009-09-09 15:08:12 +00007021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007023TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007024 TypeSourceInfo *EncodedTypeInfo
7025 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7026 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregora16548e2009-08-11 05:31:07 +00007029 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007030 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007031 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007032
7033 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007034 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007035 E->getRParenLoc());
7036}
Mike Stump11289f42009-09-09 15:08:12 +00007037
Douglas Gregora16548e2009-08-11 05:31:07 +00007038template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007039ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007040TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007041 // Transform arguments.
7042 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007043 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007044 Args.reserve(E->getNumArgs());
7045 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7046 &ArgChanged))
7047 return ExprError();
7048
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007049 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7050 // Class message: transform the receiver type.
7051 TypeSourceInfo *ReceiverTypeInfo
7052 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7053 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007054 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007055
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007056 // If nothing changed, just retain the existing message send.
7057 if (!getDerived().AlwaysRebuild() &&
7058 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007059 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007060
7061 // Build a new class message send.
7062 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7063 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007064 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007065 E->getMethodDecl(),
7066 E->getLeftLoc(),
7067 move_arg(Args),
7068 E->getRightLoc());
7069 }
7070
7071 // Instance message: transform the receiver
7072 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7073 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007074 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007075 = getDerived().TransformExpr(E->getInstanceReceiver());
7076 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007077 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007078
7079 // If nothing changed, just retain the existing message send.
7080 if (!getDerived().AlwaysRebuild() &&
7081 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007082 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007083
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007084 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007085 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007086 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007087 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007088 E->getMethodDecl(),
7089 E->getLeftLoc(),
7090 move_arg(Args),
7091 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007092}
7093
Mike Stump11289f42009-09-09 15:08:12 +00007094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007096TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007097 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007098}
7099
Mike Stump11289f42009-09-09 15:08:12 +00007100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007102TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007103 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007104}
7105
Mike Stump11289f42009-09-09 15:08:12 +00007106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007107ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007108TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007109 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007110 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007111 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007112 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007113
7114 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007115
Douglas Gregord51d90d2010-04-26 20:11:03 +00007116 // If nothing changed, just retain the existing expression.
7117 if (!getDerived().AlwaysRebuild() &&
7118 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007119 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007120
John McCallb268a282010-08-23 23:25:46 +00007121 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007122 E->getLocation(),
7123 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007124}
7125
Mike Stump11289f42009-09-09 15:08:12 +00007126template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007128TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007129 // 'super' and types never change. Property never changes. Just
7130 // retain the existing expression.
7131 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007132 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007133
Douglas Gregor9faee212010-04-26 20:47:02 +00007134 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007135 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007136 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007137 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007138
Douglas Gregor9faee212010-04-26 20:47:02 +00007139 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007140
Douglas Gregor9faee212010-04-26 20:47:02 +00007141 // If nothing changed, just retain the existing expression.
7142 if (!getDerived().AlwaysRebuild() &&
7143 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007144 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007145
John McCallb7bd14f2010-12-02 01:19:52 +00007146 if (E->isExplicitProperty())
7147 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7148 E->getExplicitProperty(),
7149 E->getLocation());
7150
7151 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7152 E->getType(),
7153 E->getImplicitPropertyGetter(),
7154 E->getImplicitPropertySetter(),
7155 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007156}
7157
Mike Stump11289f42009-09-09 15:08:12 +00007158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007159ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007160TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007161 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007162 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007163 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007164 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007165
Douglas Gregord51d90d2010-04-26 20:11:03 +00007166 // If nothing changed, just retain the existing expression.
7167 if (!getDerived().AlwaysRebuild() &&
7168 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007169 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007170
John McCallb268a282010-08-23 23:25:46 +00007171 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007172 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007173}
7174
Mike Stump11289f42009-09-09 15:08:12 +00007175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007177TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007178 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007179 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007180 SubExprs.reserve(E->getNumSubExprs());
7181 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7182 SubExprs, &ArgumentChanged))
7183 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007184
Douglas Gregora16548e2009-08-11 05:31:07 +00007185 if (!getDerived().AlwaysRebuild() &&
7186 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007187 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007188
Douglas Gregora16548e2009-08-11 05:31:07 +00007189 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7190 move_arg(SubExprs),
7191 E->getRParenLoc());
7192}
7193
Mike Stump11289f42009-09-09 15:08:12 +00007194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007195ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007196TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007197 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007198
John McCall490112f2011-02-04 18:33:18 +00007199 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7200 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7201
7202 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7203 llvm::SmallVector<ParmVarDecl*, 4> params;
7204 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007205
7206 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007207 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7208 oldBlock->param_begin(),
7209 oldBlock->param_size(),
7210 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007211 return true;
John McCall490112f2011-02-04 18:33:18 +00007212
7213 const FunctionType *exprFunctionType = E->getFunctionType();
7214 QualType exprResultType = exprFunctionType->getResultType();
7215 if (!exprResultType.isNull()) {
7216 if (!exprResultType->isDependentType())
7217 blockScope->ReturnType = exprResultType;
7218 else if (exprResultType != getSema().Context.DependentTy)
7219 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007220 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007221
7222 // If the return type has not been determined yet, leave it as a dependent
7223 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007224 if (blockScope->ReturnType.isNull())
7225 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007226
7227 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007228 if (blockScope->ReturnType->isObjCObjectType()) {
7229 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007230 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007231 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007232 return ExprError();
7233 }
John McCall3882ace2011-01-05 12:14:39 +00007234
John McCall490112f2011-02-04 18:33:18 +00007235 QualType functionType = getDerived().RebuildFunctionProtoType(
7236 blockScope->ReturnType,
7237 paramTypes.data(),
7238 paramTypes.size(),
7239 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007240 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007241 exprFunctionType->getExtInfo());
7242 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007243
7244 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007245 if (!params.empty())
7246 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007247
7248 // If the return type wasn't explicitly set, it will have been marked as a
7249 // dependent type (DependentTy); clear out the return type setting so
7250 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007251 if (blockScope->ReturnType == getSema().Context.DependentTy)
7252 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007253
John McCall3882ace2011-01-05 12:14:39 +00007254 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007255 StmtResult body = getDerived().TransformStmt(E->getBody());
7256 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007257 return ExprError();
7258
John McCall490112f2011-02-04 18:33:18 +00007259#ifndef NDEBUG
7260 // In builds with assertions, make sure that we captured everything we
7261 // captured before.
7262
7263 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7264
7265 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7266 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007267 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007268
7269 // Ignore parameter packs.
7270 if (isa<ParmVarDecl>(oldCapture) &&
7271 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7272 continue;
7273
7274 VarDecl *newCapture =
7275 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7276 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007277 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007278 }
7279#endif
7280
7281 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7282 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007283}
7284
Mike Stump11289f42009-09-09 15:08:12 +00007285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007287TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007288 NestedNameSpecifier *Qualifier = 0;
7289
7290 ValueDecl *ND
7291 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7292 E->getDecl()));
7293 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007294 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007295
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007296 if (!getDerived().AlwaysRebuild() &&
7297 ND == E->getDecl()) {
7298 // Mark it referenced in the new context regardless.
7299 // FIXME: this is a bit instantiation-specific.
7300 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7301
John McCallc3007a22010-10-26 07:05:15 +00007302 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007303 }
7304
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007305 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007306 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007307 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007308}
Mike Stump11289f42009-09-09 15:08:12 +00007309
Douglas Gregora16548e2009-08-11 05:31:07 +00007310//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007311// Type reconstruction
7312//===----------------------------------------------------------------------===//
7313
Mike Stump11289f42009-09-09 15:08:12 +00007314template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007315QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7316 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007317 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007318 getDerived().getBaseEntity());
7319}
7320
Mike Stump11289f42009-09-09 15:08:12 +00007321template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007322QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7323 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007324 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007325 getDerived().getBaseEntity());
7326}
7327
Mike Stump11289f42009-09-09 15:08:12 +00007328template<typename Derived>
7329QualType
John McCall70dd5f62009-10-30 00:06:24 +00007330TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7331 bool WrittenAsLValue,
7332 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007333 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007334 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007335}
7336
7337template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007338QualType
John McCall70dd5f62009-10-30 00:06:24 +00007339TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7340 QualType ClassType,
7341 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007342 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007343 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007344}
7345
7346template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007347QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007348TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7349 ArrayType::ArraySizeModifier SizeMod,
7350 const llvm::APInt *Size,
7351 Expr *SizeExpr,
7352 unsigned IndexTypeQuals,
7353 SourceRange BracketsRange) {
7354 if (SizeExpr || !Size)
7355 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7356 IndexTypeQuals, BracketsRange,
7357 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007358
7359 QualType Types[] = {
7360 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7361 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7362 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007363 };
7364 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7365 QualType SizeType;
7366 for (unsigned I = 0; I != NumTypes; ++I)
7367 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7368 SizeType = Types[I];
7369 break;
7370 }
Mike Stump11289f42009-09-09 15:08:12 +00007371
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007372 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7373 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007374 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007375 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007376 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007377}
Mike Stump11289f42009-09-09 15:08:12 +00007378
Douglas Gregord6ff3322009-08-04 16:50:30 +00007379template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007380QualType
7381TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007382 ArrayType::ArraySizeModifier SizeMod,
7383 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007384 unsigned IndexTypeQuals,
7385 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007386 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007387 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007388}
7389
7390template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007391QualType
Mike Stump11289f42009-09-09 15:08:12 +00007392TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007393 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007394 unsigned IndexTypeQuals,
7395 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007396 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007397 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007398}
Mike Stump11289f42009-09-09 15:08:12 +00007399
Douglas Gregord6ff3322009-08-04 16:50:30 +00007400template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007401QualType
7402TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007403 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007404 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007405 unsigned IndexTypeQuals,
7406 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007407 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007408 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007409 IndexTypeQuals, BracketsRange);
7410}
7411
7412template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007413QualType
7414TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007415 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007416 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007417 unsigned IndexTypeQuals,
7418 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007419 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007420 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007421 IndexTypeQuals, BracketsRange);
7422}
7423
7424template<typename Derived>
7425QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007426 unsigned NumElements,
7427 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007428 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007429 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007430}
Mike Stump11289f42009-09-09 15:08:12 +00007431
Douglas Gregord6ff3322009-08-04 16:50:30 +00007432template<typename Derived>
7433QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7434 unsigned NumElements,
7435 SourceLocation AttributeLoc) {
7436 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7437 NumElements, true);
7438 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007439 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7440 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007441 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007442}
Mike Stump11289f42009-09-09 15:08:12 +00007443
Douglas Gregord6ff3322009-08-04 16:50:30 +00007444template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007445QualType
7446TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007447 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007448 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007449 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007450}
Mike Stump11289f42009-09-09 15:08:12 +00007451
Douglas Gregord6ff3322009-08-04 16:50:30 +00007452template<typename Derived>
7453QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007454 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007455 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007456 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007457 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007458 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007459 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007460 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007461 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007462 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007463 getDerived().getBaseEntity(),
7464 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007465}
Mike Stump11289f42009-09-09 15:08:12 +00007466
Douglas Gregord6ff3322009-08-04 16:50:30 +00007467template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007468QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7469 return SemaRef.Context.getFunctionNoProtoType(T);
7470}
7471
7472template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007473QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7474 assert(D && "no decl found");
7475 if (D->isInvalidDecl()) return QualType();
7476
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007477 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007478 TypeDecl *Ty;
7479 if (isa<UsingDecl>(D)) {
7480 UsingDecl *Using = cast<UsingDecl>(D);
7481 assert(Using->isTypeName() &&
7482 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7483
7484 // A valid resolved using typename decl points to exactly one type decl.
7485 assert(++Using->shadow_begin() == Using->shadow_end());
7486 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007487
John McCallb96ec562009-12-04 22:46:56 +00007488 } else {
7489 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7490 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7491 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7492 }
7493
7494 return SemaRef.Context.getTypeDeclType(Ty);
7495}
7496
7497template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007498QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7499 SourceLocation Loc) {
7500 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007501}
7502
7503template<typename Derived>
7504QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7505 return SemaRef.Context.getTypeOfType(Underlying);
7506}
7507
7508template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007509QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7510 SourceLocation Loc) {
7511 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007512}
7513
7514template<typename Derived>
7515QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007516 TemplateName Template,
7517 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007518 const TemplateArgumentListInfo &TemplateArgs) {
7519 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007520}
Mike Stump11289f42009-09-09 15:08:12 +00007521
Douglas Gregor1135c352009-08-06 05:28:30 +00007522template<typename Derived>
7523NestedNameSpecifier *
7524TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7525 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007526 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007527 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007528 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007529 CXXScopeSpec SS;
7530 // FIXME: The source location information is all wrong.
7531 SS.setRange(Range);
7532 SS.setScopeRep(Prefix);
7533 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007534 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007535 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007536 ObjectType,
7537 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007538 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007539}
7540
7541template<typename Derived>
7542NestedNameSpecifier *
7543TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7544 SourceRange Range,
7545 NamespaceDecl *NS) {
7546 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7547}
7548
7549template<typename Derived>
7550NestedNameSpecifier *
7551TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7552 SourceRange Range,
7553 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007554 QualType T) {
7555 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007556 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007557 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007558 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7559 T.getTypePtr());
7560 }
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregor1135c352009-08-06 05:28:30 +00007562 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7563 return 0;
7564}
Mike Stump11289f42009-09-09 15:08:12 +00007565
Douglas Gregor71dc5092009-08-06 06:41:21 +00007566template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007567TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007568TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7569 bool TemplateKW,
7570 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007571 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007572 Template);
7573}
7574
7575template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007576TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007577TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007578 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007579 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007580 QualType ObjectType,
7581 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007582 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007583 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007584 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007585 UnqualifiedId Name;
7586 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007587 Sema::TemplateTy Template;
7588 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7589 /*FIXME:*/getDerived().getBaseLocation(),
7590 SS,
7591 Name,
John McCallba7bf592010-08-24 05:47:05 +00007592 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007593 /*EnteringContext=*/false,
7594 Template);
John McCall31f82722010-11-12 08:19:04 +00007595 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007596}
Mike Stump11289f42009-09-09 15:08:12 +00007597
Douglas Gregora16548e2009-08-11 05:31:07 +00007598template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007599TemplateName
7600TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7601 OverloadedOperatorKind Operator,
7602 QualType ObjectType) {
7603 CXXScopeSpec SS;
7604 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7605 SS.setScopeRep(Qualifier);
7606 UnqualifiedId Name;
7607 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7608 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7609 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007610 Sema::TemplateTy Template;
7611 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007612 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007613 SS,
7614 Name,
John McCallba7bf592010-08-24 05:47:05 +00007615 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007616 /*EnteringContext=*/false,
7617 Template);
7618 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007619}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007620
Douglas Gregor71395fa2009-11-04 00:56:37 +00007621template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007622ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007623TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7624 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007625 Expr *OrigCallee,
7626 Expr *First,
7627 Expr *Second) {
7628 Expr *Callee = OrigCallee->IgnoreParenCasts();
7629 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007630
Douglas Gregora16548e2009-08-11 05:31:07 +00007631 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007632 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007633 if (!First->getType()->isOverloadableType() &&
7634 !Second->getType()->isOverloadableType())
7635 return getSema().CreateBuiltinArraySubscriptExpr(First,
7636 Callee->getLocStart(),
7637 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007638 } else if (Op == OO_Arrow) {
7639 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007640 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7641 } else if (Second == 0 || isPostIncDec) {
7642 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007643 // The argument is not of overloadable type, so try to create a
7644 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007645 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007646 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007647
John McCallb268a282010-08-23 23:25:46 +00007648 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007649 }
7650 } else {
John McCallb268a282010-08-23 23:25:46 +00007651 if (!First->getType()->isOverloadableType() &&
7652 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007653 // Neither of the arguments is an overloadable type, so try to
7654 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007655 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007656 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007657 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007658 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007659 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007660
Douglas Gregora16548e2009-08-11 05:31:07 +00007661 return move(Result);
7662 }
7663 }
Mike Stump11289f42009-09-09 15:08:12 +00007664
7665 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007666 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007667 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007668
John McCallb268a282010-08-23 23:25:46 +00007669 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007670 assert(ULE->requiresADL());
7671
7672 // FIXME: Do we have to check
7673 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007674 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007675 } else {
John McCallb268a282010-08-23 23:25:46 +00007676 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007677 }
Mike Stump11289f42009-09-09 15:08:12 +00007678
Douglas Gregora16548e2009-08-11 05:31:07 +00007679 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007680 Expr *Args[2] = { First, Second };
7681 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007682
Douglas Gregora16548e2009-08-11 05:31:07 +00007683 // Create the overloaded operator invocation for unary operators.
7684 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007685 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007686 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007687 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007688 }
Mike Stump11289f42009-09-09 15:08:12 +00007689
Sebastian Redladba46e2009-10-29 20:17:01 +00007690 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007691 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007692 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007693 First,
7694 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007695
Douglas Gregora16548e2009-08-11 05:31:07 +00007696 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007697 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007698 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007699 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7700 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007701 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007702
Mike Stump11289f42009-09-09 15:08:12 +00007703 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007704}
Mike Stump11289f42009-09-09 15:08:12 +00007705
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007707ExprResult
John McCallb268a282010-08-23 23:25:46 +00007708TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007709 SourceLocation OperatorLoc,
7710 bool isArrow,
7711 NestedNameSpecifier *Qualifier,
7712 SourceRange QualifierRange,
7713 TypeSourceInfo *ScopeType,
7714 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007715 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007716 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007717 CXXScopeSpec SS;
7718 if (Qualifier) {
7719 SS.setRange(QualifierRange);
7720 SS.setScopeRep(Qualifier);
7721 }
7722
John McCallb268a282010-08-23 23:25:46 +00007723 QualType BaseType = Base->getType();
7724 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007725 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007726 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007727 !BaseType->getAs<PointerType>()->getPointeeType()
7728 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007729 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007730 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007731 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007732 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007733 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007734 /*FIXME?*/true);
7735 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007736
Douglas Gregor678f90d2010-02-25 01:56:36 +00007737 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007738 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7739 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7740 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7741 NameInfo.setNamedTypeInfo(DestroyedType);
7742
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007743 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007744
John McCallb268a282010-08-23 23:25:46 +00007745 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007746 OperatorLoc, isArrow,
7747 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007748 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007749 /*TemplateArgs*/ 0);
7750}
7751
Douglas Gregord6ff3322009-08-04 16:50:30 +00007752} // end namespace clang
7753
7754#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H