blob: 944e6a13e113a55038e17abd2e20184ab58f442c [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
Richard Smith30482bc2011-02-20 03:19:35 +0000679 /// \brief Build a new C++0x auto type.
680 ///
681 /// By default, builds a new AutoType with the given deduced type.
682 QualType RebuildAutoType(QualType Deduced) {
683 return SemaRef.Context.getAutoType(Deduced);
684 }
685
Douglas Gregord6ff3322009-08-04 16:50:30 +0000686 /// \brief Build a new template specialization type.
687 ///
688 /// By default, performs semantic analysis when building the template
689 /// specialization type. Subclasses may override this routine to provide
690 /// different behavior.
691 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000692 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000693 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000695 /// \brief Build a new parenthesized type.
696 ///
697 /// By default, builds a new ParenType type from the inner type.
698 /// Subclasses may override this routine to provide different behavior.
699 QualType RebuildParenType(QualType InnerType) {
700 return SemaRef.Context.getParenType(InnerType);
701 }
702
Douglas Gregord6ff3322009-08-04 16:50:30 +0000703 /// \brief Build a new qualified name type.
704 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000705 /// By default, builds a new ElaboratedType type from the keyword,
706 /// the nested-name-specifier and the named type.
707 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000708 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
709 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000710 NestedNameSpecifier *NNS, QualType Named) {
711 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000712 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713
714 /// \brief Build a new typename type that refers to a template-id.
715 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000716 /// By default, builds a new DependentNameType type from the
717 /// nested-name-specifier and the given type. Subclasses may override
718 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000719 QualType RebuildDependentTemplateSpecializationType(
720 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000721 NestedNameSpecifier *Qualifier,
722 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000723 const IdentifierInfo *Name,
724 SourceLocation NameLoc,
725 const TemplateArgumentListInfo &Args) {
726 // Rebuild the template name.
727 // TODO: avoid TemplateName abstraction
728 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000729 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000730 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000731
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000732 if (InstName.isNull())
733 return QualType();
734
John McCallc392f372010-06-11 00:33:02 +0000735 // If it's still dependent, make a dependent specialization.
736 if (InstName.getAsDependentTemplateName())
737 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000738 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000739
740 // Otherwise, make an elaborated type wrapping a non-dependent
741 // specialization.
742 QualType T =
743 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
744 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000745
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000746 // NOTE: NNS is already recorded in template specialization type T.
747 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000748 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000749
750 /// \brief Build a new typename type that refers to an identifier.
751 ///
752 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000753 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000754 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000755 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000756 NestedNameSpecifier *NNS,
757 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000758 SourceLocation KeywordLoc,
759 SourceRange NNSRange,
760 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000761 CXXScopeSpec SS;
762 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000763 SS.setRange(NNSRange);
764
Douglas Gregore677daf2010-03-31 22:19:08 +0000765 if (NNS->isDependent()) {
766 // If the name is still dependent, just build a new dependent name type.
767 if (!SemaRef.computeDeclContext(SS))
768 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
769 }
770
Abramo Bagnara6150c882010-05-11 21:36:43 +0000771 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000772 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
773 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000774
775 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
776
Abramo Bagnarad7548482010-05-19 21:37:53 +0000777 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000778 // into a non-dependent elaborated-type-specifier. Find the tag we're
779 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000780 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000781 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
782 if (!DC)
783 return QualType();
784
John McCallbf8c5192010-05-27 06:40:31 +0000785 if (SemaRef.RequireCompleteDeclContext(SS, DC))
786 return QualType();
787
Douglas Gregore677daf2010-03-31 22:19:08 +0000788 TagDecl *Tag = 0;
789 SemaRef.LookupQualifiedName(Result, DC);
790 switch (Result.getResultKind()) {
791 case LookupResult::NotFound:
792 case LookupResult::NotFoundInCurrentInstantiation:
793 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000794
Douglas Gregore677daf2010-03-31 22:19:08 +0000795 case LookupResult::Found:
796 Tag = Result.getAsSingle<TagDecl>();
797 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000798
Douglas Gregore677daf2010-03-31 22:19:08 +0000799 case LookupResult::FoundOverloaded:
800 case LookupResult::FoundUnresolvedValue:
801 llvm_unreachable("Tag lookup cannot find non-tags");
802 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000803
Douglas Gregore677daf2010-03-31 22:19:08 +0000804 case LookupResult::Ambiguous:
805 // Let the LookupResult structure handle ambiguities.
806 return QualType();
807 }
808
809 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000810 // Check where the name exists but isn't a tag type and use that to emit
811 // better diagnostics.
812 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
813 SemaRef.LookupQualifiedName(Result, DC);
814 switch (Result.getResultKind()) {
815 case LookupResult::Found:
816 case LookupResult::FoundOverloaded:
817 case LookupResult::FoundUnresolvedValue: {
818 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
819 unsigned Kind = 0;
820 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
821 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
822 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
823 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
824 break;
825 }
826 default:
827 // FIXME: Would be nice to highlight just the source range.
828 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
829 << Kind << Id << DC;
830 break;
831 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000832 return QualType();
833 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000834
Abramo Bagnarad7548482010-05-19 21:37:53 +0000835 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
836 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000837 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
838 return QualType();
839 }
840
841 // Build the elaborated-type-specifier type.
842 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000843 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000844 }
Mike Stump11289f42009-09-09 15:08:12 +0000845
Douglas Gregor822d0302011-01-12 17:07:58 +0000846 /// \brief Build a new pack expansion type.
847 ///
848 /// By default, builds a new PackExpansionType type from the given pattern.
849 /// Subclasses may override this routine to provide different behavior.
850 QualType RebuildPackExpansionType(QualType Pattern,
851 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000852 SourceLocation EllipsisLoc,
853 llvm::Optional<unsigned> NumExpansions) {
854 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
855 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000856 }
857
Douglas Gregor1135c352009-08-06 05:28:30 +0000858 /// \brief Build a new nested-name-specifier given the prefix and an
859 /// identifier that names the next step in the nested-name-specifier.
860 ///
861 /// By default, performs semantic analysis when building the new
862 /// nested-name-specifier. Subclasses may override this routine to provide
863 /// different behavior.
864 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
865 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000866 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000867 QualType ObjectType,
868 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000869
870 /// \brief Build a new nested-name-specifier given the prefix and the
871 /// namespace named in the next step in the nested-name-specifier.
872 ///
873 /// By default, performs semantic analysis when building the new
874 /// nested-name-specifier. Subclasses may override this routine to provide
875 /// different behavior.
876 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
877 SourceRange Range,
878 NamespaceDecl *NS);
879
880 /// \brief Build a new nested-name-specifier given the prefix and the
881 /// type named in the next step in the nested-name-specifier.
882 ///
883 /// By default, performs semantic analysis when building the new
884 /// nested-name-specifier. Subclasses may override this routine to provide
885 /// different behavior.
886 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
887 SourceRange Range,
888 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000889 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000890
891 /// \brief Build a new template name given a nested name specifier, a flag
892 /// indicating whether the "template" keyword was provided, and the template
893 /// that the template name refers to.
894 ///
895 /// By default, builds the new template name directly. Subclasses may override
896 /// this routine to provide different behavior.
897 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
898 bool TemplateKW,
899 TemplateDecl *Template);
900
Douglas Gregor71dc5092009-08-06 06:41:21 +0000901 /// \brief Build a new template name given a nested name specifier and the
902 /// name that is referred to as a template.
903 ///
904 /// By default, performs semantic analysis to determine whether the name can
905 /// be resolved to a specific template, then builds the appropriate kind of
906 /// template name. Subclasses may override this routine to provide different
907 /// behavior.
908 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000909 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000910 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000911 QualType ObjectType,
912 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000913
Douglas Gregor71395fa2009-11-04 00:56:37 +0000914 /// \brief Build a new template name given a nested name specifier and the
915 /// overloaded operator name that is referred to as a template.
916 ///
917 /// By default, performs semantic analysis to determine whether the name can
918 /// be resolved to a specific template, then builds the appropriate kind of
919 /// template name. Subclasses may override this routine to provide different
920 /// behavior.
921 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
922 OverloadedOperatorKind Operator,
923 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000924
925 /// \brief Build a new template name given a template template parameter pack
926 /// and the
927 ///
928 /// By default, performs semantic analysis to determine whether the name can
929 /// be resolved to a specific template, then builds the appropriate kind of
930 /// template name. Subclasses may override this routine to provide different
931 /// behavior.
932 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
933 const TemplateArgument &ArgPack) {
934 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
935 }
936
Douglas Gregorebe10102009-08-20 07:17:43 +0000937 /// \brief Build a new compound statement.
938 ///
939 /// By default, performs semantic analysis to build the new statement.
940 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000941 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000942 MultiStmtArg Statements,
943 SourceLocation RBraceLoc,
944 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000945 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000946 IsStmtExpr);
947 }
948
949 /// \brief Build a new case statement.
950 ///
951 /// By default, performs semantic analysis to build the new statement.
952 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000953 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000954 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000956 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000958 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000959 ColonLoc);
960 }
Mike Stump11289f42009-09-09 15:08:12 +0000961
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 /// \brief Attach the body to a new case statement.
963 ///
964 /// By default, performs semantic analysis to build the new statement.
965 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000966 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000967 getSema().ActOnCaseStmtBody(S, Body);
968 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000969 }
Mike Stump11289f42009-09-09 15:08:12 +0000970
Douglas Gregorebe10102009-08-20 07:17:43 +0000971 /// \brief Build a new default statement.
972 ///
973 /// By default, performs semantic analysis to build the new statement.
974 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000975 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000976 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000977 Stmt *SubStmt) {
978 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 /*CurScope=*/0);
980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 /// \brief Build a new label statement.
983 ///
984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +0000986 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
987 SourceLocation ColonLoc, Stmt *SubStmt) {
988 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 }
Mike Stump11289f42009-09-09 15:08:12 +0000990
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 /// \brief Build a new "if" statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000995 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +0000996 VarDecl *CondVar, Stmt *Then,
997 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000998 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Douglas Gregorebe10102009-08-20 07:17:43 +00001001 /// \brief Start building a new switch statement.
1002 ///
1003 /// By default, performs semantic analysis to build the new statement.
1004 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001005 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001006 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001007 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001008 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 /// \brief Attach the body to the switch statement.
1012 ///
1013 /// By default, performs semantic analysis to build the new statement.
1014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001015 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001016 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001017 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001018 }
1019
1020 /// \brief Build a new while statement.
1021 ///
1022 /// By default, performs semantic analysis to build the new statement.
1023 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001024 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1025 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001026 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /// \brief Build a new do-while statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001034 SourceLocation WhileLoc, SourceLocation LParenLoc,
1035 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001036 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1037 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001038 }
1039
1040 /// \brief Build a new for statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001044 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1045 Stmt *Init, Sema::FullExprArg Cond,
1046 VarDecl *CondVar, Sema::FullExprArg Inc,
1047 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001048 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001049 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001050 }
Mike Stump11289f42009-09-09 15:08:12 +00001051
Douglas Gregorebe10102009-08-20 07:17:43 +00001052 /// \brief Build a new goto statement.
1053 ///
1054 /// By default, performs semantic analysis to build the new statement.
1055 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001056 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1057 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001058 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001059 }
1060
1061 /// \brief Build a new indirect goto statement.
1062 ///
1063 /// By default, performs semantic analysis to build the new statement.
1064 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001065 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001066 SourceLocation StarLoc,
1067 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001068 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001069 }
Mike Stump11289f42009-09-09 15:08:12 +00001070
Douglas Gregorebe10102009-08-20 07:17:43 +00001071 /// \brief Build a new return statement.
1072 ///
1073 /// By default, performs semantic analysis to build the new statement.
1074 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001075 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001076 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 /// \brief Build a new declaration statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001083 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001084 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001085 SourceLocation EndLoc) {
1086 return getSema().Owned(
1087 new (getSema().Context) DeclStmt(
1088 DeclGroupRef::Create(getSema().Context,
1089 Decls, NumDecls),
1090 StartLoc, EndLoc));
1091 }
Mike Stump11289f42009-09-09 15:08:12 +00001092
Anders Carlssonaaeef072010-01-24 05:50:09 +00001093 /// \brief Build a new inline asm statement.
1094 ///
1095 /// By default, performs semantic analysis to build the new statement.
1096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001097 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001098 bool IsSimple,
1099 bool IsVolatile,
1100 unsigned NumOutputs,
1101 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001102 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001103 MultiExprArg Constraints,
1104 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001105 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001106 MultiExprArg Clobbers,
1107 SourceLocation RParenLoc,
1108 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001109 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001110 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001111 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001112 RParenLoc, MSAsm);
1113 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001114
1115 /// \brief Build a new Objective-C @try statement.
1116 ///
1117 /// By default, performs semantic analysis to build the new statement.
1118 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001119 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001120 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001121 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001122 Stmt *Finally) {
1123 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1124 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001125 }
1126
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001127 /// \brief Rebuild an Objective-C exception declaration.
1128 ///
1129 /// By default, performs semantic analysis to build the new declaration.
1130 /// Subclasses may override this routine to provide different behavior.
1131 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1132 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001133 return getSema().BuildObjCExceptionDecl(TInfo, T,
1134 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001135 ExceptionDecl->getLocation());
1136 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001137
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001138 /// \brief Build a new Objective-C @catch statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001142 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001143 SourceLocation RParenLoc,
1144 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001145 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001146 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001147 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001148 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001149
Douglas Gregor306de2f2010-04-22 23:59:56 +00001150 /// \brief Build a new Objective-C @finally statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001154 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001155 Stmt *Body) {
1156 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001158
Douglas Gregor6148de72010-04-22 22:01:21 +00001159 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001160 ///
1161 /// By default, performs semantic analysis to build the new statement.
1162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001163 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001164 Expr *Operand) {
1165 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001166 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001167
Douglas Gregor6148de72010-04-22 22:01:21 +00001168 /// \brief Build a new Objective-C @synchronized statement.
1169 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001172 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001173 Expr *Object,
1174 Stmt *Body) {
1175 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1176 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001177 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001178
1179 /// \brief Build a new Objective-C fast enumeration statement.
1180 ///
1181 /// By default, performs semantic analysis to build the new statement.
1182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001183 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001184 SourceLocation LParenLoc,
1185 Stmt *Element,
1186 Expr *Collection,
1187 SourceLocation RParenLoc,
1188 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001189 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001190 Element,
1191 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001192 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001193 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001194 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001195
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 /// \brief Build a new C++ exception declaration.
1197 ///
1198 /// By default, performs semantic analysis to build the new decaration.
1199 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001200 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001201 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001203 SourceLocation Loc) {
1204 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001205 }
1206
1207 /// \brief Build a new C++ catch statement.
1208 ///
1209 /// By default, performs semantic analysis to build the new statement.
1210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001211 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001212 VarDecl *ExceptionDecl,
1213 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001214 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1215 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001216 }
Mike Stump11289f42009-09-09 15:08:12 +00001217
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 /// \brief Build a new C++ try statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001222 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001223 Stmt *TryBlock,
1224 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001225 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 }
Mike Stump11289f42009-09-09 15:08:12 +00001227
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 /// \brief Build a new expression that references a declaration.
1229 ///
1230 /// By default, performs semantic analysis to build the new expression.
1231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001232 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001233 LookupResult &R,
1234 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001235 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1236 }
1237
1238
1239 /// \brief Build a new expression that references a declaration.
1240 ///
1241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001243 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001244 SourceRange QualifierRange,
1245 ValueDecl *VD,
1246 const DeclarationNameInfo &NameInfo,
1247 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001248 CXXScopeSpec SS;
1249 SS.setScopeRep(Qualifier);
1250 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001251
1252 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001253
1254 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 }
Mike Stump11289f42009-09-09 15:08:12 +00001256
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001258 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// By default, performs semantic analysis to build the new expression.
1260 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001261 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001263 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 }
1265
Douglas Gregorad8a3362009-09-04 17:36:40 +00001266 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001267 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001268 /// By default, performs semantic analysis to build the new expression.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001271 SourceLocation OperatorLoc,
1272 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001273 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001274 SourceRange QualifierRange,
1275 TypeSourceInfo *ScopeType,
1276 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001277 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001278 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001279
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001281 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001284 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001285 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001286 Expr *SubExpr) {
1287 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 }
Mike Stump11289f42009-09-09 15:08:12 +00001289
Douglas Gregor882211c2010-04-28 22:16:22 +00001290 /// \brief Build a new builtin offsetof expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001295 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001296 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001297 unsigned NumComponents,
1298 SourceLocation RParenLoc) {
1299 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1300 NumComponents, RParenLoc);
1301 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001302
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001304 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// By default, performs semantic analysis to build the new expression.
1306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001307 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001308 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001310 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 }
1312
Mike Stump11289f42009-09-09 15:08:12 +00001313 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001320 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001321 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001323 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 return move(Result);
1326 }
Mike Stump11289f42009-09-09 15:08:12 +00001327
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001329 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// By default, performs semantic analysis to build the new expression.
1331 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001332 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001334 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001336 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1337 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 RBracketLoc);
1339 }
1340
1341 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001345 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001347 SourceLocation RParenLoc,
1348 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001349 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001350 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 }
1352
1353 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001354 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001357 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001358 bool isArrow,
1359 NestedNameSpecifier *Qualifier,
1360 SourceRange QualifierRange,
1361 const DeclarationNameInfo &MemberNameInfo,
1362 ValueDecl *Member,
1363 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001364 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001365 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001366 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001367 // We have a reference to an unnamed field. This is always the
1368 // base of an anonymous struct/union member access, i.e. the
1369 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001370 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001371 assert(Member->getType()->isRecordType() &&
1372 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001373
John McCallb268a282010-08-23 23:25:46 +00001374 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001375 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001376 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001377
John McCall7decc9e2010-11-18 06:31:45 +00001378 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001379 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001380 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001381 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001382 cast<FieldDecl>(Member)->getType(),
1383 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001384 return getSema().Owned(ME);
1385 }
Mike Stump11289f42009-09-09 15:08:12 +00001386
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001387 CXXScopeSpec SS;
1388 if (Qualifier) {
1389 SS.setRange(QualifierRange);
1390 SS.setScopeRep(Qualifier);
1391 }
1392
John McCallb268a282010-08-23 23:25:46 +00001393 getSema().DefaultFunctionArrayConversion(Base);
1394 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001395
John McCall16df1e52010-03-30 21:47:33 +00001396 // FIXME: this involves duplicating earlier analysis in a lot of
1397 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001398 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001399 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001400 R.resolveKind();
1401
John McCallb268a282010-08-23 23:25:46 +00001402 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001403 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001404 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 }
Mike Stump11289f42009-09-09 15:08:12 +00001406
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001408 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001411 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001412 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001413 Expr *LHS, Expr *RHS) {
1414 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 }
1416
1417 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001418 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001421 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001422 SourceLocation QuestionLoc,
1423 Expr *LHS,
1424 SourceLocation ColonLoc,
1425 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001426 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1427 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 }
1429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001431 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001434 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001435 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001437 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001438 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001439 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 }
Mike Stump11289f42009-09-09 15:08:12 +00001441
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001443 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// By default, performs semantic analysis to build the new expression.
1445 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001446 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001447 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001449 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001450 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 }
Mike Stump11289f42009-09-09 15:08:12 +00001453
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001455 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001458 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 SourceLocation OpLoc,
1460 SourceLocation AccessorLoc,
1461 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001462
John McCall10eae182009-11-30 22:42:35 +00001463 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001464 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001465 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001466 OpLoc, /*IsArrow*/ false,
1467 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001468 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001469 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
Mike Stump11289f42009-09-09 15:08:12 +00001471
Douglas Gregora16548e2009-08-11 05:31:07 +00001472 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001473 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 SourceLocation RBraceLoc,
1479 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001480 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001481 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1482 if (Result.isInvalid() || ResultTy->isDependentType())
1483 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001484
Douglas Gregord3d93062009-11-09 17:16:50 +00001485 // Patch in the result type we were given, which may have been computed
1486 // when the initial InitListExpr was built.
1487 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1488 ILE->setType(ResultTy);
1489 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001490 }
Mike Stump11289f42009-09-09 15:08:12 +00001491
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001493 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001496 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 MultiExprArg ArrayExprs,
1498 SourceLocation EqualOrColonLoc,
1499 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001500 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001501 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001503 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001506
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 ArrayExprs.release();
1508 return move(Result);
1509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001512 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001513 /// By default, builds the implicit value initialization without performing
1514 /// any semantic analysis. Subclasses may override this routine to provide
1515 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001516 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001521 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001524 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001526 SourceLocation RParenLoc) {
1527 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001529 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
1531
1532 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001533 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001536 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 MultiExprArg SubExprs,
1538 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001539 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001540 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
1545 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001546 /// rather than attempting to map the label statement itself.
1547 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001548 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001549 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001550 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 }
Mike Stump11289f42009-09-09 15:08:12 +00001552
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001554 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001557 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001558 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001560 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 }
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// \brief Build a new __builtin_choose_expr expression.
1564 ///
1565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001567 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001568 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 SourceLocation RParenLoc) {
1570 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001571 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 RParenLoc);
1573 }
Mike Stump11289f42009-09-09 15:08:12 +00001574
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// \brief Build a new overloaded operator call expression.
1576 ///
1577 /// By default, performs semantic analysis to build the new expression.
1578 /// The semantic analysis provides the behavior of template instantiation,
1579 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001580 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// argument-dependent lookup, etc. Subclasses may override this routine to
1582 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001583 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001584 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001585 Expr *Callee,
1586 Expr *First,
1587 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001588
1589 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 /// reinterpret_cast.
1591 ///
1592 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001593 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001595 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 Stmt::StmtClass Class,
1597 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001598 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 SourceLocation RAngleLoc,
1600 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001601 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 SourceLocation RParenLoc) {
1603 switch (Class) {
1604 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001605 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001606 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001607 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001608
1609 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001610 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001611 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001612 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001613
Douglas Gregora16548e2009-08-11 05:31:07 +00001614 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001615 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001616 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001619
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001621 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001622 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001623 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001624
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 default:
1626 assert(false && "Invalid C++ named cast");
1627 break;
1628 }
Mike Stump11289f42009-09-09 15:08:12 +00001629
John McCallfaf5fb42010-08-26 23:41:50 +00001630 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 }
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 /// \brief Build a new C++ static_cast expression.
1634 ///
1635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001637 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001639 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RAngleLoc,
1641 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001642 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001644 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001645 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001646 SourceRange(LAngleLoc, RAngleLoc),
1647 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 }
1649
1650 /// \brief Build a new C++ dynamic_cast expression.
1651 ///
1652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001654 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001656 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation RAngleLoc,
1658 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001659 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001661 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001662 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001663 SourceRange(LAngleLoc, RAngleLoc),
1664 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
1667 /// \brief Build a new C++ reinterpret_cast expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001671 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001673 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation RAngleLoc,
1675 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001676 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001678 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001679 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001680 SourceRange(LAngleLoc, RAngleLoc),
1681 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 }
1683
1684 /// \brief Build a new C++ const_cast expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001690 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RAngleLoc,
1692 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001693 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001695 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001696 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001697 SourceRange(LAngleLoc, RAngleLoc),
1698 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 }
Mike Stump11289f42009-09-09 15:08:12 +00001700
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 /// \brief Build a new C++ functional-style cast expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001705 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1706 SourceLocation LParenLoc,
1707 Expr *Sub,
1708 SourceLocation RParenLoc) {
1709 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001710 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 RParenLoc);
1712 }
Mike Stump11289f42009-09-09 15:08:12 +00001713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 /// \brief Build a new C++ typeid(type) expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001718 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001719 SourceLocation TypeidLoc,
1720 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001722 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001723 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 }
Mike Stump11289f42009-09-09 15:08:12 +00001725
Francois Pichet9f4f2072010-09-08 12:20:18 +00001726
Douglas Gregora16548e2009-08-11 05:31:07 +00001727 /// \brief Build a new C++ typeid(expr) expression.
1728 ///
1729 /// By default, performs semantic analysis to build the new expression.
1730 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001731 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001732 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001733 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001735 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001736 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001737 }
1738
Francois Pichet9f4f2072010-09-08 12:20:18 +00001739 /// \brief Build a new C++ __uuidof(type) expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
1743 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1744 SourceLocation TypeidLoc,
1745 TypeSourceInfo *Operand,
1746 SourceLocation RParenLoc) {
1747 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1748 RParenLoc);
1749 }
1750
1751 /// \brief Build a new C++ __uuidof(expr) expression.
1752 ///
1753 /// By default, performs semantic analysis to build the new expression.
1754 /// Subclasses may override this routine to provide different behavior.
1755 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1756 SourceLocation TypeidLoc,
1757 Expr *Operand,
1758 SourceLocation RParenLoc) {
1759 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1760 RParenLoc);
1761 }
1762
Douglas Gregora16548e2009-08-11 05:31:07 +00001763 /// \brief Build a new C++ "this" expression.
1764 ///
1765 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001766 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001768 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001769 QualType ThisType,
1770 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001772 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1773 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 }
1775
1776 /// \brief Build a new C++ throw expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001780 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001781 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 }
1783
1784 /// \brief Build a new C++ default-argument expression.
1785 ///
1786 /// By default, builds a new default-argument expression, which does not
1787 /// require any semantic analysis. Subclasses may override this routine to
1788 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001789 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001790 ParmVarDecl *Param) {
1791 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1792 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 }
1794
1795 /// \brief Build a new C++ zero-initialization expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001799 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1800 SourceLocation LParenLoc,
1801 SourceLocation RParenLoc) {
1802 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001803 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001804 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 }
Mike Stump11289f42009-09-09 15:08:12 +00001806
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 /// \brief Build a new C++ "new" expression.
1808 ///
1809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001811 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001812 bool UseGlobal,
1813 SourceLocation PlacementLParen,
1814 MultiExprArg PlacementArgs,
1815 SourceLocation PlacementRParen,
1816 SourceRange TypeIdParens,
1817 QualType AllocatedType,
1818 TypeSourceInfo *AllocatedTypeInfo,
1819 Expr *ArraySize,
1820 SourceLocation ConstructorLParen,
1821 MultiExprArg ConstructorArgs,
1822 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001823 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001824 PlacementLParen,
1825 move(PlacementArgs),
1826 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001827 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001828 AllocatedType,
1829 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001830 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 ConstructorLParen,
1832 move(ConstructorArgs),
1833 ConstructorRParen);
1834 }
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregora16548e2009-08-11 05:31:07 +00001836 /// \brief Build a new C++ "delete" expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001840 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 bool IsGlobalDelete,
1842 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001843 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001844 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001845 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregora16548e2009-08-11 05:31:07 +00001848 /// \brief Build a new unary type trait expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001853 SourceLocation StartLoc,
1854 TypeSourceInfo *T,
1855 SourceLocation RParenLoc) {
1856 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 }
1858
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001859 /// \brief Build a new binary type trait expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
1862 /// Subclasses may override this routine to provide different behavior.
1863 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1864 SourceLocation StartLoc,
1865 TypeSourceInfo *LhsT,
1866 TypeSourceInfo *RhsT,
1867 SourceLocation RParenLoc) {
1868 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1869 }
1870
Mike Stump11289f42009-09-09 15:08:12 +00001871 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001872 /// expression.
1873 ///
1874 /// By default, performs semantic analysis to build the new expression.
1875 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001876 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001878 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001879 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 CXXScopeSpec SS;
1881 SS.setRange(QualifierRange);
1882 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001883
1884 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001885 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001886 *TemplateArgs);
1887
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001888 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 }
1890
1891 /// \brief Build a new template-id expression.
1892 ///
1893 /// By default, performs semantic analysis to build the new expression.
1894 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001895 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001896 LookupResult &R,
1897 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001898 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001899 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001900 }
1901
1902 /// \brief Build a new object-construction expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001906 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001907 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001908 CXXConstructorDecl *Constructor,
1909 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001910 MultiExprArg Args,
1911 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001912 CXXConstructExpr::ConstructionKind ConstructKind,
1913 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001914 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001915 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001916 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001917 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001918
Douglas Gregordb121ba2009-12-14 16:27:04 +00001919 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001920 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001921 RequiresZeroInit, ConstructKind,
1922 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 }
1924
1925 /// \brief Build a new object-construction expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001929 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1930 SourceLocation LParenLoc,
1931 MultiExprArg Args,
1932 SourceLocation RParenLoc) {
1933 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 LParenLoc,
1935 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 RParenLoc);
1937 }
1938
1939 /// \brief Build a new object-construction expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001943 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1944 SourceLocation LParenLoc,
1945 MultiExprArg Args,
1946 SourceLocation RParenLoc) {
1947 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 LParenLoc,
1949 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 RParenLoc);
1951 }
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// \brief Build a new member reference expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001958 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 bool IsArrow,
1960 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001961 NestedNameSpecifier *Qualifier,
1962 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001963 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001964 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001965 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001967 SS.setRange(QualifierRange);
1968 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001969
John McCallb268a282010-08-23 23:25:46 +00001970 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001971 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001972 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001973 MemberNameInfo,
1974 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001975 }
1976
John McCall10eae182009-11-30 22:42:35 +00001977 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001981 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001982 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001983 SourceLocation OperatorLoc,
1984 bool IsArrow,
1985 NestedNameSpecifier *Qualifier,
1986 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001987 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001988 LookupResult &R,
1989 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001990 CXXScopeSpec SS;
1991 SS.setRange(QualifierRange);
1992 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001993
John McCallb268a282010-08-23 23:25:46 +00001994 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001995 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001996 SS, FirstQualifierInScope,
1997 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002000 /// \brief Build a new noexcept expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2005 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2006 }
2007
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002008 /// \brief Build a new expression to compute the length of a parameter pack.
2009 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2010 SourceLocation PackLoc,
2011 SourceLocation RParenLoc,
2012 unsigned Length) {
2013 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2014 OperatorLoc, Pack, PackLoc,
2015 RParenLoc, Length);
2016 }
2017
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// \brief Build a new Objective-C @encode expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002023 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002024 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002025 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002027 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002028
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002029 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002030 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002031 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002032 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002033 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002034 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002035 MultiExprArg Args,
2036 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002037 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2038 ReceiverTypeInfo->getType(),
2039 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002040 Sel, Method, LBracLoc, SelectorLoc,
2041 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 }
2043
2044 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002045 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002047 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002048 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002049 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002050 MultiExprArg Args,
2051 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002052 return SemaRef.BuildInstanceMessage(Receiver,
2053 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002054 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002055 Sel, Method, LBracLoc, SelectorLoc,
2056 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002057 }
2058
Douglas Gregord51d90d2010-04-26 20:11:03 +00002059 /// \brief Build a new Objective-C ivar reference expression.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 SourceLocation IvarLoc,
2065 bool IsArrow, bool IsFreeIvar) {
2066 // FIXME: We lose track of the IsFreeIvar bit.
2067 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002068 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002069 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2070 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002072 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002073 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002074 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002075 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002076 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002077
Douglas Gregord51d90d2010-04-26 20:11:03 +00002078 if (Result.get())
2079 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002080
John McCallb268a282010-08-23 23:25:46 +00002081 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002082 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002083 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002084 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002085 /*TemplateArgs=*/0);
2086 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002087
2088 /// \brief Build a new Objective-C property reference expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002092 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002093 ObjCPropertyDecl *Property,
2094 SourceLocation PropertyLoc) {
2095 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002096 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002097 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2098 Sema::LookupMemberName);
2099 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002101 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002102 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002103 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002104 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002105
Douglas Gregor9faee212010-04-26 20:47:02 +00002106 if (Result.get())
2107 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002108
John McCallb268a282010-08-23 23:25:46 +00002109 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002110 /*FIXME:*/PropertyLoc, IsArrow,
2111 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002112 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002114 /*TemplateArgs=*/0);
2115 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002116
John McCallb7bd14f2010-12-02 01:19:52 +00002117 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002118 ///
2119 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002120 /// Subclasses may override this routine to provide different behavior.
2121 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2122 ObjCMethodDecl *Getter,
2123 ObjCMethodDecl *Setter,
2124 SourceLocation PropertyLoc) {
2125 // Since these expressions can only be value-dependent, we do not
2126 // need to perform semantic analysis again.
2127 return Owned(
2128 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2129 VK_LValue, OK_ObjCProperty,
2130 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002131 }
2132
Douglas Gregord51d90d2010-04-26 20:11:03 +00002133 /// \brief Build a new Objective-C "isa" expression.
2134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002137 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 bool IsArrow) {
2139 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002140 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2142 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002143 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002145 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002146 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002147 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 if (Result.get())
2150 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002151
John McCallb268a282010-08-23 23:25:46 +00002152 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002153 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002154 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002156 /*TemplateArgs=*/0);
2157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002158
Douglas Gregora16548e2009-08-11 05:31:07 +00002159 /// \brief Build a new shuffle vector expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002164 MultiExprArg SubExprs,
2165 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002166 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002167 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2169 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2170 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2171 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 // Build a reference to the __builtin_shufflevector builtin
2174 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002175 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002177 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002179
2180 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 unsigned NumSubExprs = SubExprs.size();
2182 Expr **Subs = (Expr **)SubExprs.release();
2183 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2184 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002185 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002186 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002191 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002193 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002194
Douglas Gregora16548e2009-08-11 05:31:07 +00002195 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002196 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 }
John McCall31f82722010-11-12 08:19:04 +00002198
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002199 /// \brief Build a new template argument pack expansion.
2200 ///
2201 /// By default, performs semantic analysis to build a new pack expansion
2202 /// for a template argument. Subclasses may override this routine to provide
2203 /// different behavior.
2204 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002205 SourceLocation EllipsisLoc,
2206 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002207 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002208 case TemplateArgument::Expression: {
2209 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002210 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2211 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002212 if (Result.isInvalid())
2213 return TemplateArgumentLoc();
2214
2215 return TemplateArgumentLoc(Result.get(), Result.get());
2216 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002217
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002218 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002219 return TemplateArgumentLoc(TemplateArgument(
2220 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002221 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002222 Pattern.getTemplateQualifierRange(),
2223 Pattern.getTemplateNameLoc(),
2224 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002225
2226 case TemplateArgument::Null:
2227 case TemplateArgument::Integral:
2228 case TemplateArgument::Declaration:
2229 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002230 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002231 llvm_unreachable("Pack expansion pattern has no parameter packs");
2232
2233 case TemplateArgument::Type:
2234 if (TypeSourceInfo *Expansion
2235 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002236 EllipsisLoc,
2237 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002238 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2239 Expansion);
2240 break;
2241 }
2242
2243 return TemplateArgumentLoc();
2244 }
2245
Douglas Gregor968f23a2011-01-03 19:31:53 +00002246 /// \brief Build a new expression pack expansion.
2247 ///
2248 /// By default, performs semantic analysis to build a new pack expansion
2249 /// for an expression. Subclasses may override this routine to provide
2250 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002251 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2252 llvm::Optional<unsigned> NumExpansions) {
2253 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002254 }
2255
John McCall31f82722010-11-12 08:19:04 +00002256private:
2257 QualType TransformTypeInObjectScope(QualType T,
2258 QualType ObjectType,
2259 NamedDecl *FirstQualifierInScope,
2260 NestedNameSpecifier *Prefix);
2261
2262 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2263 QualType ObjectType,
2264 NamedDecl *FirstQualifierInScope,
2265 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002266};
Douglas Gregora16548e2009-08-11 05:31:07 +00002267
Douglas Gregorebe10102009-08-20 07:17:43 +00002268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002269StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002270 if (!S)
2271 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregorebe10102009-08-20 07:17:43 +00002273 switch (S->getStmtClass()) {
2274 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002275
Douglas Gregorebe10102009-08-20 07:17:43 +00002276 // Transform individual statement nodes
2277#define STMT(Node, Parent) \
2278 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002279#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002280#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002281#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregorebe10102009-08-20 07:17:43 +00002283 // Transform expressions by calling TransformExpr.
2284#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002285#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002286#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002287#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002288 {
John McCalldadc5752010-08-24 06:29:42 +00002289 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002290 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002291 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002292
John McCallb268a282010-08-23 23:25:46 +00002293 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002294 }
Mike Stump11289f42009-09-09 15:08:12 +00002295 }
2296
John McCallc3007a22010-10-26 07:05:15 +00002297 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002298}
Mike Stump11289f42009-09-09 15:08:12 +00002299
2300
Douglas Gregore922c772009-08-04 22:27:00 +00002301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002302ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 if (!E)
2304 return SemaRef.Owned(E);
2305
2306 switch (E->getStmtClass()) {
2307 case Stmt::NoStmtClass: break;
2308#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002309#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002310#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002311 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002312#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002313 }
2314
John McCallc3007a22010-10-26 07:05:15 +00002315 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002316}
2317
2318template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002319bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2320 unsigned NumInputs,
2321 bool IsCall,
2322 llvm::SmallVectorImpl<Expr *> &Outputs,
2323 bool *ArgChanged) {
2324 for (unsigned I = 0; I != NumInputs; ++I) {
2325 // If requested, drop call arguments that need to be dropped.
2326 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2327 if (ArgChanged)
2328 *ArgChanged = true;
2329
2330 break;
2331 }
2332
Douglas Gregor968f23a2011-01-03 19:31:53 +00002333 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2334 Expr *Pattern = Expansion->getPattern();
2335
2336 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2337 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2339
2340 // Determine whether the set of unexpanded parameter packs can and should
2341 // be expanded.
2342 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002343 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002344 llvm::Optional<unsigned> OrigNumExpansions
2345 = Expansion->getNumExpansions();
2346 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002347 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2348 Pattern->getSourceRange(),
2349 Unexpanded.data(),
2350 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002351 Expand, RetainExpansion,
2352 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002353 return true;
2354
2355 if (!Expand) {
2356 // The transform has determined that we should perform a simple
2357 // transformation on the pack expansion, producing another pack
2358 // expansion.
2359 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2360 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2361 if (OutPattern.isInvalid())
2362 return true;
2363
2364 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002365 Expansion->getEllipsisLoc(),
2366 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002367 if (Out.isInvalid())
2368 return true;
2369
2370 if (ArgChanged)
2371 *ArgChanged = true;
2372 Outputs.push_back(Out.get());
2373 continue;
2374 }
2375
2376 // The transform has determined that we should perform an elementwise
2377 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002378 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002379 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2380 ExprResult Out = getDerived().TransformExpr(Pattern);
2381 if (Out.isInvalid())
2382 return true;
2383
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002384 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002385 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2386 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002387 if (Out.isInvalid())
2388 return true;
2389 }
2390
Douglas Gregor968f23a2011-01-03 19:31:53 +00002391 if (ArgChanged)
2392 *ArgChanged = true;
2393 Outputs.push_back(Out.get());
2394 }
2395
2396 continue;
2397 }
2398
Douglas Gregora3efea12011-01-03 19:04:46 +00002399 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2400 if (Result.isInvalid())
2401 return true;
2402
2403 if (Result.get() != Inputs[I] && ArgChanged)
2404 *ArgChanged = true;
2405
2406 Outputs.push_back(Result.get());
2407 }
2408
2409 return false;
2410}
2411
2412template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002413NestedNameSpecifier *
2414TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002415 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002416 QualType ObjectType,
2417 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002418 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002419
Douglas Gregorebe10102009-08-20 07:17:43 +00002420 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002421 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002422 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002423 ObjectType,
2424 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002425 if (!Prefix)
2426 return 0;
2427 }
Mike Stump11289f42009-09-09 15:08:12 +00002428
Douglas Gregor1135c352009-08-06 05:28:30 +00002429 switch (NNS->getKind()) {
2430 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002431 if (Prefix) {
2432 // The object type and qualifier-in-scope really apply to the
2433 // leftmost entity.
2434 ObjectType = QualType();
2435 FirstQualifierInScope = 0;
2436 }
2437
Mike Stump11289f42009-09-09 15:08:12 +00002438 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002439 "Identifier nested-name-specifier with no prefix or object type");
2440 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2441 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002442 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002443
2444 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002445 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002446 ObjectType,
2447 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002448
Douglas Gregor1135c352009-08-06 05:28:30 +00002449 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002450 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002451 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002452 getDerived().TransformDecl(Range.getBegin(),
2453 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002454 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002455 Prefix == NNS->getPrefix() &&
2456 NS == NNS->getAsNamespace())
2457 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002458
Douglas Gregor1135c352009-08-06 05:28:30 +00002459 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2460 }
Mike Stump11289f42009-09-09 15:08:12 +00002461
Douglas Gregor1135c352009-08-06 05:28:30 +00002462 case NestedNameSpecifier::Global:
2463 // There is no meaningful transformation that one could perform on the
2464 // global scope.
2465 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002466
Douglas Gregor1135c352009-08-06 05:28:30 +00002467 case NestedNameSpecifier::TypeSpecWithTemplate:
2468 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002469 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002470 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2471 ObjectType,
2472 FirstQualifierInScope,
2473 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002474 if (T.isNull())
2475 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002476
Douglas Gregor1135c352009-08-06 05:28:30 +00002477 if (!getDerived().AlwaysRebuild() &&
2478 Prefix == NNS->getPrefix() &&
2479 T == QualType(NNS->getAsType(), 0))
2480 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002481
2482 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2483 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002484 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002485 }
2486 }
Mike Stump11289f42009-09-09 15:08:12 +00002487
Douglas Gregor1135c352009-08-06 05:28:30 +00002488 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002489 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002490}
2491
2492template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002493DeclarationNameInfo
2494TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002495::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002496 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002497 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002498 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002499
2500 switch (Name.getNameKind()) {
2501 case DeclarationName::Identifier:
2502 case DeclarationName::ObjCZeroArgSelector:
2503 case DeclarationName::ObjCOneArgSelector:
2504 case DeclarationName::ObjCMultiArgSelector:
2505 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002506 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002507 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002508 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002509
Douglas Gregorf816bd72009-09-03 22:13:48 +00002510 case DeclarationName::CXXConstructorName:
2511 case DeclarationName::CXXDestructorName:
2512 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002513 TypeSourceInfo *NewTInfo;
2514 CanQualType NewCanTy;
2515 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002516 NewTInfo = getDerived().TransformType(OldTInfo);
2517 if (!NewTInfo)
2518 return DeclarationNameInfo();
2519 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002520 }
2521 else {
2522 NewTInfo = 0;
2523 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002524 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002525 if (NewT.isNull())
2526 return DeclarationNameInfo();
2527 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2528 }
Mike Stump11289f42009-09-09 15:08:12 +00002529
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002530 DeclarationName NewName
2531 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2532 NewCanTy);
2533 DeclarationNameInfo NewNameInfo(NameInfo);
2534 NewNameInfo.setName(NewName);
2535 NewNameInfo.setNamedTypeInfo(NewTInfo);
2536 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002537 }
Mike Stump11289f42009-09-09 15:08:12 +00002538 }
2539
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002540 assert(0 && "Unknown name kind.");
2541 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002542}
2543
2544template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002545TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002546TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002547 QualType ObjectType,
2548 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002549 SourceLocation Loc = getDerived().getBaseLocation();
2550
Douglas Gregor71dc5092009-08-06 06:41:21 +00002551 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002552 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002553 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002554 /*FIXME*/ SourceRange(Loc),
2555 ObjectType,
2556 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002557 if (!NNS)
2558 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002559
Douglas Gregor71dc5092009-08-06 06:41:21 +00002560 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002561 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002562 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002563 if (!TransTemplate)
2564 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002565
Douglas Gregor71dc5092009-08-06 06:41:21 +00002566 if (!getDerived().AlwaysRebuild() &&
2567 NNS == QTN->getQualifier() &&
2568 TransTemplate == Template)
2569 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002570
Douglas Gregor71dc5092009-08-06 06:41:21 +00002571 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2572 TransTemplate);
2573 }
Mike Stump11289f42009-09-09 15:08:12 +00002574
John McCalle66edc12009-11-24 19:00:30 +00002575 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002576 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002577 }
Mike Stump11289f42009-09-09 15:08:12 +00002578
Douglas Gregor71dc5092009-08-06 06:41:21 +00002579 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002580 NestedNameSpecifier *NNS = DTN->getQualifier();
2581 if (NNS) {
2582 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2583 /*FIXME:*/SourceRange(Loc),
2584 ObjectType,
2585 FirstQualifierInScope);
2586 if (!NNS) return TemplateName();
2587
2588 // These apply to the scope specifier, not the template.
2589 ObjectType = QualType();
2590 FirstQualifierInScope = 0;
2591 }
Mike Stump11289f42009-09-09 15:08:12 +00002592
Douglas Gregor71dc5092009-08-06 06:41:21 +00002593 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002594 NNS == DTN->getQualifier() &&
2595 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002596 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002597
Douglas Gregora5614c52010-09-08 23:56:00 +00002598 if (DTN->isIdentifier()) {
2599 // FIXME: Bad range
2600 SourceRange QualifierRange(getDerived().getBaseLocation());
2601 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2602 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002603 ObjectType,
2604 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002605 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002606
2607 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002608 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002609 }
Mike Stump11289f42009-09-09 15:08:12 +00002610
Douglas Gregor71dc5092009-08-06 06:41:21 +00002611 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002612 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002613 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002614 if (!TransTemplate)
2615 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002616
Douglas Gregor71dc5092009-08-06 06:41:21 +00002617 if (!getDerived().AlwaysRebuild() &&
2618 TransTemplate == Template)
2619 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002620
Douglas Gregor71dc5092009-08-06 06:41:21 +00002621 return TemplateName(TransTemplate);
2622 }
Mike Stump11289f42009-09-09 15:08:12 +00002623
Douglas Gregor5590be02011-01-15 06:45:20 +00002624 if (SubstTemplateTemplateParmPackStorage *SubstPack
2625 = Name.getAsSubstTemplateTemplateParmPack()) {
2626 TemplateTemplateParmDecl *TransParam
2627 = cast_or_null<TemplateTemplateParmDecl>(
2628 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2629 if (!TransParam)
2630 return TemplateName();
2631
2632 if (!getDerived().AlwaysRebuild() &&
2633 TransParam == SubstPack->getParameterPack())
2634 return Name;
2635
2636 return getDerived().RebuildTemplateName(TransParam,
2637 SubstPack->getArgumentPack());
2638 }
2639
John McCalle66edc12009-11-24 19:00:30 +00002640 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002641 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002642 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002643}
2644
2645template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002646void TreeTransform<Derived>::InventTemplateArgumentLoc(
2647 const TemplateArgument &Arg,
2648 TemplateArgumentLoc &Output) {
2649 SourceLocation Loc = getDerived().getBaseLocation();
2650 switch (Arg.getKind()) {
2651 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002652 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002653 break;
2654
2655 case TemplateArgument::Type:
2656 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002657 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002658
John McCall0ad16662009-10-29 08:12:44 +00002659 break;
2660
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002661 case TemplateArgument::Template:
2662 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2663 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002664
2665 case TemplateArgument::TemplateExpansion:
2666 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2667 break;
2668
John McCall0ad16662009-10-29 08:12:44 +00002669 case TemplateArgument::Expression:
2670 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2671 break;
2672
2673 case TemplateArgument::Declaration:
2674 case TemplateArgument::Integral:
2675 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002676 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002677 break;
2678 }
2679}
2680
2681template<typename Derived>
2682bool TreeTransform<Derived>::TransformTemplateArgument(
2683 const TemplateArgumentLoc &Input,
2684 TemplateArgumentLoc &Output) {
2685 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002686 switch (Arg.getKind()) {
2687 case TemplateArgument::Null:
2688 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002689 Output = Input;
2690 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregore922c772009-08-04 22:27:00 +00002692 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002693 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002694 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002695 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002696
2697 DI = getDerived().TransformType(DI);
2698 if (!DI) return true;
2699
2700 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2701 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002702 }
Mike Stump11289f42009-09-09 15:08:12 +00002703
Douglas Gregore922c772009-08-04 22:27:00 +00002704 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002705 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002706 DeclarationName Name;
2707 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2708 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002709 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002710 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002711 if (!D) return true;
2712
John McCall0d07eb32009-10-29 18:45:58 +00002713 Expr *SourceExpr = Input.getSourceDeclExpression();
2714 if (SourceExpr) {
2715 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002716 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002717 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002718 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002719 }
2720
2721 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002722 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002723 }
Mike Stump11289f42009-09-09 15:08:12 +00002724
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002725 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002726 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002727 TemplateName Template
2728 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2729 if (Template.isNull())
2730 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002731
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002732 Output = TemplateArgumentLoc(TemplateArgument(Template),
2733 Input.getTemplateQualifierRange(),
2734 Input.getTemplateNameLoc());
2735 return false;
2736 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002737
2738 case TemplateArgument::TemplateExpansion:
2739 llvm_unreachable("Caller should expand pack expansions");
2740
Douglas Gregore922c772009-08-04 22:27:00 +00002741 case TemplateArgument::Expression: {
2742 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002743 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002744 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002745
John McCall0ad16662009-10-29 08:12:44 +00002746 Expr *InputExpr = Input.getSourceExpression();
2747 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2748
John McCalldadc5752010-08-24 06:29:42 +00002749 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002750 = getDerived().TransformExpr(InputExpr);
2751 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002752 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002753 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
Douglas Gregore922c772009-08-04 22:27:00 +00002756 case TemplateArgument::Pack: {
2757 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2758 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002759 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002760 AEnd = Arg.pack_end();
2761 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002762
John McCall0ad16662009-10-29 08:12:44 +00002763 // FIXME: preserve source information here when we start
2764 // caring about parameter packs.
2765
John McCall0d07eb32009-10-29 18:45:58 +00002766 TemplateArgumentLoc InputArg;
2767 TemplateArgumentLoc OutputArg;
2768 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2769 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002770 return true;
2771
John McCall0d07eb32009-10-29 18:45:58 +00002772 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002773 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002774
2775 TemplateArgument *TransformedArgsPtr
2776 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2777 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2778 TransformedArgsPtr);
2779 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2780 TransformedArgs.size()),
2781 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002782 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002783 }
2784 }
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregore922c772009-08-04 22:27:00 +00002786 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002787 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002788}
2789
Douglas Gregorfe921a72010-12-20 23:36:19 +00002790/// \brief Iterator adaptor that invents template argument location information
2791/// for each of the template arguments in its underlying iterator.
2792template<typename Derived, typename InputIterator>
2793class TemplateArgumentLocInventIterator {
2794 TreeTransform<Derived> &Self;
2795 InputIterator Iter;
2796
2797public:
2798 typedef TemplateArgumentLoc value_type;
2799 typedef TemplateArgumentLoc reference;
2800 typedef typename std::iterator_traits<InputIterator>::difference_type
2801 difference_type;
2802 typedef std::input_iterator_tag iterator_category;
2803
2804 class pointer {
2805 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002806
Douglas Gregorfe921a72010-12-20 23:36:19 +00002807 public:
2808 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2809
2810 const TemplateArgumentLoc *operator->() const { return &Arg; }
2811 };
2812
2813 TemplateArgumentLocInventIterator() { }
2814
2815 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2816 InputIterator Iter)
2817 : Self(Self), Iter(Iter) { }
2818
2819 TemplateArgumentLocInventIterator &operator++() {
2820 ++Iter;
2821 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002822 }
2823
Douglas Gregorfe921a72010-12-20 23:36:19 +00002824 TemplateArgumentLocInventIterator operator++(int) {
2825 TemplateArgumentLocInventIterator Old(*this);
2826 ++(*this);
2827 return Old;
2828 }
2829
2830 reference operator*() const {
2831 TemplateArgumentLoc Result;
2832 Self.InventTemplateArgumentLoc(*Iter, Result);
2833 return Result;
2834 }
2835
2836 pointer operator->() const { return pointer(**this); }
2837
2838 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2839 const TemplateArgumentLocInventIterator &Y) {
2840 return X.Iter == Y.Iter;
2841 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002842
Douglas Gregorfe921a72010-12-20 23:36:19 +00002843 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2844 const TemplateArgumentLocInventIterator &Y) {
2845 return X.Iter != Y.Iter;
2846 }
2847};
2848
Douglas Gregor42cafa82010-12-20 17:42:22 +00002849template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002850template<typename InputIterator>
2851bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2852 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002853 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002854 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002855 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002856 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002857
2858 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2859 // Unpack argument packs, which we translate them into separate
2860 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002861 // FIXME: We could do much better if we could guarantee that the
2862 // TemplateArgumentLocInfo for the pack expansion would be usable for
2863 // all of the template arguments in the argument pack.
2864 typedef TemplateArgumentLocInventIterator<Derived,
2865 TemplateArgument::pack_iterator>
2866 PackLocIterator;
2867 if (TransformTemplateArguments(PackLocIterator(*this,
2868 In.getArgument().pack_begin()),
2869 PackLocIterator(*this,
2870 In.getArgument().pack_end()),
2871 Outputs))
2872 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002873
2874 continue;
2875 }
2876
2877 if (In.getArgument().isPackExpansion()) {
2878 // We have a pack expansion, for which we will be substituting into
2879 // the pattern.
2880 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002881 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002882 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002883 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2884 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002885
2886 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2887 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2888 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2889
2890 // Determine whether the set of unexpanded parameter packs can and should
2891 // be expanded.
2892 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002893 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002894 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002895 if (getDerived().TryExpandParameterPacks(Ellipsis,
2896 Pattern.getSourceRange(),
2897 Unexpanded.data(),
2898 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002899 Expand,
2900 RetainExpansion,
2901 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002902 return true;
2903
2904 if (!Expand) {
2905 // The transform has determined that we should perform a simple
2906 // transformation on the pack expansion, producing another pack
2907 // expansion.
2908 TemplateArgumentLoc OutPattern;
2909 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2910 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2911 return true;
2912
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002913 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2914 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002915 if (Out.getArgument().isNull())
2916 return true;
2917
2918 Outputs.addArgument(Out);
2919 continue;
2920 }
2921
2922 // The transform has determined that we should perform an elementwise
2923 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002924 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002925 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2926
2927 if (getDerived().TransformTemplateArgument(Pattern, Out))
2928 return true;
2929
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002930 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002931 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2932 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002933 if (Out.getArgument().isNull())
2934 return true;
2935 }
2936
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002937 Outputs.addArgument(Out);
2938 }
2939
Douglas Gregor48d24112011-01-10 20:53:55 +00002940 // If we're supposed to retain a pack expansion, do so by temporarily
2941 // forgetting the partially-substituted parameter pack.
2942 if (RetainExpansion) {
2943 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2944
2945 if (getDerived().TransformTemplateArgument(Pattern, Out))
2946 return true;
2947
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002948 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2949 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002950 if (Out.getArgument().isNull())
2951 return true;
2952
2953 Outputs.addArgument(Out);
2954 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002955
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002956 continue;
2957 }
2958
2959 // The simple case:
2960 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002961 return true;
2962
2963 Outputs.addArgument(Out);
2964 }
2965
2966 return false;
2967
2968}
2969
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970//===----------------------------------------------------------------------===//
2971// Type transformation
2972//===----------------------------------------------------------------------===//
2973
2974template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002975QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976 if (getDerived().AlreadyTransformed(T))
2977 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 // Temporary workaround. All of these transformations should
2980 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002981 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2982 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002983
John McCall31f82722010-11-12 08:19:04 +00002984 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002985
John McCall550e0c22009-10-21 00:40:46 +00002986 if (!NewDI)
2987 return QualType();
2988
2989 return NewDI->getType();
2990}
2991
2992template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002993TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002994 if (getDerived().AlreadyTransformed(DI->getType()))
2995 return DI;
2996
2997 TypeLocBuilder TLB;
2998
2999 TypeLoc TL = DI->getTypeLoc();
3000 TLB.reserve(TL.getFullDataSize());
3001
John McCall31f82722010-11-12 08:19:04 +00003002 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003003 if (Result.isNull())
3004 return 0;
3005
John McCallbcd03502009-12-07 02:54:59 +00003006 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003007}
3008
3009template<typename Derived>
3010QualType
John McCall31f82722010-11-12 08:19:04 +00003011TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003012 switch (T.getTypeLocClass()) {
3013#define ABSTRACT_TYPELOC(CLASS, PARENT)
3014#define TYPELOC(CLASS, PARENT) \
3015 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003016 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003017#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018 }
Mike Stump11289f42009-09-09 15:08:12 +00003019
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003020 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003021 return QualType();
3022}
3023
3024/// FIXME: By default, this routine adds type qualifiers only to types
3025/// that can have qualifiers, and silently suppresses those qualifiers
3026/// that are not permitted (e.g., qualifiers on reference or function
3027/// types). This is the right thing for template instantiation, but
3028/// probably not for other clients.
3029template<typename Derived>
3030QualType
3031TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003032 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003033 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003034
John McCall31f82722010-11-12 08:19:04 +00003035 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003036 if (Result.isNull())
3037 return QualType();
3038
3039 // Silently suppress qualifiers if the result type can't be qualified.
3040 // FIXME: this is the right thing for template instantiation, but
3041 // probably not for other clients.
3042 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003043 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003044
John McCallcb0f89a2010-06-05 06:41:15 +00003045 if (!Quals.empty()) {
3046 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3047 TLB.push<QualifiedTypeLoc>(Result);
3048 // No location information to preserve.
3049 }
John McCall550e0c22009-10-21 00:40:46 +00003050
3051 return Result;
3052}
3053
John McCall31f82722010-11-12 08:19:04 +00003054/// \brief Transforms a type that was written in a scope specifier,
3055/// given an object type, the results of unqualified lookup, and
3056/// an already-instantiated prefix.
3057///
3058/// The object type is provided iff the scope specifier qualifies the
3059/// member of a dependent member-access expression. The prefix is
3060/// provided iff the the scope specifier in which this appears has a
3061/// prefix.
3062///
3063/// This is private to TreeTransform.
3064template<typename Derived>
3065QualType
3066TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3067 QualType ObjectType,
3068 NamedDecl *UnqualLookup,
3069 NestedNameSpecifier *Prefix) {
3070 if (getDerived().AlreadyTransformed(T))
3071 return T;
3072
3073 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003074 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003075
3076 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3077 UnqualLookup, Prefix);
3078 if (!TSI) return QualType();
3079 return TSI->getType();
3080}
3081
3082template<typename Derived>
3083TypeSourceInfo *
3084TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3085 QualType ObjectType,
3086 NamedDecl *UnqualLookup,
3087 NestedNameSpecifier *Prefix) {
3088 // TODO: in some cases, we might be some verification to do here.
3089 if (ObjectType.isNull())
3090 return getDerived().TransformType(TSI);
3091
3092 QualType T = TSI->getType();
3093 if (getDerived().AlreadyTransformed(T))
3094 return TSI;
3095
3096 TypeLocBuilder TLB;
3097 QualType Result;
3098
3099 if (isa<TemplateSpecializationType>(T)) {
3100 TemplateSpecializationTypeLoc TL
3101 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3102
3103 TemplateName Template =
3104 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3105 ObjectType, UnqualLookup);
3106 if (Template.isNull()) return 0;
3107
3108 Result = getDerived()
3109 .TransformTemplateSpecializationType(TLB, TL, Template);
3110 } else if (isa<DependentTemplateSpecializationType>(T)) {
3111 DependentTemplateSpecializationTypeLoc TL
3112 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3113
3114 Result = getDerived()
3115 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3116 } else {
3117 // Nothing special needs to be done for these.
3118 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3119 }
3120
3121 if (Result.isNull()) return 0;
3122 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3123}
3124
John McCall550e0c22009-10-21 00:40:46 +00003125template <class TyLoc> static inline
3126QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3127 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3128 NewT.setNameLoc(T.getNameLoc());
3129 return T.getType();
3130}
3131
John McCall550e0c22009-10-21 00:40:46 +00003132template<typename Derived>
3133QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003134 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003135 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3136 NewT.setBuiltinLoc(T.getBuiltinLoc());
3137 if (T.needsExtraLocalData())
3138 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3139 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140}
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregord6ff3322009-08-04 16:50:30 +00003142template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003143QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003144 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003145 // FIXME: recurse?
3146 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003147}
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003150QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003151 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003152 QualType PointeeType
3153 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003154 if (PointeeType.isNull())
3155 return QualType();
3156
3157 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003158 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003159 // A dependent pointer type 'T *' has is being transformed such
3160 // that an Objective-C class type is being replaced for 'T'. The
3161 // resulting pointer type is an ObjCObjectPointerType, not a
3162 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003163 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003164
John McCall8b07ec22010-05-15 11:32:37 +00003165 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3166 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003167 return Result;
3168 }
John McCall31f82722010-11-12 08:19:04 +00003169
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003170 if (getDerived().AlwaysRebuild() ||
3171 PointeeType != TL.getPointeeLoc().getType()) {
3172 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3173 if (Result.isNull())
3174 return QualType();
3175 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003176
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003177 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3178 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003179 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003180}
Mike Stump11289f42009-09-09 15:08:12 +00003181
3182template<typename Derived>
3183QualType
John McCall550e0c22009-10-21 00:40:46 +00003184TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003185 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003186 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003187 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3188 if (PointeeType.isNull())
3189 return QualType();
3190
3191 QualType Result = TL.getType();
3192 if (getDerived().AlwaysRebuild() ||
3193 PointeeType != TL.getPointeeLoc().getType()) {
3194 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003195 TL.getSigilLoc());
3196 if (Result.isNull())
3197 return QualType();
3198 }
3199
Douglas Gregor049211a2010-04-22 16:50:51 +00003200 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003201 NewT.setSigilLoc(TL.getSigilLoc());
3202 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003203}
3204
John McCall70dd5f62009-10-30 00:06:24 +00003205/// Transforms a reference type. Note that somewhat paradoxically we
3206/// don't care whether the type itself is an l-value type or an r-value
3207/// type; we only care if the type was *written* as an l-value type
3208/// or an r-value type.
3209template<typename Derived>
3210QualType
3211TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003212 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003213 const ReferenceType *T = TL.getTypePtr();
3214
3215 // Note that this works with the pointee-as-written.
3216 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3217 if (PointeeType.isNull())
3218 return QualType();
3219
3220 QualType Result = TL.getType();
3221 if (getDerived().AlwaysRebuild() ||
3222 PointeeType != T->getPointeeTypeAsWritten()) {
3223 Result = getDerived().RebuildReferenceType(PointeeType,
3224 T->isSpelledAsLValue(),
3225 TL.getSigilLoc());
3226 if (Result.isNull())
3227 return QualType();
3228 }
3229
3230 // r-value references can be rebuilt as l-value references.
3231 ReferenceTypeLoc NewTL;
3232 if (isa<LValueReferenceType>(Result))
3233 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3234 else
3235 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3236 NewTL.setSigilLoc(TL.getSigilLoc());
3237
3238 return Result;
3239}
3240
Mike Stump11289f42009-09-09 15:08:12 +00003241template<typename Derived>
3242QualType
John McCall550e0c22009-10-21 00:40:46 +00003243TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003244 LValueReferenceTypeLoc TL) {
3245 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003246}
3247
Mike Stump11289f42009-09-09 15:08:12 +00003248template<typename Derived>
3249QualType
John McCall550e0c22009-10-21 00:40:46 +00003250TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003251 RValueReferenceTypeLoc TL) {
3252 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003253}
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003256QualType
John McCall550e0c22009-10-21 00:40:46 +00003257TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003258 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003259 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003260
3261 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003262 if (PointeeType.isNull())
3263 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003264
John McCall550e0c22009-10-21 00:40:46 +00003265 // TODO: preserve source information for this.
3266 QualType ClassType
3267 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003268 if (ClassType.isNull())
3269 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003270
John McCall550e0c22009-10-21 00:40:46 +00003271 QualType Result = TL.getType();
3272 if (getDerived().AlwaysRebuild() ||
3273 PointeeType != T->getPointeeType() ||
3274 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003275 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3276 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003277 if (Result.isNull())
3278 return QualType();
3279 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003280
John McCall550e0c22009-10-21 00:40:46 +00003281 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3282 NewTL.setSigilLoc(TL.getSigilLoc());
3283
3284 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285}
3286
Mike Stump11289f42009-09-09 15:08:12 +00003287template<typename Derived>
3288QualType
John McCall550e0c22009-10-21 00:40:46 +00003289TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003290 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003291 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003292 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 if (ElementType.isNull())
3294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003295
John McCall550e0c22009-10-21 00:40:46 +00003296 QualType Result = TL.getType();
3297 if (getDerived().AlwaysRebuild() ||
3298 ElementType != T->getElementType()) {
3299 Result = getDerived().RebuildConstantArrayType(ElementType,
3300 T->getSizeModifier(),
3301 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003302 T->getIndexTypeCVRQualifiers(),
3303 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003304 if (Result.isNull())
3305 return QualType();
3306 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003307
John McCall550e0c22009-10-21 00:40:46 +00003308 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3309 NewTL.setLBracketLoc(TL.getLBracketLoc());
3310 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003311
John McCall550e0c22009-10-21 00:40:46 +00003312 Expr *Size = TL.getSizeExpr();
3313 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003314 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003315 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3316 }
3317 NewTL.setSizeExpr(Size);
3318
3319 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320}
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003324 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003325 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003326 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003327 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328 if (ElementType.isNull())
3329 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003330
John McCall550e0c22009-10-21 00:40:46 +00003331 QualType Result = TL.getType();
3332 if (getDerived().AlwaysRebuild() ||
3333 ElementType != T->getElementType()) {
3334 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003335 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003336 T->getIndexTypeCVRQualifiers(),
3337 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003338 if (Result.isNull())
3339 return QualType();
3340 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003341
John McCall550e0c22009-10-21 00:40:46 +00003342 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3343 NewTL.setLBracketLoc(TL.getLBracketLoc());
3344 NewTL.setRBracketLoc(TL.getRBracketLoc());
3345 NewTL.setSizeExpr(0);
3346
3347 return Result;
3348}
3349
3350template<typename Derived>
3351QualType
3352TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003353 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003354 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003355 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3356 if (ElementType.isNull())
3357 return QualType();
3358
3359 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003360 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003361
John McCalldadc5752010-08-24 06:29:42 +00003362 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003363 = getDerived().TransformExpr(T->getSizeExpr());
3364 if (SizeResult.isInvalid())
3365 return QualType();
3366
John McCallb268a282010-08-23 23:25:46 +00003367 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003368
3369 QualType Result = TL.getType();
3370 if (getDerived().AlwaysRebuild() ||
3371 ElementType != T->getElementType() ||
3372 Size != T->getSizeExpr()) {
3373 Result = getDerived().RebuildVariableArrayType(ElementType,
3374 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003375 Size,
John McCall550e0c22009-10-21 00:40:46 +00003376 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003377 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003378 if (Result.isNull())
3379 return QualType();
3380 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003381
John McCall550e0c22009-10-21 00:40:46 +00003382 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3383 NewTL.setLBracketLoc(TL.getLBracketLoc());
3384 NewTL.setRBracketLoc(TL.getRBracketLoc());
3385 NewTL.setSizeExpr(Size);
3386
3387 return Result;
3388}
3389
3390template<typename Derived>
3391QualType
3392TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003393 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003394 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003395 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3396 if (ElementType.isNull())
3397 return QualType();
3398
3399 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003401
John McCall33ddac02011-01-19 10:06:00 +00003402 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3403 Expr *origSize = TL.getSizeExpr();
3404 if (!origSize) origSize = T->getSizeExpr();
3405
3406 ExprResult sizeResult
3407 = getDerived().TransformExpr(origSize);
3408 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003409 return QualType();
3410
John McCall33ddac02011-01-19 10:06:00 +00003411 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003412
3413 QualType Result = TL.getType();
3414 if (getDerived().AlwaysRebuild() ||
3415 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003416 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003417 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3418 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003419 size,
John McCall550e0c22009-10-21 00:40:46 +00003420 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003421 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003422 if (Result.isNull())
3423 return QualType();
3424 }
John McCall550e0c22009-10-21 00:40:46 +00003425
3426 // We might have any sort of array type now, but fortunately they
3427 // all have the same location layout.
3428 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3429 NewTL.setLBracketLoc(TL.getLBracketLoc());
3430 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003431 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003432
3433 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003434}
Mike Stump11289f42009-09-09 15:08:12 +00003435
3436template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003438 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003439 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003440 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003441
3442 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003443 QualType ElementType = getDerived().TransformType(T->getElementType());
3444 if (ElementType.isNull())
3445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregore922c772009-08-04 22:27:00 +00003447 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003448 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003449
John McCalldadc5752010-08-24 06:29:42 +00003450 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003451 if (Size.isInvalid())
3452 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003453
John McCall550e0c22009-10-21 00:40:46 +00003454 QualType Result = TL.getType();
3455 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003456 ElementType != T->getElementType() ||
3457 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003458 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003459 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003460 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003461 if (Result.isNull())
3462 return QualType();
3463 }
John McCall550e0c22009-10-21 00:40:46 +00003464
3465 // Result might be dependent or not.
3466 if (isa<DependentSizedExtVectorType>(Result)) {
3467 DependentSizedExtVectorTypeLoc NewTL
3468 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3469 NewTL.setNameLoc(TL.getNameLoc());
3470 } else {
3471 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3472 NewTL.setNameLoc(TL.getNameLoc());
3473 }
3474
3475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003476}
Mike Stump11289f42009-09-09 15:08:12 +00003477
3478template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003479QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003480 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003481 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003482 QualType ElementType = getDerived().TransformType(T->getElementType());
3483 if (ElementType.isNull())
3484 return QualType();
3485
John McCall550e0c22009-10-21 00:40:46 +00003486 QualType Result = TL.getType();
3487 if (getDerived().AlwaysRebuild() ||
3488 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003489 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003490 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003491 if (Result.isNull())
3492 return QualType();
3493 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003494
John McCall550e0c22009-10-21 00:40:46 +00003495 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3496 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003497
John McCall550e0c22009-10-21 00:40:46 +00003498 return Result;
3499}
3500
3501template<typename Derived>
3502QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003503 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003504 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003505 QualType ElementType = getDerived().TransformType(T->getElementType());
3506 if (ElementType.isNull())
3507 return QualType();
3508
3509 QualType Result = TL.getType();
3510 if (getDerived().AlwaysRebuild() ||
3511 ElementType != T->getElementType()) {
3512 Result = getDerived().RebuildExtVectorType(ElementType,
3513 T->getNumElements(),
3514 /*FIXME*/ SourceLocation());
3515 if (Result.isNull())
3516 return QualType();
3517 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003518
John McCall550e0c22009-10-21 00:40:46 +00003519 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3520 NewTL.setNameLoc(TL.getNameLoc());
3521
3522 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523}
Mike Stump11289f42009-09-09 15:08:12 +00003524
3525template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003526ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003527TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3528 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003529 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003530 TypeSourceInfo *NewDI = 0;
3531
3532 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3533 // If we're substituting into a pack expansion type and we know the
3534 TypeLoc OldTL = OldDI->getTypeLoc();
3535 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3536
3537 TypeLocBuilder TLB;
3538 TypeLoc NewTL = OldDI->getTypeLoc();
3539 TLB.reserve(NewTL.getFullDataSize());
3540
3541 QualType Result = getDerived().TransformType(TLB,
3542 OldExpansionTL.getPatternLoc());
3543 if (Result.isNull())
3544 return 0;
3545
3546 Result = RebuildPackExpansionType(Result,
3547 OldExpansionTL.getPatternLoc().getSourceRange(),
3548 OldExpansionTL.getEllipsisLoc(),
3549 NumExpansions);
3550 if (Result.isNull())
3551 return 0;
3552
3553 PackExpansionTypeLoc NewExpansionTL
3554 = TLB.push<PackExpansionTypeLoc>(Result);
3555 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3556 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3557 } else
3558 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003559 if (!NewDI)
3560 return 0;
3561
3562 if (NewDI == OldDI)
3563 return OldParm;
3564 else
3565 return ParmVarDecl::Create(SemaRef.Context,
3566 OldParm->getDeclContext(),
3567 OldParm->getLocation(),
3568 OldParm->getIdentifier(),
3569 NewDI->getType(),
3570 NewDI,
3571 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003572 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003573 /* DefArg */ NULL);
3574}
3575
3576template<typename Derived>
3577bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003578 TransformFunctionTypeParams(SourceLocation Loc,
3579 ParmVarDecl **Params, unsigned NumParams,
3580 const QualType *ParamTypes,
3581 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3582 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3583 for (unsigned i = 0; i != NumParams; ++i) {
3584 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003585 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003586 if (OldParm->isParameterPack()) {
3587 // We have a function parameter pack that may need to be expanded.
3588 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003589
Douglas Gregor5499af42011-01-05 23:12:31 +00003590 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003591 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3592 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3593 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3594 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003595
3596 // Determine whether we should expand the parameter packs.
3597 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003598 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003599 llvm::Optional<unsigned> OrigNumExpansions
3600 = ExpansionTL.getTypePtr()->getNumExpansions();
3601 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003602 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3603 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003604 Unexpanded.data(),
3605 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003606 ShouldExpand,
3607 RetainExpansion,
3608 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003609 return true;
3610 }
3611
3612 if (ShouldExpand) {
3613 // Expand the function parameter pack into multiple, separate
3614 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003615 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003616 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003617 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3618 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003619 = getDerived().TransformFunctionTypeParam(OldParm,
3620 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003621 if (!NewParm)
3622 return true;
3623
Douglas Gregordd472162011-01-07 00:20:55 +00003624 OutParamTypes.push_back(NewParm->getType());
3625 if (PVars)
3626 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003627 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003628
3629 // If we're supposed to retain a pack expansion, do so by temporarily
3630 // forgetting the partially-substituted parameter pack.
3631 if (RetainExpansion) {
3632 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3633 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003634 = getDerived().TransformFunctionTypeParam(OldParm,
3635 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003636 if (!NewParm)
3637 return true;
3638
3639 OutParamTypes.push_back(NewParm->getType());
3640 if (PVars)
3641 PVars->push_back(NewParm);
3642 }
3643
Douglas Gregor5499af42011-01-05 23:12:31 +00003644 // We're done with the pack expansion.
3645 continue;
3646 }
3647
3648 // We'll substitute the parameter now without expanding the pack
3649 // expansion.
3650 }
3651
3652 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003653 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3654 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003655 if (!NewParm)
3656 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003657
Douglas Gregordd472162011-01-07 00:20:55 +00003658 OutParamTypes.push_back(NewParm->getType());
3659 if (PVars)
3660 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003661 continue;
3662 }
John McCall58f10c32010-03-11 09:03:00 +00003663
3664 // Deal with the possibility that we don't have a parameter
3665 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003666 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003667 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003668 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003669 if (const PackExpansionType *Expansion
3670 = dyn_cast<PackExpansionType>(OldType)) {
3671 // We have a function parameter pack that may need to be expanded.
3672 QualType Pattern = Expansion->getPattern();
3673 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3674 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3675
3676 // Determine whether we should expand the parameter packs.
3677 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003678 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003679 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003680 Unexpanded.data(),
3681 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003682 ShouldExpand,
3683 RetainExpansion,
3684 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003685 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003686 }
3687
3688 if (ShouldExpand) {
3689 // Expand the function parameter pack into multiple, separate
3690 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003691 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003692 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3693 QualType NewType = getDerived().TransformType(Pattern);
3694 if (NewType.isNull())
3695 return true;
John McCall58f10c32010-03-11 09:03:00 +00003696
Douglas Gregordd472162011-01-07 00:20:55 +00003697 OutParamTypes.push_back(NewType);
3698 if (PVars)
3699 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003700 }
3701
3702 // We're done with the pack expansion.
3703 continue;
3704 }
3705
Douglas Gregor48d24112011-01-10 20:53:55 +00003706 // If we're supposed to retain a pack expansion, do so by temporarily
3707 // forgetting the partially-substituted parameter pack.
3708 if (RetainExpansion) {
3709 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3710 QualType NewType = getDerived().TransformType(Pattern);
3711 if (NewType.isNull())
3712 return true;
3713
3714 OutParamTypes.push_back(NewType);
3715 if (PVars)
3716 PVars->push_back(0);
3717 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003718
Douglas Gregor5499af42011-01-05 23:12:31 +00003719 // We'll substitute the parameter now without expanding the pack
3720 // expansion.
3721 OldType = Expansion->getPattern();
3722 IsPackExpansion = true;
3723 }
3724
3725 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3726 QualType NewType = getDerived().TransformType(OldType);
3727 if (NewType.isNull())
3728 return true;
3729
3730 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003731 NewType = getSema().Context.getPackExpansionType(NewType,
3732 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003733
Douglas Gregordd472162011-01-07 00:20:55 +00003734 OutParamTypes.push_back(NewType);
3735 if (PVars)
3736 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003737 }
3738
3739 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003740 }
John McCall58f10c32010-03-11 09:03:00 +00003741
3742template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003743QualType
John McCall550e0c22009-10-21 00:40:46 +00003744TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003745 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003746 // Transform the parameters and return type.
3747 //
3748 // We instantiate in source order, with the return type first followed by
3749 // the parameters, because users tend to expect this (even if they shouldn't
3750 // rely on it!).
3751 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003752 // When the function has a trailing return type, we instantiate the
3753 // parameters before the return type, since the return type can then refer
3754 // to the parameters themselves (via decltype, sizeof, etc.).
3755 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003756 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003757 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003758 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003759
Douglas Gregor7fb25412010-10-01 18:44:50 +00003760 QualType ResultType;
3761
3762 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003763 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3764 TL.getParmArray(),
3765 TL.getNumArgs(),
3766 TL.getTypePtr()->arg_type_begin(),
3767 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003768 return QualType();
3769
3770 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3771 if (ResultType.isNull())
3772 return QualType();
3773 }
3774 else {
3775 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3776 if (ResultType.isNull())
3777 return QualType();
3778
Douglas Gregordd472162011-01-07 00:20:55 +00003779 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3780 TL.getParmArray(),
3781 TL.getNumArgs(),
3782 TL.getTypePtr()->arg_type_begin(),
3783 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003784 return QualType();
3785 }
3786
John McCall550e0c22009-10-21 00:40:46 +00003787 QualType Result = TL.getType();
3788 if (getDerived().AlwaysRebuild() ||
3789 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003790 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003791 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3792 Result = getDerived().RebuildFunctionProtoType(ResultType,
3793 ParamTypes.data(),
3794 ParamTypes.size(),
3795 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003796 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003797 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003798 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003799 if (Result.isNull())
3800 return QualType();
3801 }
Mike Stump11289f42009-09-09 15:08:12 +00003802
John McCall550e0c22009-10-21 00:40:46 +00003803 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3804 NewTL.setLParenLoc(TL.getLParenLoc());
3805 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003806 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003807 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3808 NewTL.setArg(i, ParamDecls[i]);
3809
3810 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003811}
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregord6ff3322009-08-04 16:50:30 +00003813template<typename Derived>
3814QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003815 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003816 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003817 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003818 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3819 if (ResultType.isNull())
3820 return QualType();
3821
3822 QualType Result = TL.getType();
3823 if (getDerived().AlwaysRebuild() ||
3824 ResultType != T->getResultType())
3825 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3826
3827 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3828 NewTL.setLParenLoc(TL.getLParenLoc());
3829 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003830 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003831
3832 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003833}
Mike Stump11289f42009-09-09 15:08:12 +00003834
John McCallb96ec562009-12-04 22:46:56 +00003835template<typename Derived> QualType
3836TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003837 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003838 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003839 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003840 if (!D)
3841 return QualType();
3842
3843 QualType Result = TL.getType();
3844 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3845 Result = getDerived().RebuildUnresolvedUsingType(D);
3846 if (Result.isNull())
3847 return QualType();
3848 }
3849
3850 // We might get an arbitrary type spec type back. We should at
3851 // least always get a type spec type, though.
3852 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3853 NewTL.setNameLoc(TL.getNameLoc());
3854
3855 return Result;
3856}
3857
Douglas Gregord6ff3322009-08-04 16:50:30 +00003858template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003859QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003860 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003861 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003863 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3864 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003865 if (!Typedef)
3866 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003867
John McCall550e0c22009-10-21 00:40:46 +00003868 QualType Result = TL.getType();
3869 if (getDerived().AlwaysRebuild() ||
3870 Typedef != T->getDecl()) {
3871 Result = getDerived().RebuildTypedefType(Typedef);
3872 if (Result.isNull())
3873 return QualType();
3874 }
Mike Stump11289f42009-09-09 15:08:12 +00003875
John McCall550e0c22009-10-21 00:40:46 +00003876 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3877 NewTL.setNameLoc(TL.getNameLoc());
3878
3879 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003883QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003884 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003885 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003886 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003887
John McCalldadc5752010-08-24 06:29:42 +00003888 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003889 if (E.isInvalid())
3890 return QualType();
3891
John McCall550e0c22009-10-21 00:40:46 +00003892 QualType Result = TL.getType();
3893 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003894 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003895 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003896 if (Result.isNull())
3897 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003898 }
John McCall550e0c22009-10-21 00:40:46 +00003899 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003900
John McCall550e0c22009-10-21 00:40:46 +00003901 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003902 NewTL.setTypeofLoc(TL.getTypeofLoc());
3903 NewTL.setLParenLoc(TL.getLParenLoc());
3904 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003905
3906 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003907}
Mike Stump11289f42009-09-09 15:08:12 +00003908
3909template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003910QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003911 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003912 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3913 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3914 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003915 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003916
John McCall550e0c22009-10-21 00:40:46 +00003917 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003918 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3919 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003920 if (Result.isNull())
3921 return QualType();
3922 }
Mike Stump11289f42009-09-09 15:08:12 +00003923
John McCall550e0c22009-10-21 00:40:46 +00003924 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003925 NewTL.setTypeofLoc(TL.getTypeofLoc());
3926 NewTL.setLParenLoc(TL.getLParenLoc());
3927 NewTL.setRParenLoc(TL.getRParenLoc());
3928 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003929
3930 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003931}
Mike Stump11289f42009-09-09 15:08:12 +00003932
3933template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003934QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003935 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003936 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003937
Douglas Gregore922c772009-08-04 22:27:00 +00003938 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003939 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003940
John McCalldadc5752010-08-24 06:29:42 +00003941 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003942 if (E.isInvalid())
3943 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003944
John McCall550e0c22009-10-21 00:40:46 +00003945 QualType Result = TL.getType();
3946 if (getDerived().AlwaysRebuild() ||
3947 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003948 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003949 if (Result.isNull())
3950 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003951 }
John McCall550e0c22009-10-21 00:40:46 +00003952 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003953
John McCall550e0c22009-10-21 00:40:46 +00003954 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3955 NewTL.setNameLoc(TL.getNameLoc());
3956
3957 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003958}
3959
3960template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00003961QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
3962 AutoTypeLoc TL) {
3963 const AutoType *T = TL.getTypePtr();
3964 QualType OldDeduced = T->getDeducedType();
3965 QualType NewDeduced;
3966 if (!OldDeduced.isNull()) {
3967 NewDeduced = getDerived().TransformType(OldDeduced);
3968 if (NewDeduced.isNull())
3969 return QualType();
3970 }
3971
3972 QualType Result = TL.getType();
3973 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
3974 Result = getDerived().RebuildAutoType(NewDeduced);
3975 if (Result.isNull())
3976 return QualType();
3977 }
3978
3979 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
3980 NewTL.setNameLoc(TL.getNameLoc());
3981
3982 return Result;
3983}
3984
3985template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003986QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003987 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003988 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003990 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3991 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003992 if (!Record)
3993 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003994
John McCall550e0c22009-10-21 00:40:46 +00003995 QualType Result = TL.getType();
3996 if (getDerived().AlwaysRebuild() ||
3997 Record != T->getDecl()) {
3998 Result = getDerived().RebuildRecordType(Record);
3999 if (Result.isNull())
4000 return QualType();
4001 }
Mike Stump11289f42009-09-09 15:08:12 +00004002
John McCall550e0c22009-10-21 00:40:46 +00004003 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4004 NewTL.setNameLoc(TL.getNameLoc());
4005
4006 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004007}
Mike Stump11289f42009-09-09 15:08:12 +00004008
4009template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004010QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004011 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004012 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004013 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004014 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4015 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004016 if (!Enum)
4017 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004018
John McCall550e0c22009-10-21 00:40:46 +00004019 QualType Result = TL.getType();
4020 if (getDerived().AlwaysRebuild() ||
4021 Enum != T->getDecl()) {
4022 Result = getDerived().RebuildEnumType(Enum);
4023 if (Result.isNull())
4024 return QualType();
4025 }
Mike Stump11289f42009-09-09 15:08:12 +00004026
John McCall550e0c22009-10-21 00:40:46 +00004027 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4028 NewTL.setNameLoc(TL.getNameLoc());
4029
4030 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004031}
John McCallfcc33b02009-09-05 00:15:47 +00004032
John McCalle78aac42010-03-10 03:28:59 +00004033template<typename Derived>
4034QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4035 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004036 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004037 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4038 TL.getTypePtr()->getDecl());
4039 if (!D) return QualType();
4040
4041 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4042 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4043 return T;
4044}
4045
Douglas Gregord6ff3322009-08-04 16:50:30 +00004046template<typename Derived>
4047QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004048 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004049 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004050 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004051}
4052
Mike Stump11289f42009-09-09 15:08:12 +00004053template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004054QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004055 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004056 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004057 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004058}
4059
4060template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004061QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4062 TypeLocBuilder &TLB,
4063 SubstTemplateTypeParmPackTypeLoc TL) {
4064 return TransformTypeSpecType(TLB, TL);
4065}
4066
4067template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004068QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004069 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004070 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004071 const TemplateSpecializationType *T = TL.getTypePtr();
4072
Mike Stump11289f42009-09-09 15:08:12 +00004073 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004074 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004075 if (Template.isNull())
4076 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004077
John McCall31f82722010-11-12 08:19:04 +00004078 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4079}
4080
Douglas Gregorfe921a72010-12-20 23:36:19 +00004081namespace {
4082 /// \brief Simple iterator that traverses the template arguments in a
4083 /// container that provides a \c getArgLoc() member function.
4084 ///
4085 /// This iterator is intended to be used with the iterator form of
4086 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4087 template<typename ArgLocContainer>
4088 class TemplateArgumentLocContainerIterator {
4089 ArgLocContainer *Container;
4090 unsigned Index;
4091
4092 public:
4093 typedef TemplateArgumentLoc value_type;
4094 typedef TemplateArgumentLoc reference;
4095 typedef int difference_type;
4096 typedef std::input_iterator_tag iterator_category;
4097
4098 class pointer {
4099 TemplateArgumentLoc Arg;
4100
4101 public:
4102 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4103
4104 const TemplateArgumentLoc *operator->() const {
4105 return &Arg;
4106 }
4107 };
4108
4109
4110 TemplateArgumentLocContainerIterator() {}
4111
4112 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4113 unsigned Index)
4114 : Container(&Container), Index(Index) { }
4115
4116 TemplateArgumentLocContainerIterator &operator++() {
4117 ++Index;
4118 return *this;
4119 }
4120
4121 TemplateArgumentLocContainerIterator operator++(int) {
4122 TemplateArgumentLocContainerIterator Old(*this);
4123 ++(*this);
4124 return Old;
4125 }
4126
4127 TemplateArgumentLoc operator*() const {
4128 return Container->getArgLoc(Index);
4129 }
4130
4131 pointer operator->() const {
4132 return pointer(Container->getArgLoc(Index));
4133 }
4134
4135 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004136 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004137 return X.Container == Y.Container && X.Index == Y.Index;
4138 }
4139
4140 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004141 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004142 return !(X == Y);
4143 }
4144 };
4145}
4146
4147
John McCall31f82722010-11-12 08:19:04 +00004148template <typename Derived>
4149QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4150 TypeLocBuilder &TLB,
4151 TemplateSpecializationTypeLoc TL,
4152 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004153 TemplateArgumentListInfo NewTemplateArgs;
4154 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4155 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004156 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4157 ArgIterator;
4158 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4159 ArgIterator(TL, TL.getNumArgs()),
4160 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004161 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004162
John McCall0ad16662009-10-29 08:12:44 +00004163 // FIXME: maybe don't rebuild if all the template arguments are the same.
4164
4165 QualType Result =
4166 getDerived().RebuildTemplateSpecializationType(Template,
4167 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004168 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004169
4170 if (!Result.isNull()) {
4171 TemplateSpecializationTypeLoc NewTL
4172 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4173 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4174 NewTL.setLAngleLoc(TL.getLAngleLoc());
4175 NewTL.setRAngleLoc(TL.getRAngleLoc());
4176 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4177 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004178 }
Mike Stump11289f42009-09-09 15:08:12 +00004179
John McCall0ad16662009-10-29 08:12:44 +00004180 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004181}
Mike Stump11289f42009-09-09 15:08:12 +00004182
4183template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004184QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004185TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004186 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004187 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004188
4189 NestedNameSpecifier *NNS = 0;
4190 // NOTE: the qualifier in an ElaboratedType is optional.
4191 if (T->getQualifier() != 0) {
4192 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004193 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004194 if (!NNS)
4195 return QualType();
4196 }
Mike Stump11289f42009-09-09 15:08:12 +00004197
John McCall31f82722010-11-12 08:19:04 +00004198 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4199 if (NamedT.isNull())
4200 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004201
John McCall550e0c22009-10-21 00:40:46 +00004202 QualType Result = TL.getType();
4203 if (getDerived().AlwaysRebuild() ||
4204 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004205 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004206 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4207 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004208 if (Result.isNull())
4209 return QualType();
4210 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004211
Abramo Bagnara6150c882010-05-11 21:36:43 +00004212 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004213 NewTL.setKeywordLoc(TL.getKeywordLoc());
4214 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004215
4216 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004217}
Mike Stump11289f42009-09-09 15:08:12 +00004218
4219template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004220QualType TreeTransform<Derived>::TransformAttributedType(
4221 TypeLocBuilder &TLB,
4222 AttributedTypeLoc TL) {
4223 const AttributedType *oldType = TL.getTypePtr();
4224 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4225 if (modifiedType.isNull())
4226 return QualType();
4227
4228 QualType result = TL.getType();
4229
4230 // FIXME: dependent operand expressions?
4231 if (getDerived().AlwaysRebuild() ||
4232 modifiedType != oldType->getModifiedType()) {
4233 // TODO: this is really lame; we should really be rebuilding the
4234 // equivalent type from first principles.
4235 QualType equivalentType
4236 = getDerived().TransformType(oldType->getEquivalentType());
4237 if (equivalentType.isNull())
4238 return QualType();
4239 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4240 modifiedType,
4241 equivalentType);
4242 }
4243
4244 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4245 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4246 if (TL.hasAttrOperand())
4247 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4248 if (TL.hasAttrExprOperand())
4249 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4250 else if (TL.hasAttrEnumOperand())
4251 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4252
4253 return result;
4254}
4255
4256template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004257QualType
4258TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4259 ParenTypeLoc TL) {
4260 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4261 if (Inner.isNull())
4262 return QualType();
4263
4264 QualType Result = TL.getType();
4265 if (getDerived().AlwaysRebuild() ||
4266 Inner != TL.getInnerLoc().getType()) {
4267 Result = getDerived().RebuildParenType(Inner);
4268 if (Result.isNull())
4269 return QualType();
4270 }
4271
4272 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4273 NewTL.setLParenLoc(TL.getLParenLoc());
4274 NewTL.setRParenLoc(TL.getRParenLoc());
4275 return Result;
4276}
4277
4278template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004279QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004280 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004281 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004282
Douglas Gregord6ff3322009-08-04 16:50:30 +00004283 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004284 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004285 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286 if (!NNS)
4287 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004288
John McCallc392f372010-06-11 00:33:02 +00004289 QualType Result
4290 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4291 T->getIdentifier(),
4292 TL.getKeywordLoc(),
4293 TL.getQualifierRange(),
4294 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004295 if (Result.isNull())
4296 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004297
Abramo Bagnarad7548482010-05-19 21:37:53 +00004298 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4299 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004300 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4301
Abramo Bagnarad7548482010-05-19 21:37:53 +00004302 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4303 NewTL.setKeywordLoc(TL.getKeywordLoc());
4304 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004305 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004306 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4307 NewTL.setKeywordLoc(TL.getKeywordLoc());
4308 NewTL.setQualifierRange(TL.getQualifierRange());
4309 NewTL.setNameLoc(TL.getNameLoc());
4310 }
John McCall550e0c22009-10-21 00:40:46 +00004311 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004312}
Mike Stump11289f42009-09-09 15:08:12 +00004313
Douglas Gregord6ff3322009-08-04 16:50:30 +00004314template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004315QualType TreeTransform<Derived>::
4316 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004317 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004318 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004319
4320 NestedNameSpecifier *NNS
4321 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004322 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004323 if (!NNS)
4324 return QualType();
4325
John McCall31f82722010-11-12 08:19:04 +00004326 return getDerived()
4327 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4328}
4329
4330template<typename Derived>
4331QualType TreeTransform<Derived>::
4332 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4333 DependentTemplateSpecializationTypeLoc TL,
4334 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004335 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004336
John McCallc392f372010-06-11 00:33:02 +00004337 TemplateArgumentListInfo NewTemplateArgs;
4338 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4339 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004340
4341 typedef TemplateArgumentLocContainerIterator<
4342 DependentTemplateSpecializationTypeLoc> ArgIterator;
4343 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4344 ArgIterator(TL, TL.getNumArgs()),
4345 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004346 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004347
Douglas Gregora5614c52010-09-08 23:56:00 +00004348 QualType Result
4349 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4350 NNS,
4351 TL.getQualifierRange(),
4352 T->getIdentifier(),
4353 TL.getNameLoc(),
4354 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004355 if (Result.isNull())
4356 return QualType();
4357
4358 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4359 QualType NamedT = ElabT->getNamedType();
4360
4361 // Copy information relevant to the template specialization.
4362 TemplateSpecializationTypeLoc NamedTL
4363 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4364 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4365 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4366 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4367 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4368
4369 // Copy information relevant to the elaborated type.
4370 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4371 NewTL.setKeywordLoc(TL.getKeywordLoc());
4372 NewTL.setQualifierRange(TL.getQualifierRange());
4373 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004374 TypeLoc NewTL(Result, TL.getOpaqueData());
4375 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004376 }
4377 return Result;
4378}
4379
4380template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004381QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4382 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004383 QualType Pattern
4384 = getDerived().TransformType(TLB, TL.getPatternLoc());
4385 if (Pattern.isNull())
4386 return QualType();
4387
4388 QualType Result = TL.getType();
4389 if (getDerived().AlwaysRebuild() ||
4390 Pattern != TL.getPatternLoc().getType()) {
4391 Result = getDerived().RebuildPackExpansionType(Pattern,
4392 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004393 TL.getEllipsisLoc(),
4394 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004395 if (Result.isNull())
4396 return QualType();
4397 }
4398
4399 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4400 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4401 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004402}
4403
4404template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004405QualType
4406TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004407 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004408 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004409 TLB.pushFullCopy(TL);
4410 return TL.getType();
4411}
4412
4413template<typename Derived>
4414QualType
4415TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004416 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004417 // ObjCObjectType is never dependent.
4418 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004419 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004420}
Mike Stump11289f42009-09-09 15:08:12 +00004421
4422template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004423QualType
4424TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004425 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004426 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004427 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004428 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004429}
4430
Douglas Gregord6ff3322009-08-04 16:50:30 +00004431//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004432// Statement transformation
4433//===----------------------------------------------------------------------===//
4434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004435StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004436TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004437 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004438}
4439
4440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004441StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004442TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4443 return getDerived().TransformCompoundStmt(S, false);
4444}
4445
4446template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004447StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004448TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004449 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004450 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004451 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004452 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004453 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4454 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004455 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004456 if (Result.isInvalid()) {
4457 // Immediately fail if this was a DeclStmt, since it's very
4458 // likely that this will cause problems for future statements.
4459 if (isa<DeclStmt>(*B))
4460 return StmtError();
4461
4462 // Otherwise, just keep processing substatements and fail later.
4463 SubStmtInvalid = true;
4464 continue;
4465 }
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregorebe10102009-08-20 07:17:43 +00004467 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4468 Statements.push_back(Result.takeAs<Stmt>());
4469 }
Mike Stump11289f42009-09-09 15:08:12 +00004470
John McCall1ababa62010-08-27 19:56:05 +00004471 if (SubStmtInvalid)
4472 return StmtError();
4473
Douglas Gregorebe10102009-08-20 07:17:43 +00004474 if (!getDerived().AlwaysRebuild() &&
4475 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004476 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004477
4478 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4479 move_arg(Statements),
4480 S->getRBracLoc(),
4481 IsStmtExpr);
4482}
Mike Stump11289f42009-09-09 15:08:12 +00004483
Douglas Gregorebe10102009-08-20 07:17:43 +00004484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004485StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004486TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004487 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004488 {
4489 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004490 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004491
Eli Friedman06577382009-11-19 03:14:00 +00004492 // Transform the left-hand case value.
4493 LHS = getDerived().TransformExpr(S->getLHS());
4494 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004495 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004496
Eli Friedman06577382009-11-19 03:14:00 +00004497 // Transform the right-hand case value (for the GNU case-range extension).
4498 RHS = getDerived().TransformExpr(S->getRHS());
4499 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004500 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004501 }
Mike Stump11289f42009-09-09 15:08:12 +00004502
Douglas Gregorebe10102009-08-20 07:17:43 +00004503 // Build the case statement.
4504 // Case statements are always rebuilt so that they will attached to their
4505 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004506 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004507 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004508 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004509 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004510 S->getColonLoc());
4511 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004512 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004513
Douglas Gregorebe10102009-08-20 07:17:43 +00004514 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004515 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004516 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004517 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregorebe10102009-08-20 07:17:43 +00004519 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004520 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004521}
4522
4523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004524StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004525TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004526 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004527 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004528 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004529 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregorebe10102009-08-20 07:17:43 +00004531 // Default statements are always rebuilt
4532 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004533 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004534}
Mike Stump11289f42009-09-09 15:08:12 +00004535
Douglas Gregorebe10102009-08-20 07:17:43 +00004536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004537StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004538TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004539 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004540 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004541 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004542
Chris Lattnercab02a62011-02-17 20:34:02 +00004543 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4544 S->getDecl());
4545 if (!LD)
4546 return StmtError();
4547
4548
Douglas Gregorebe10102009-08-20 07:17:43 +00004549 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004550 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004551 cast<LabelDecl>(LD), SourceLocation(),
4552 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004553}
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregorebe10102009-08-20 07:17:43 +00004555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004556StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004557TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004558 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004559 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004560 VarDecl *ConditionVar = 0;
4561 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004562 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004563 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004564 getDerived().TransformDefinition(
4565 S->getConditionVariable()->getLocation(),
4566 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004567 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004568 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004569 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004570 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004571
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004572 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004573 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004574
4575 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004576 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004577 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4578 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004579 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004580 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004581
John McCallb268a282010-08-23 23:25:46 +00004582 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004583 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004584 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004585
John McCallb268a282010-08-23 23:25:46 +00004586 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4587 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004588 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004589
Douglas Gregorebe10102009-08-20 07:17:43 +00004590 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004591 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004592 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004593 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregorebe10102009-08-20 07:17:43 +00004595 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004596 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004597 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004598 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004599
Douglas Gregorebe10102009-08-20 07:17:43 +00004600 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004601 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004602 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004603 Then.get() == S->getThen() &&
4604 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004605 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004606
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004607 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004608 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004609 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004610}
4611
4612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004613StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004614TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004615 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004616 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004617 VarDecl *ConditionVar = 0;
4618 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004619 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004620 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004621 getDerived().TransformDefinition(
4622 S->getConditionVariable()->getLocation(),
4623 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004624 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004625 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004626 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004627 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004628
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004629 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004630 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004631 }
Mike Stump11289f42009-09-09 15:08:12 +00004632
Douglas Gregorebe10102009-08-20 07:17:43 +00004633 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004634 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004635 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004636 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004637 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004638 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004639
Douglas Gregorebe10102009-08-20 07:17:43 +00004640 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004641 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004642 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004643 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregorebe10102009-08-20 07:17:43 +00004645 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004646 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4647 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004648}
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregorebe10102009-08-20 07:17:43 +00004650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004651StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004652TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004653 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004654 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004655 VarDecl *ConditionVar = 0;
4656 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004657 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004658 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004659 getDerived().TransformDefinition(
4660 S->getConditionVariable()->getLocation(),
4661 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004662 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004663 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004664 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004665 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004666
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004667 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004668 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004669
4670 if (S->getCond()) {
4671 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004672 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4673 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004674 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004675 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004676 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004677 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004678 }
Mike Stump11289f42009-09-09 15:08:12 +00004679
John McCallb268a282010-08-23 23:25:46 +00004680 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4681 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004682 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004683
Douglas Gregorebe10102009-08-20 07:17:43 +00004684 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004685 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004686 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004688
Douglas Gregorebe10102009-08-20 07:17:43 +00004689 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004690 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004691 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004692 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004693 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004695 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004696 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregorebe10102009-08-20 07:17:43 +00004699template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004700StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004701TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004703 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004704 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004705 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004706
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004707 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004708 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004709 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004710 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004711
Douglas Gregorebe10102009-08-20 07:17:43 +00004712 if (!getDerived().AlwaysRebuild() &&
4713 Cond.get() == S->getCond() &&
4714 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004715 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004716
John McCallb268a282010-08-23 23:25:46 +00004717 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4718 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004719 S->getRParenLoc());
4720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregorebe10102009-08-20 07:17:43 +00004722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004723StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004724TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004725 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004726 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004727 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004728 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004729
Douglas Gregorebe10102009-08-20 07:17:43 +00004730 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004731 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004732 VarDecl *ConditionVar = 0;
4733 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004734 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004735 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004736 getDerived().TransformDefinition(
4737 S->getConditionVariable()->getLocation(),
4738 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004739 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004740 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004741 } else {
4742 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004743
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004744 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004745 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004746
4747 if (S->getCond()) {
4748 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004749 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4750 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004751 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004752 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004753
John McCallb268a282010-08-23 23:25:46 +00004754 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004755 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004756 }
Mike Stump11289f42009-09-09 15:08:12 +00004757
John McCallb268a282010-08-23 23:25:46 +00004758 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4759 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004760 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004761
Douglas Gregorebe10102009-08-20 07:17:43 +00004762 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004763 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004764 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004765 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004766
John McCallb268a282010-08-23 23:25:46 +00004767 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4768 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004769 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004770
Douglas Gregorebe10102009-08-20 07:17:43 +00004771 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004772 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 if (Body.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 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004778 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004779 Inc.get() == S->getInc() &&
4780 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004781 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregorebe10102009-08-20 07:17:43 +00004783 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004784 Init.get(), FullCond, ConditionVar,
4785 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004786}
4787
4788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004789StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004790TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004791 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4792 S->getLabel());
4793 if (!LD)
4794 return StmtError();
4795
Douglas Gregorebe10102009-08-20 07:17:43 +00004796 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004797 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004798 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004799}
4800
4801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004802StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004803TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004804 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004805 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004806 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregorebe10102009-08-20 07:17:43 +00004808 if (!getDerived().AlwaysRebuild() &&
4809 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004810 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004811
4812 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004813 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004814}
4815
4816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004817StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004818TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004819 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004820}
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregorebe10102009-08-20 07:17:43 +00004822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004823StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004824TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004825 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004826}
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregorebe10102009-08-20 07:17:43 +00004828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004829StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004830TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004831 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004832 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004833 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004834
Mike Stump11289f42009-09-09 15:08:12 +00004835 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004836 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004837 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004838}
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregorebe10102009-08-20 07:17:43 +00004840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004841StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004842TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004843 bool DeclChanged = false;
4844 llvm::SmallVector<Decl *, 4> Decls;
4845 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4846 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004847 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4848 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004849 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004850 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregorebe10102009-08-20 07:17:43 +00004852 if (Transformed != *D)
4853 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004854
Douglas Gregorebe10102009-08-20 07:17:43 +00004855 Decls.push_back(Transformed);
4856 }
Mike Stump11289f42009-09-09 15:08:12 +00004857
Douglas Gregorebe10102009-08-20 07:17:43 +00004858 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004859 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004860
4861 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004862 S->getStartLoc(), S->getEndLoc());
4863}
Mike Stump11289f42009-09-09 15:08:12 +00004864
Douglas Gregorebe10102009-08-20 07:17:43 +00004865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004866StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004867TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004868
John McCall37ad5512010-08-23 06:44:23 +00004869 ASTOwningVector<Expr*> Constraints(getSema());
4870 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004871 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004872
John McCalldadc5752010-08-24 06:29:42 +00004873 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004874 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004875
4876 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004877
Anders Carlssonaaeef072010-01-24 05:50:09 +00004878 // Go through the outputs.
4879 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004880 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004881
Anders Carlssonaaeef072010-01-24 05:50:09 +00004882 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004883 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004884
Anders Carlssonaaeef072010-01-24 05:50:09 +00004885 // Transform the output expr.
4886 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004887 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004888 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004889 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004890
Anders Carlssonaaeef072010-01-24 05:50:09 +00004891 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004892
John McCallb268a282010-08-23 23:25:46 +00004893 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004894 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004895
Anders Carlssonaaeef072010-01-24 05:50:09 +00004896 // Go through the inputs.
4897 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004898 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004899
Anders Carlssonaaeef072010-01-24 05:50:09 +00004900 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004901 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004902
Anders Carlssonaaeef072010-01-24 05:50:09 +00004903 // Transform the input expr.
4904 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004905 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004906 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004907 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004908
Anders Carlssonaaeef072010-01-24 05:50:09 +00004909 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004910
John McCallb268a282010-08-23 23:25:46 +00004911 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004912 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004913
Anders Carlssonaaeef072010-01-24 05:50:09 +00004914 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004915 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004916
4917 // Go through the clobbers.
4918 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004919 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004920
4921 // No need to transform the asm string literal.
4922 AsmString = SemaRef.Owned(S->getAsmString());
4923
4924 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4925 S->isSimple(),
4926 S->isVolatile(),
4927 S->getNumOutputs(),
4928 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004929 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004930 move_arg(Constraints),
4931 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004932 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004933 move_arg(Clobbers),
4934 S->getRParenLoc(),
4935 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004936}
4937
4938
4939template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004940StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004941TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004942 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004943 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004944 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004945 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004946
Douglas Gregor96c79492010-04-23 22:50:49 +00004947 // Transform the @catch statements (if present).
4948 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004949 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004950 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004951 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004952 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004953 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004954 if (Catch.get() != S->getCatchStmt(I))
4955 AnyCatchChanged = true;
4956 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004957 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004958
Douglas Gregor306de2f2010-04-22 23:59:56 +00004959 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004960 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004961 if (S->getFinallyStmt()) {
4962 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4963 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004964 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004965 }
4966
4967 // If nothing changed, just retain this statement.
4968 if (!getDerived().AlwaysRebuild() &&
4969 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004970 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004971 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004972 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004973
Douglas Gregor306de2f2010-04-22 23:59:56 +00004974 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004975 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4976 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004977}
Mike Stump11289f42009-09-09 15:08:12 +00004978
Douglas Gregorebe10102009-08-20 07:17:43 +00004979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004981TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004982 // Transform the @catch parameter, if there is one.
4983 VarDecl *Var = 0;
4984 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4985 TypeSourceInfo *TSInfo = 0;
4986 if (FromVar->getTypeSourceInfo()) {
4987 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4988 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004990 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004991
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004992 QualType T;
4993 if (TSInfo)
4994 T = TSInfo->getType();
4995 else {
4996 T = getDerived().TransformType(FromVar->getType());
4997 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004998 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004999 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005000
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005001 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5002 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005003 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005004 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005005
John McCalldadc5752010-08-24 06:29:42 +00005006 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005007 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005008 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005009
5010 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005011 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005012 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005013}
Mike Stump11289f42009-09-09 15:08:12 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005016StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005017TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005018 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005019 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005020 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005021 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005022
Douglas Gregor306de2f2010-04-22 23:59:56 +00005023 // If nothing changed, just retain this statement.
5024 if (!getDerived().AlwaysRebuild() &&
5025 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005026 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005027
5028 // Build a new statement.
5029 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005030 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregorebe10102009-08-20 07:17:43 +00005033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005034StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005035TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005036 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005037 if (S->getThrowExpr()) {
5038 Operand = getDerived().TransformExpr(S->getThrowExpr());
5039 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005040 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005041 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005042
Douglas Gregor2900c162010-04-22 21:44:01 +00005043 if (!getDerived().AlwaysRebuild() &&
5044 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005045 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005046
John McCallb268a282010-08-23 23:25:46 +00005047 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005048}
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregorebe10102009-08-20 07:17:43 +00005050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005051StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005052TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005053 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005054 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005055 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005056 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005057 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005058
Douglas Gregor6148de72010-04-22 22:01:21 +00005059 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005060 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005061 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005062 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005063
Douglas Gregor6148de72010-04-22 22:01:21 +00005064 // If nothing change, just retain the current statement.
5065 if (!getDerived().AlwaysRebuild() &&
5066 Object.get() == S->getSynchExpr() &&
5067 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005068 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005069
5070 // Build a new statement.
5071 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005072 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005073}
5074
5075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005076StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005077TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005078 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005079 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005080 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005081 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005082 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005083
Douglas Gregorf68a5082010-04-22 23:10:45 +00005084 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005085 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005086 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005087 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005088
Douglas Gregorf68a5082010-04-22 23:10:45 +00005089 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005090 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005091 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005092 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005093
Douglas Gregorf68a5082010-04-22 23:10:45 +00005094 // If nothing changed, just retain this statement.
5095 if (!getDerived().AlwaysRebuild() &&
5096 Element.get() == S->getElement() &&
5097 Collection.get() == S->getCollection() &&
5098 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005099 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005100
Douglas Gregorf68a5082010-04-22 23:10:45 +00005101 // Build a new statement.
5102 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5103 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005104 Element.get(),
5105 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005106 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005107 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005108}
5109
5110
5111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005112StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005113TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5114 // Transform the exception declaration, if any.
5115 VarDecl *Var = 0;
5116 if (S->getExceptionDecl()) {
5117 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005118 TypeSourceInfo *T = getDerived().TransformType(
5119 ExceptionDecl->getTypeSourceInfo());
5120 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005121 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005123 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005124 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005125 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005126 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005127 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005128 }
Mike Stump11289f42009-09-09 15:08:12 +00005129
Douglas Gregorebe10102009-08-20 07:17:43 +00005130 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005131 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005132 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005133 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregorebe10102009-08-20 07:17:43 +00005135 if (!getDerived().AlwaysRebuild() &&
5136 !Var &&
5137 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005138 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005139
5140 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5141 Var,
John McCallb268a282010-08-23 23:25:46 +00005142 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005143}
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregorebe10102009-08-20 07:17:43 +00005145template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005146StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005147TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5148 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005149 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005150 = getDerived().TransformCompoundStmt(S->getTryBlock());
5151 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005152 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregorebe10102009-08-20 07:17:43 +00005154 // Transform the handlers.
5155 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005156 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005157 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005158 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005159 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5160 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005161 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregorebe10102009-08-20 07:17:43 +00005163 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5164 Handlers.push_back(Handler.takeAs<Stmt>());
5165 }
Mike Stump11289f42009-09-09 15:08:12 +00005166
Douglas Gregorebe10102009-08-20 07:17:43 +00005167 if (!getDerived().AlwaysRebuild() &&
5168 TryBlock.get() == S->getTryBlock() &&
5169 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005170 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005171
John McCallb268a282010-08-23 23:25:46 +00005172 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005173 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005174}
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregorebe10102009-08-20 07:17:43 +00005176//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005177// Expression transformation
5178//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005180ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005181TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005182 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005183}
Mike Stump11289f42009-09-09 15:08:12 +00005184
5185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005186ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005187TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005188 NestedNameSpecifier *Qualifier = 0;
5189 if (E->getQualifier()) {
5190 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005191 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005192 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005193 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005194 }
John McCallce546572009-12-08 09:08:17 +00005195
5196 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005197 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5198 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005199 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005200 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005201
John McCall815039a2010-08-17 21:27:17 +00005202 DeclarationNameInfo NameInfo = E->getNameInfo();
5203 if (NameInfo.getName()) {
5204 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5205 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005206 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005207 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005208
5209 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005210 Qualifier == E->getQualifier() &&
5211 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005212 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005213 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005214
5215 // Mark it referenced in the new context regardless.
5216 // FIXME: this is a bit instantiation-specific.
5217 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5218
John McCallc3007a22010-10-26 07:05:15 +00005219 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005220 }
John McCallce546572009-12-08 09:08:17 +00005221
5222 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005223 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005224 TemplateArgs = &TransArgs;
5225 TransArgs.setLAngleLoc(E->getLAngleLoc());
5226 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005227 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5228 E->getNumTemplateArgs(),
5229 TransArgs))
5230 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005231 }
5232
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005233 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005234 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005235}
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregora16548e2009-08-11 05:31:07 +00005237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005238ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005239TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005240 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005245TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005246 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005247}
Mike Stump11289f42009-09-09 15:08:12 +00005248
Douglas Gregora16548e2009-08-11 05:31:07 +00005249template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005250ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005251TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005252 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005253}
Mike Stump11289f42009-09-09 15:08:12 +00005254
Douglas Gregora16548e2009-08-11 05:31:07 +00005255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005257TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005258 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregora16548e2009-08-11 05:31:07 +00005261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005262ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005263TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005264 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005265}
5266
5267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005269TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005270 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005275 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005276
John McCallb268a282010-08-23 23:25:46 +00005277 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005278 E->getRParen());
5279}
5280
Mike Stump11289f42009-09-09 15:08:12 +00005281template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005282ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005283TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005284 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005285 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005289 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005290
Douglas Gregora16548e2009-08-11 05:31:07 +00005291 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5292 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005293 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005294}
Mike Stump11289f42009-09-09 15:08:12 +00005295
Douglas Gregora16548e2009-08-11 05:31:07 +00005296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005297ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005298TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5299 // Transform the type.
5300 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5301 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005302 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005303
Douglas Gregor882211c2010-04-28 22:16:22 +00005304 // Transform all of the components into components similar to what the
5305 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005306 // FIXME: It would be slightly more efficient in the non-dependent case to
5307 // just map FieldDecls, rather than requiring the rebuilder to look for
5308 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005309 // template code that we don't care.
5310 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005311 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005312 typedef OffsetOfExpr::OffsetOfNode Node;
5313 llvm::SmallVector<Component, 4> Components;
5314 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5315 const Node &ON = E->getComponent(I);
5316 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005317 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005318 Comp.LocStart = ON.getRange().getBegin();
5319 Comp.LocEnd = ON.getRange().getEnd();
5320 switch (ON.getKind()) {
5321 case Node::Array: {
5322 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005323 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005324 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005325 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005326
Douglas Gregor882211c2010-04-28 22:16:22 +00005327 ExprChanged = ExprChanged || Index.get() != FromIndex;
5328 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005329 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005330 break;
5331 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005332
Douglas Gregor882211c2010-04-28 22:16:22 +00005333 case Node::Field:
5334 case Node::Identifier:
5335 Comp.isBrackets = false;
5336 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005337 if (!Comp.U.IdentInfo)
5338 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005339
Douglas Gregor882211c2010-04-28 22:16:22 +00005340 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005341
Douglas Gregord1702062010-04-29 00:18:15 +00005342 case Node::Base:
5343 // Will be recomputed during the rebuild.
5344 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005346
Douglas Gregor882211c2010-04-28 22:16:22 +00005347 Components.push_back(Comp);
5348 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005349
Douglas Gregor882211c2010-04-28 22:16:22 +00005350 // If nothing changed, retain the existing expression.
5351 if (!getDerived().AlwaysRebuild() &&
5352 Type == E->getTypeSourceInfo() &&
5353 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005354 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005355
Douglas Gregor882211c2010-04-28 22:16:22 +00005356 // Build a new offsetof expression.
5357 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5358 Components.data(), Components.size(),
5359 E->getRParenLoc());
5360}
5361
5362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005363ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005364TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5365 assert(getDerived().AlreadyTransformed(E->getType()) &&
5366 "opaque value expression requires transformation");
5367 return SemaRef.Owned(E);
5368}
5369
5370template<typename Derived>
5371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005372TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005373 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005374 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005375
John McCallbcd03502009-12-07 02:54:59 +00005376 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005377 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005378 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005379
John McCall4c98fd82009-11-04 07:28:41 +00005380 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005381 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005382
John McCall4c98fd82009-11-04 07:28:41 +00005383 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005384 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 E->getSourceRange());
5386 }
Mike Stump11289f42009-09-09 15:08:12 +00005387
John McCalldadc5752010-08-24 06:29:42 +00005388 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005389 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005390 // C++0x [expr.sizeof]p1:
5391 // The operand is either an expression, which is an unevaluated operand
5392 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005393 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005394
Douglas Gregora16548e2009-08-11 05:31:07 +00005395 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5396 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005398
Douglas Gregora16548e2009-08-11 05:31:07 +00005399 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005400 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005401 }
Mike Stump11289f42009-09-09 15:08:12 +00005402
John McCallb268a282010-08-23 23:25:46 +00005403 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 E->isSizeOf(),
5405 E->getSourceRange());
5406}
Mike Stump11289f42009-09-09 15:08:12 +00005407
Douglas Gregora16548e2009-08-11 05:31:07 +00005408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005410TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005411 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005412 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005414
John McCalldadc5752010-08-24 06:29:42 +00005415 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005416 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005418
5419
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 if (!getDerived().AlwaysRebuild() &&
5421 LHS.get() == E->getLHS() &&
5422 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005423 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005424
John McCallb268a282010-08-23 23:25:46 +00005425 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005426 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005427 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 E->getRBracketLoc());
5429}
Mike Stump11289f42009-09-09 15:08:12 +00005430
5431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005433TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005434 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005435 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005436 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005437 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005438
5439 // Transform arguments.
5440 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005441 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005442 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5443 &ArgChanged))
5444 return ExprError();
5445
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 if (!getDerived().AlwaysRebuild() &&
5447 Callee.get() == E->getCallee() &&
5448 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005449 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005450
Douglas Gregora16548e2009-08-11 05:31:07 +00005451 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005452 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005454 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005455 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005456 E->getRParenLoc());
5457}
Mike Stump11289f42009-09-09 15:08:12 +00005458
5459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005460ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005461TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005462 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005466 NestedNameSpecifier *Qualifier = 0;
5467 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005468 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005469 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005470 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005471 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005472 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005473 }
Mike Stump11289f42009-09-09 15:08:12 +00005474
Eli Friedman2cfcef62009-12-04 06:40:45 +00005475 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005476 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5477 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005478 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005479 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005480
John McCall16df1e52010-03-30 21:47:33 +00005481 NamedDecl *FoundDecl = E->getFoundDecl();
5482 if (FoundDecl == E->getMemberDecl()) {
5483 FoundDecl = Member;
5484 } else {
5485 FoundDecl = cast_or_null<NamedDecl>(
5486 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5487 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005488 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005489 }
5490
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 if (!getDerived().AlwaysRebuild() &&
5492 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005493 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005494 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005495 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005496 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005497
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005498 // Mark it referenced in the new context regardless.
5499 // FIXME: this is a bit instantiation-specific.
5500 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005501 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005502 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005503
John McCall6b51f282009-11-23 01:53:49 +00005504 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005505 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005506 TransArgs.setLAngleLoc(E->getLAngleLoc());
5507 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005508 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5509 E->getNumTemplateArgs(),
5510 TransArgs))
5511 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005512 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005513
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 // FIXME: Bogus source location for the operator
5515 SourceLocation FakeOperatorLoc
5516 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5517
John McCall38836f02010-01-15 08:34:02 +00005518 // FIXME: to do this check properly, we will need to preserve the
5519 // first-qualifier-in-scope here, just in case we had a dependent
5520 // base (and therefore couldn't do the check) and a
5521 // nested-name-qualifier (and therefore could do the lookup).
5522 NamedDecl *FirstQualifierInScope = 0;
5523
John McCallb268a282010-08-23 23:25:46 +00005524 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005525 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005526 Qualifier,
5527 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005528 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005529 Member,
John McCall16df1e52010-03-30 21:47:33 +00005530 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005531 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005532 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005533 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005534}
Mike Stump11289f42009-09-09 15:08:12 +00005535
Douglas Gregora16548e2009-08-11 05:31:07 +00005536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005538TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005539 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005540 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005541 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005542
John McCalldadc5752010-08-24 06:29:42 +00005543 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregora16548e2009-08-11 05:31:07 +00005547 if (!getDerived().AlwaysRebuild() &&
5548 LHS.get() == E->getLHS() &&
5549 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005550 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005553 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005554}
5555
Mike Stump11289f42009-09-09 15:08:12 +00005556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005557ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005558TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005559 CompoundAssignOperator *E) {
5560 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005561}
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregora16548e2009-08-11 05:31:07 +00005563template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005564ExprResult TreeTransform<Derived>::
5565TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5566 // Just rebuild the common and RHS expressions and see whether we
5567 // get any changes.
5568
5569 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5570 if (commonExpr.isInvalid())
5571 return ExprError();
5572
5573 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5574 if (rhs.isInvalid())
5575 return ExprError();
5576
5577 if (!getDerived().AlwaysRebuild() &&
5578 commonExpr.get() == e->getCommon() &&
5579 rhs.get() == e->getFalseExpr())
5580 return SemaRef.Owned(e);
5581
5582 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5583 e->getQuestionLoc(),
5584 0,
5585 e->getColonLoc(),
5586 rhs.get());
5587}
5588
5589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005591TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005592 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005593 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005595
John McCalldadc5752010-08-24 06:29:42 +00005596 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005598 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005599
John McCalldadc5752010-08-24 06:29:42 +00005600 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 if (!getDerived().AlwaysRebuild() &&
5605 Cond.get() == E->getCond() &&
5606 LHS.get() == E->getLHS() &&
5607 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005608 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005609
John McCallb268a282010-08-23 23:25:46 +00005610 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005611 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005612 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005613 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005614 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005615}
Mike Stump11289f42009-09-09 15:08:12 +00005616
5617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005619TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005620 // Implicit casts are eliminated during transformation, since they
5621 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005622 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005623}
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregora16548e2009-08-11 05:31:07 +00005625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005627TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005628 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5629 if (!Type)
5630 return ExprError();
5631
John McCalldadc5752010-08-24 06:29:42 +00005632 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005633 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005635 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005638 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005640 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005641
John McCall97513962010-01-15 18:39:57 +00005642 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005643 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005644 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005645 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005646}
Mike Stump11289f42009-09-09 15:08:12 +00005647
Douglas Gregora16548e2009-08-11 05:31:07 +00005648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005650TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005651 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5652 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5653 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005654 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005655
John McCalldadc5752010-08-24 06:29:42 +00005656 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005658 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005659
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005661 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005663 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005664
John McCall5d7aa7f2010-01-19 22:33:45 +00005665 // Note: the expression type doesn't necessarily match the
5666 // type-as-written, but that's okay, because it should always be
5667 // derivable from the initializer.
5668
John McCalle15bbff2010-01-18 19:35:47 +00005669 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005671 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005672}
Mike Stump11289f42009-09-09 15:08:12 +00005673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005677 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005679 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005680
Douglas Gregora16548e2009-08-11 05:31:07 +00005681 if (!getDerived().AlwaysRebuild() &&
5682 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005683 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005684
Douglas Gregora16548e2009-08-11 05:31:07 +00005685 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005686 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005688 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 E->getAccessorLoc(),
5690 E->getAccessor());
5691}
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregora16548e2009-08-11 05:31:07 +00005693template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005694ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005695TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005697
John McCall37ad5512010-08-23 06:44:23 +00005698 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005699 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5700 Inits, &InitChanged))
5701 return ExprError();
5702
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005704 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005707 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005708}
Mike Stump11289f42009-09-09 15:08:12 +00005709
Douglas Gregora16548e2009-08-11 05:31:07 +00005710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005711ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005712TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005713 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregorebe10102009-08-20 07:17:43 +00005715 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005716 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005717 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005718 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005719
Douglas Gregorebe10102009-08-20 07:17:43 +00005720 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005721 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005722 bool ExprChanged = false;
5723 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5724 DEnd = E->designators_end();
5725 D != DEnd; ++D) {
5726 if (D->isFieldDesignator()) {
5727 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5728 D->getDotLoc(),
5729 D->getFieldLoc()));
5730 continue;
5731 }
Mike Stump11289f42009-09-09 15:08:12 +00005732
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005734 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005737
5738 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005739 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5742 ArrayExprs.push_back(Index.release());
5743 continue;
5744 }
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005747 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005748 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5749 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005751
John McCalldadc5752010-08-24 06:29:42 +00005752 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005755
5756 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005757 End.get(),
5758 D->getLBracketLoc(),
5759 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005760
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5762 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005763
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 ArrayExprs.push_back(Start.release());
5765 ArrayExprs.push_back(End.release());
5766 }
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 if (!getDerived().AlwaysRebuild() &&
5769 Init.get() == E->getInit() &&
5770 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005771 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005772
Douglas Gregora16548e2009-08-11 05:31:07 +00005773 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5774 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005775 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005776}
Mike Stump11289f42009-09-09 15:08:12 +00005777
Douglas Gregora16548e2009-08-11 05:31:07 +00005778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005779ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005780TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005781 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005782 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005783
Douglas Gregor3da3c062009-10-28 00:29:27 +00005784 // FIXME: Will we ever have proper type location here? Will we actually
5785 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 QualType T = getDerived().TransformType(E->getType());
5787 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005789
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 if (!getDerived().AlwaysRebuild() &&
5791 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005792 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794 return getDerived().RebuildImplicitValueInitExpr(T);
5795}
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005799TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005800 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5801 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005802 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005803
John McCalldadc5752010-08-24 06:29:42 +00005804 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005809 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005810 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005811 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005812
John McCallb268a282010-08-23 23:25:46 +00005813 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005814 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005815}
5816
5817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005818ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005819TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005821 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005822 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5823 &ArgumentChanged))
5824 return ExprError();
5825
Douglas Gregora16548e2009-08-11 05:31:07 +00005826 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5827 move_arg(Inits),
5828 E->getRParenLoc());
5829}
Mike Stump11289f42009-09-09 15:08:12 +00005830
Douglas Gregora16548e2009-08-11 05:31:07 +00005831/// \brief Transform an address-of-label expression.
5832///
5833/// By default, the transformation of an address-of-label expression always
5834/// rebuilds the expression, so that the label identifier can be resolved to
5835/// the corresponding label statement by semantic analysis.
5836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005838TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005839 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
5840 E->getLabel());
5841 if (!LD)
5842 return ExprError();
5843
Douglas Gregora16548e2009-08-11 05:31:07 +00005844 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005845 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00005846}
Mike Stump11289f42009-09-09 15:08:12 +00005847
5848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005850TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005851 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005852 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5853 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005855
Douglas Gregora16548e2009-08-11 05:31:07 +00005856 if (!getDerived().AlwaysRebuild() &&
5857 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005858 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005859
5860 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005861 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 E->getRParenLoc());
5863}
Mike Stump11289f42009-09-09 15:08:12 +00005864
Douglas Gregora16548e2009-08-11 05:31:07 +00005865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005867TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005868 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005869 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005871
John McCalldadc5752010-08-24 06:29:42 +00005872 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005873 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005875
John McCalldadc5752010-08-24 06:29:42 +00005876 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005879
Douglas Gregora16548e2009-08-11 05:31:07 +00005880 if (!getDerived().AlwaysRebuild() &&
5881 Cond.get() == E->getCond() &&
5882 LHS.get() == E->getLHS() &&
5883 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005884 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005887 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005888 E->getRParenLoc());
5889}
Mike Stump11289f42009-09-09 15:08:12 +00005890
Douglas Gregora16548e2009-08-11 05:31:07 +00005891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005893TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005894 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005895}
5896
5897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005899TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005900 switch (E->getOperator()) {
5901 case OO_New:
5902 case OO_Delete:
5903 case OO_Array_New:
5904 case OO_Array_Delete:
5905 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005906 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005907
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005908 case OO_Call: {
5909 // This is a call to an object's operator().
5910 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5911
5912 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005913 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005914 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005915 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005916
5917 // FIXME: Poor location information
5918 SourceLocation FakeLParenLoc
5919 = SemaRef.PP.getLocForEndOfToken(
5920 static_cast<Expr *>(Object.get())->getLocEnd());
5921
5922 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005923 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005924 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5925 Args))
5926 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005927
John McCallb268a282010-08-23 23:25:46 +00005928 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005929 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005930 E->getLocEnd());
5931 }
5932
5933#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5934 case OO_##Name:
5935#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5936#include "clang/Basic/OperatorKinds.def"
5937 case OO_Subscript:
5938 // Handled below.
5939 break;
5940
5941 case OO_Conditional:
5942 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005943 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005944
5945 case OO_None:
5946 case NUM_OVERLOADED_OPERATORS:
5947 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005948 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005949 }
5950
John McCalldadc5752010-08-24 06:29:42 +00005951 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005952 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005953 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005954
John McCalldadc5752010-08-24 06:29:42 +00005955 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005956 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005957 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005958
John McCalldadc5752010-08-24 06:29:42 +00005959 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005960 if (E->getNumArgs() == 2) {
5961 Second = getDerived().TransformExpr(E->getArg(1));
5962 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005963 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005964 }
Mike Stump11289f42009-09-09 15:08:12 +00005965
Douglas Gregora16548e2009-08-11 05:31:07 +00005966 if (!getDerived().AlwaysRebuild() &&
5967 Callee.get() == E->getCallee() &&
5968 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005969 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005970 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005971
Douglas Gregora16548e2009-08-11 05:31:07 +00005972 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5973 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005974 Callee.get(),
5975 First.get(),
5976 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005977}
Mike Stump11289f42009-09-09 15:08:12 +00005978
Douglas Gregora16548e2009-08-11 05:31:07 +00005979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005980ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5982 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005983}
Mike Stump11289f42009-09-09 15:08:12 +00005984
Douglas Gregora16548e2009-08-11 05:31:07 +00005985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005986ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00005987TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
5988 // Transform the callee.
5989 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5990 if (Callee.isInvalid())
5991 return ExprError();
5992
5993 // Transform exec config.
5994 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
5995 if (EC.isInvalid())
5996 return ExprError();
5997
5998 // Transform arguments.
5999 bool ArgChanged = false;
6000 ASTOwningVector<Expr*> Args(SemaRef);
6001 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6002 &ArgChanged))
6003 return ExprError();
6004
6005 if (!getDerived().AlwaysRebuild() &&
6006 Callee.get() == E->getCallee() &&
6007 !ArgChanged)
6008 return SemaRef.Owned(E);
6009
6010 // FIXME: Wrong source location information for the '('.
6011 SourceLocation FakeLParenLoc
6012 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6013 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6014 move_arg(Args),
6015 E->getRParenLoc(), EC.get());
6016}
6017
6018template<typename Derived>
6019ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006020TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006021 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6022 if (!Type)
6023 return ExprError();
6024
John McCalldadc5752010-08-24 06:29:42 +00006025 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006026 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006028 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006029
Douglas Gregora16548e2009-08-11 05:31:07 +00006030 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006031 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006033 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006036 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006037 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6038 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6039 SourceLocation FakeRParenLoc
6040 = SemaRef.PP.getLocForEndOfToken(
6041 E->getSubExpr()->getSourceRange().getEnd());
6042 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006043 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006045 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 FakeRAngleLoc,
6047 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006048 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 FakeRParenLoc);
6050}
Mike Stump11289f42009-09-09 15:08:12 +00006051
Douglas Gregora16548e2009-08-11 05:31:07 +00006052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006053ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006054TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6055 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006056}
Mike Stump11289f42009-09-09 15:08:12 +00006057
6058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006059ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006060TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6061 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006062}
6063
Douglas Gregora16548e2009-08-11 05:31:07 +00006064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006065ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006066TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006067 CXXReinterpretCastExpr *E) {
6068 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006069}
Mike Stump11289f42009-09-09 15:08:12 +00006070
Douglas Gregora16548e2009-08-11 05:31:07 +00006071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006073TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6074 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006075}
Mike Stump11289f42009-09-09 15:08:12 +00006076
Douglas Gregora16548e2009-08-11 05:31:07 +00006077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006078ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006079TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006080 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006081 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6082 if (!Type)
6083 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006084
John McCalldadc5752010-08-24 06:29:42 +00006085 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006086 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006087 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006089
Douglas Gregora16548e2009-08-11 05:31:07 +00006090 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006091 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006092 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006093 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006095 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006096 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006097 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006098 E->getRParenLoc());
6099}
Mike Stump11289f42009-09-09 15:08:12 +00006100
Douglas Gregora16548e2009-08-11 05:31:07 +00006101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006103TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006105 TypeSourceInfo *TInfo
6106 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6107 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006108 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006109
Douglas Gregora16548e2009-08-11 05:31:07 +00006110 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006111 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006112 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregor9da64192010-04-26 22:37:10 +00006114 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6115 E->getLocStart(),
6116 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 E->getLocEnd());
6118 }
Mike Stump11289f42009-09-09 15:08:12 +00006119
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 // We don't know whether the expression is potentially evaluated until
6121 // after we perform semantic analysis, so the expression is potentially
6122 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006123 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006124 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006125
John McCalldadc5752010-08-24 06:29:42 +00006126 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006127 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregora16548e2009-08-11 05:31:07 +00006130 if (!getDerived().AlwaysRebuild() &&
6131 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregor9da64192010-04-26 22:37:10 +00006134 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6135 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006136 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 E->getLocEnd());
6138}
6139
6140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006141ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006142TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6143 if (E->isTypeOperand()) {
6144 TypeSourceInfo *TInfo
6145 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6146 if (!TInfo)
6147 return ExprError();
6148
6149 if (!getDerived().AlwaysRebuild() &&
6150 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006151 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006152
6153 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6154 E->getLocStart(),
6155 TInfo,
6156 E->getLocEnd());
6157 }
6158
6159 // We don't know whether the expression is potentially evaluated until
6160 // after we perform semantic analysis, so the expression is potentially
6161 // potentially evaluated.
6162 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6163
6164 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6165 if (SubExpr.isInvalid())
6166 return ExprError();
6167
6168 if (!getDerived().AlwaysRebuild() &&
6169 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006170 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006171
6172 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6173 E->getLocStart(),
6174 SubExpr.get(),
6175 E->getLocEnd());
6176}
6177
6178template<typename Derived>
6179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006180TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006181 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006182}
Mike Stump11289f42009-09-09 15:08:12 +00006183
Douglas Gregora16548e2009-08-11 05:31:07 +00006184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006185ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006186TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006187 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006188 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006189}
Mike Stump11289f42009-09-09 15:08:12 +00006190
Douglas Gregora16548e2009-08-11 05:31:07 +00006191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006192ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006193TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006194 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6195 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6196 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006198 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006200
Douglas Gregorb15af892010-01-07 23:12:05 +00006201 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006202}
Mike Stump11289f42009-09-09 15:08:12 +00006203
Douglas Gregora16548e2009-08-11 05:31:07 +00006204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006207 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006210
Douglas Gregora16548e2009-08-11 05:31:07 +00006211 if (!getDerived().AlwaysRebuild() &&
6212 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006213 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006214
John McCallb268a282010-08-23 23:25:46 +00006215 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006216}
Mike Stump11289f42009-09-09 15:08:12 +00006217
Douglas Gregora16548e2009-08-11 05:31:07 +00006218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006219ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006220TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006221 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006222 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6223 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006224 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006225 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006226
Chandler Carruth794da4c2010-02-08 06:42:49 +00006227 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006228 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006229 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregor033f6752009-12-23 23:03:06 +00006231 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006235ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006236TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6237 CXXScalarValueInitExpr *E) {
6238 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6239 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006240 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006241
Douglas Gregora16548e2009-08-11 05:31:07 +00006242 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006243 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006244 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006245
Douglas Gregor2b88c112010-09-08 00:15:04 +00006246 return getDerived().RebuildCXXScalarValueInitExpr(T,
6247 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006248 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006249}
Mike Stump11289f42009-09-09 15:08:12 +00006250
Douglas Gregora16548e2009-08-11 05:31:07 +00006251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006253TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006255 TypeSourceInfo *AllocTypeInfo
6256 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6257 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006261 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregora16548e2009-08-11 05:31:07 +00006265 // Transform the placement arguments (if any).
6266 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006267 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006268 if (getDerived().TransformExprs(E->getPlacementArgs(),
6269 E->getNumPlacementArgs(), true,
6270 PlacementArgs, &ArgumentChanged))
6271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregorebe10102009-08-20 07:17:43 +00006273 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006274 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006275 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6276 ConstructorArgs, &ArgumentChanged))
6277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006278
Douglas Gregord2d9da02010-02-26 00:38:10 +00006279 // Transform constructor, new operator, and delete operator.
6280 CXXConstructorDecl *Constructor = 0;
6281 if (E->getConstructor()) {
6282 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006283 getDerived().TransformDecl(E->getLocStart(),
6284 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006285 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006286 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006287 }
6288
6289 FunctionDecl *OperatorNew = 0;
6290 if (E->getOperatorNew()) {
6291 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006292 getDerived().TransformDecl(E->getLocStart(),
6293 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006294 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006295 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006296 }
6297
6298 FunctionDecl *OperatorDelete = 0;
6299 if (E->getOperatorDelete()) {
6300 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006301 getDerived().TransformDecl(E->getLocStart(),
6302 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006303 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006304 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006305 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006306
Douglas Gregora16548e2009-08-11 05:31:07 +00006307 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006308 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006309 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006310 Constructor == E->getConstructor() &&
6311 OperatorNew == E->getOperatorNew() &&
6312 OperatorDelete == E->getOperatorDelete() &&
6313 !ArgumentChanged) {
6314 // Mark any declarations we need as referenced.
6315 // FIXME: instantiation-specific.
6316 if (Constructor)
6317 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6318 if (OperatorNew)
6319 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6320 if (OperatorDelete)
6321 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006322 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006323 }
Mike Stump11289f42009-09-09 15:08:12 +00006324
Douglas Gregor0744ef62010-09-07 21:49:58 +00006325 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006326 if (!ArraySize.get()) {
6327 // If no array size was specified, but the new expression was
6328 // instantiated with an array type (e.g., "new T" where T is
6329 // instantiated with "int[4]"), extract the outer bound from the
6330 // array type as our array size. We do this with constant and
6331 // dependently-sized array types.
6332 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6333 if (!ArrayT) {
6334 // Do nothing
6335 } else if (const ConstantArrayType *ConsArrayT
6336 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006337 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006338 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6339 ConsArrayT->getSize(),
6340 SemaRef.Context.getSizeType(),
6341 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006342 AllocType = ConsArrayT->getElementType();
6343 } else if (const DependentSizedArrayType *DepArrayT
6344 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6345 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006346 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006347 AllocType = DepArrayT->getElementType();
6348 }
6349 }
6350 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006351
Douglas Gregora16548e2009-08-11 05:31:07 +00006352 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6353 E->isGlobalNew(),
6354 /*FIXME:*/E->getLocStart(),
6355 move_arg(PlacementArgs),
6356 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006357 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006359 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006360 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006361 /*FIXME:*/E->getLocStart(),
6362 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006363 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006364}
Mike Stump11289f42009-09-09 15:08:12 +00006365
Douglas Gregora16548e2009-08-11 05:31:07 +00006366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006367ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006368TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006369 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006370 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006371 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006372
Douglas Gregord2d9da02010-02-26 00:38:10 +00006373 // Transform the delete operator, if known.
6374 FunctionDecl *OperatorDelete = 0;
6375 if (E->getOperatorDelete()) {
6376 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006377 getDerived().TransformDecl(E->getLocStart(),
6378 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006379 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006381 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006382
Douglas Gregora16548e2009-08-11 05:31:07 +00006383 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006384 Operand.get() == E->getArgument() &&
6385 OperatorDelete == E->getOperatorDelete()) {
6386 // Mark any declarations we need as referenced.
6387 // FIXME: instantiation-specific.
6388 if (OperatorDelete)
6389 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006390
6391 if (!E->getArgument()->isTypeDependent()) {
6392 QualType Destroyed = SemaRef.Context.getBaseElementType(
6393 E->getDestroyedType());
6394 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6395 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6396 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6397 SemaRef.LookupDestructor(Record));
6398 }
6399 }
6400
John McCallc3007a22010-10-26 07:05:15 +00006401 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006402 }
Mike Stump11289f42009-09-09 15:08:12 +00006403
Douglas Gregora16548e2009-08-11 05:31:07 +00006404 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6405 E->isGlobalDelete(),
6406 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006407 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006408}
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregora16548e2009-08-11 05:31:07 +00006410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006411ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006412TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006413 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006414 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006415 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006417
John McCallba7bf592010-08-24 05:47:05 +00006418 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006419 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006420 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006421 E->getOperatorLoc(),
6422 E->isArrow()? tok::arrow : tok::period,
6423 ObjectTypePtr,
6424 MayBePseudoDestructor);
6425 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006426 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006427
John McCallba7bf592010-08-24 05:47:05 +00006428 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006429 NestedNameSpecifier *Qualifier = E->getQualifier();
6430 if (Qualifier) {
6431 Qualifier
6432 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6433 E->getQualifierRange(),
6434 ObjectType);
6435 if (!Qualifier)
6436 return ExprError();
6437 }
Mike Stump11289f42009-09-09 15:08:12 +00006438
Douglas Gregor678f90d2010-02-25 01:56:36 +00006439 PseudoDestructorTypeStorage Destroyed;
6440 if (E->getDestroyedTypeInfo()) {
6441 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006442 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6443 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006444 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006445 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006446 Destroyed = DestroyedTypeInfo;
6447 } else if (ObjectType->isDependentType()) {
6448 // We aren't likely to be able to resolve the identifier down to a type
6449 // now anyway, so just retain the identifier.
6450 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6451 E->getDestroyedTypeLoc());
6452 } else {
6453 // Look for a destructor known with the given name.
6454 CXXScopeSpec SS;
6455 if (Qualifier) {
6456 SS.setScopeRep(Qualifier);
6457 SS.setRange(E->getQualifierRange());
6458 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006459
John McCallba7bf592010-08-24 05:47:05 +00006460 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006461 *E->getDestroyedTypeIdentifier(),
6462 E->getDestroyedTypeLoc(),
6463 /*Scope=*/0,
6464 SS, ObjectTypePtr,
6465 false);
6466 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006467 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006468
Douglas Gregor678f90d2010-02-25 01:56:36 +00006469 Destroyed
6470 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6471 E->getDestroyedTypeLoc());
6472 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006473
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006474 TypeSourceInfo *ScopeTypeInfo = 0;
6475 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006476 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006477 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006478 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006479 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006480
John McCallb268a282010-08-23 23:25:46 +00006481 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006482 E->getOperatorLoc(),
6483 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006484 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006485 E->getQualifierRange(),
6486 ScopeTypeInfo,
6487 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006488 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006489 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006490}
Mike Stump11289f42009-09-09 15:08:12 +00006491
Douglas Gregorad8a3362009-09-04 17:36:40 +00006492template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006493ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006494TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006495 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006496 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6497
6498 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6499 Sema::LookupOrdinaryName);
6500
6501 // Transform all the decls.
6502 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6503 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006504 NamedDecl *InstD = static_cast<NamedDecl*>(
6505 getDerived().TransformDecl(Old->getNameLoc(),
6506 *I));
John McCall84d87672009-12-10 09:41:52 +00006507 if (!InstD) {
6508 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6509 // This can happen because of dependent hiding.
6510 if (isa<UsingShadowDecl>(*I))
6511 continue;
6512 else
John McCallfaf5fb42010-08-26 23:41:50 +00006513 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006514 }
John McCalle66edc12009-11-24 19:00:30 +00006515
6516 // Expand using declarations.
6517 if (isa<UsingDecl>(InstD)) {
6518 UsingDecl *UD = cast<UsingDecl>(InstD);
6519 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6520 E = UD->shadow_end(); I != E; ++I)
6521 R.addDecl(*I);
6522 continue;
6523 }
6524
6525 R.addDecl(InstD);
6526 }
6527
6528 // Resolve a kind, but don't do any further analysis. If it's
6529 // ambiguous, the callee needs to deal with it.
6530 R.resolveKind();
6531
6532 // Rebuild the nested-name qualifier, if present.
6533 CXXScopeSpec SS;
6534 NestedNameSpecifier *Qualifier = 0;
6535 if (Old->getQualifier()) {
6536 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006537 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006538 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006539 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006540
John McCalle66edc12009-11-24 19:00:30 +00006541 SS.setScopeRep(Qualifier);
6542 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006543 }
6544
Douglas Gregor9262f472010-04-27 18:19:34 +00006545 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006546 CXXRecordDecl *NamingClass
6547 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6548 Old->getNameLoc(),
6549 Old->getNamingClass()));
6550 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006551 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006552
Douglas Gregorda7be082010-04-27 16:10:10 +00006553 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006554 }
6555
6556 // If we have no template arguments, it's a normal declaration name.
6557 if (!Old->hasExplicitTemplateArgs())
6558 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6559
6560 // If we have template arguments, rebuild them, then rebuild the
6561 // templateid expression.
6562 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006563 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6564 Old->getNumTemplateArgs(),
6565 TransArgs))
6566 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006567
6568 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6569 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006570}
Mike Stump11289f42009-09-09 15:08:12 +00006571
Douglas Gregora16548e2009-08-11 05:31:07 +00006572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006573ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006574TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006575 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6576 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006578
Douglas Gregora16548e2009-08-11 05:31:07 +00006579 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006580 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006581 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006582
Mike Stump11289f42009-09-09 15:08:12 +00006583 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006584 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006585 T,
6586 E->getLocEnd());
6587}
Mike Stump11289f42009-09-09 15:08:12 +00006588
Douglas Gregora16548e2009-08-11 05:31:07 +00006589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006590ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006591TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6592 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6593 if (!LhsT)
6594 return ExprError();
6595
6596 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6597 if (!RhsT)
6598 return ExprError();
6599
6600 if (!getDerived().AlwaysRebuild() &&
6601 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6602 return SemaRef.Owned(E);
6603
6604 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6605 E->getLocStart(),
6606 LhsT, RhsT,
6607 E->getLocEnd());
6608}
6609
6610template<typename Derived>
6611ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006612TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006613 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006614 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006615 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006616 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006617 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006619
John McCall31f82722010-11-12 08:19:04 +00006620 // TODO: If this is a conversion-function-id, verify that the
6621 // destination type name (if present) resolves the same way after
6622 // instantiation as it did in the local scope.
6623
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006624 DeclarationNameInfo NameInfo
6625 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6626 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006627 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006628
John McCalle66edc12009-11-24 19:00:30 +00006629 if (!E->hasExplicitTemplateArgs()) {
6630 if (!getDerived().AlwaysRebuild() &&
6631 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006632 // Note: it is sufficient to compare the Name component of NameInfo:
6633 // if name has not changed, DNLoc has not changed either.
6634 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006635 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006636
John McCalle66edc12009-11-24 19:00:30 +00006637 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6638 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006639 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006640 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006641 }
John McCall6b51f282009-11-23 01:53:49 +00006642
6643 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006644 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6645 E->getNumTemplateArgs(),
6646 TransArgs))
6647 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006648
John McCalle66edc12009-11-24 19:00:30 +00006649 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6650 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006651 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006652 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006653}
6654
6655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006658 // CXXConstructExprs are always implicit, so when we have a
6659 // 1-argument construction we just transform that argument.
6660 if (E->getNumArgs() == 1 ||
6661 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6662 return getDerived().TransformExpr(E->getArg(0));
6663
Douglas Gregora16548e2009-08-11 05:31:07 +00006664 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6665
6666 QualType T = getDerived().TransformType(E->getType());
6667 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006668 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006669
6670 CXXConstructorDecl *Constructor
6671 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006672 getDerived().TransformDecl(E->getLocStart(),
6673 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006675 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregora16548e2009-08-11 05:31:07 +00006677 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006678 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006679 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6680 &ArgumentChanged))
6681 return ExprError();
6682
Douglas Gregora16548e2009-08-11 05:31:07 +00006683 if (!getDerived().AlwaysRebuild() &&
6684 T == E->getType() &&
6685 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006686 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006687 // Mark the constructor as referenced.
6688 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006689 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006690 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006691 }
Mike Stump11289f42009-09-09 15:08:12 +00006692
Douglas Gregordb121ba2009-12-14 16:27:04 +00006693 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6694 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006695 move_arg(Args),
6696 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006697 E->getConstructionKind(),
6698 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006699}
Mike Stump11289f42009-09-09 15:08:12 +00006700
Douglas Gregora16548e2009-08-11 05:31:07 +00006701/// \brief Transform a C++ temporary-binding expression.
6702///
Douglas Gregor363b1512009-12-24 18:51:59 +00006703/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6704/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006705template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006706ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006707TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006708 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006709}
Mike Stump11289f42009-09-09 15:08:12 +00006710
John McCall5d413782010-12-06 08:20:24 +00006711/// \brief Transform a C++ expression that contains cleanups that should
6712/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006713///
John McCall5d413782010-12-06 08:20:24 +00006714/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006715/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006717ExprResult
John McCall5d413782010-12-06 08:20:24 +00006718TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006719 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006720}
Mike Stump11289f42009-09-09 15:08:12 +00006721
Douglas Gregora16548e2009-08-11 05:31:07 +00006722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006723ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006724TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006725 CXXTemporaryObjectExpr *E) {
6726 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6727 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregora16548e2009-08-11 05:31:07 +00006730 CXXConstructorDecl *Constructor
6731 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006732 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006733 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006734 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006736
Douglas Gregora16548e2009-08-11 05:31:07 +00006737 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006738 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006739 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006740 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6741 &ArgumentChanged))
6742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006743
Douglas Gregora16548e2009-08-11 05:31:07 +00006744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006745 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006746 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006747 !ArgumentChanged) {
6748 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006749 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006750 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006751 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006752
6753 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6754 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006755 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006756 E->getLocEnd());
6757}
Mike Stump11289f42009-09-09 15:08:12 +00006758
Douglas Gregora16548e2009-08-11 05:31:07 +00006759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006760ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006761TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006762 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006763 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6764 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006766
Douglas Gregora16548e2009-08-11 05:31:07 +00006767 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006768 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006769 Args.reserve(E->arg_size());
6770 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6771 &ArgumentChanged))
6772 return ExprError();
6773
Douglas Gregora16548e2009-08-11 05:31:07 +00006774 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006775 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006776 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006777 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006778
Douglas Gregora16548e2009-08-11 05:31:07 +00006779 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006780 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006781 E->getLParenLoc(),
6782 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006783 E->getRParenLoc());
6784}
Mike Stump11289f42009-09-09 15:08:12 +00006785
Douglas Gregora16548e2009-08-11 05:31:07 +00006786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006787ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006788TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006789 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006790 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006791 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006792 Expr *OldBase;
6793 QualType BaseType;
6794 QualType ObjectType;
6795 if (!E->isImplicitAccess()) {
6796 OldBase = E->getBase();
6797 Base = getDerived().TransformExpr(OldBase);
6798 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006800
John McCall2d74de92009-12-01 22:10:20 +00006801 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006802 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006803 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006804 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006805 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006806 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006807 ObjectTy,
6808 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006809 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006811
John McCallba7bf592010-08-24 05:47:05 +00006812 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006813 BaseType = ((Expr*) Base.get())->getType();
6814 } else {
6815 OldBase = 0;
6816 BaseType = getDerived().TransformType(E->getBaseType());
6817 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6818 }
Mike Stump11289f42009-09-09 15:08:12 +00006819
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006820 // Transform the first part of the nested-name-specifier that qualifies
6821 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006822 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006823 = getDerived().TransformFirstQualifierInScope(
6824 E->getFirstQualifierFoundInScope(),
6825 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006827 NestedNameSpecifier *Qualifier = 0;
6828 if (E->getQualifier()) {
6829 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6830 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006831 ObjectType,
6832 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006833 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006834 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006835 }
Mike Stump11289f42009-09-09 15:08:12 +00006836
John McCall31f82722010-11-12 08:19:04 +00006837 // TODO: If this is a conversion-function-id, verify that the
6838 // destination type name (if present) resolves the same way after
6839 // instantiation as it did in the local scope.
6840
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006841 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006842 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006843 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006845
John McCall2d74de92009-12-01 22:10:20 +00006846 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006847 // This is a reference to a member without an explicitly-specified
6848 // template argument list. Optimize for this common case.
6849 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006850 Base.get() == OldBase &&
6851 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006852 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006853 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006854 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006855 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006856
John McCallb268a282010-08-23 23:25:46 +00006857 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006858 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006859 E->isArrow(),
6860 E->getOperatorLoc(),
6861 Qualifier,
6862 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006863 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006864 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006865 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006866 }
6867
John McCall6b51f282009-11-23 01:53:49 +00006868 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006869 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6870 E->getNumTemplateArgs(),
6871 TransArgs))
6872 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006873
John McCallb268a282010-08-23 23:25:46 +00006874 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006875 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006876 E->isArrow(),
6877 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006878 Qualifier,
6879 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006880 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006881 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006882 &TransArgs);
6883}
6884
6885template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006886ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006887TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006888 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006889 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006890 QualType BaseType;
6891 if (!Old->isImplicitAccess()) {
6892 Base = getDerived().TransformExpr(Old->getBase());
6893 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006894 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006895 BaseType = ((Expr*) Base.get())->getType();
6896 } else {
6897 BaseType = getDerived().TransformType(Old->getBaseType());
6898 }
John McCall10eae182009-11-30 22:42:35 +00006899
6900 NestedNameSpecifier *Qualifier = 0;
6901 if (Old->getQualifier()) {
6902 Qualifier
6903 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006904 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006905 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006906 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006907 }
6908
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006909 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006910 Sema::LookupOrdinaryName);
6911
6912 // Transform all the decls.
6913 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6914 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006915 NamedDecl *InstD = static_cast<NamedDecl*>(
6916 getDerived().TransformDecl(Old->getMemberLoc(),
6917 *I));
John McCall84d87672009-12-10 09:41:52 +00006918 if (!InstD) {
6919 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6920 // This can happen because of dependent hiding.
6921 if (isa<UsingShadowDecl>(*I))
6922 continue;
6923 else
John McCallfaf5fb42010-08-26 23:41:50 +00006924 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006925 }
John McCall10eae182009-11-30 22:42:35 +00006926
6927 // Expand using declarations.
6928 if (isa<UsingDecl>(InstD)) {
6929 UsingDecl *UD = cast<UsingDecl>(InstD);
6930 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6931 E = UD->shadow_end(); I != E; ++I)
6932 R.addDecl(*I);
6933 continue;
6934 }
6935
6936 R.addDecl(InstD);
6937 }
6938
6939 R.resolveKind();
6940
Douglas Gregor9262f472010-04-27 18:19:34 +00006941 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006942 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006943 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006944 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006945 Old->getMemberLoc(),
6946 Old->getNamingClass()));
6947 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006948 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006949
Douglas Gregorda7be082010-04-27 16:10:10 +00006950 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006951 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006952
John McCall10eae182009-11-30 22:42:35 +00006953 TemplateArgumentListInfo TransArgs;
6954 if (Old->hasExplicitTemplateArgs()) {
6955 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6956 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006957 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6958 Old->getNumTemplateArgs(),
6959 TransArgs))
6960 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006961 }
John McCall38836f02010-01-15 08:34:02 +00006962
6963 // FIXME: to do this check properly, we will need to preserve the
6964 // first-qualifier-in-scope here, just in case we had a dependent
6965 // base (and therefore couldn't do the check) and a
6966 // nested-name-qualifier (and therefore could do the lookup).
6967 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006968
John McCallb268a282010-08-23 23:25:46 +00006969 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006970 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006971 Old->getOperatorLoc(),
6972 Old->isArrow(),
6973 Qualifier,
6974 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006975 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006976 R,
6977 (Old->hasExplicitTemplateArgs()
6978 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006979}
6980
6981template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006982ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006983TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6984 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6985 if (SubExpr.isInvalid())
6986 return ExprError();
6987
6988 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006989 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006990
6991 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6992}
6993
6994template<typename Derived>
6995ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006996TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006997 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6998 if (Pattern.isInvalid())
6999 return ExprError();
7000
7001 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7002 return SemaRef.Owned(E);
7003
Douglas Gregorb8840002011-01-14 21:20:45 +00007004 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7005 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007006}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007007
7008template<typename Derived>
7009ExprResult
7010TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7011 // If E is not value-dependent, then nothing will change when we transform it.
7012 // Note: This is an instantiation-centric view.
7013 if (!E->isValueDependent())
7014 return SemaRef.Owned(E);
7015
7016 // Note: None of the implementations of TryExpandParameterPacks can ever
7017 // produce a diagnostic when given only a single unexpanded parameter pack,
7018 // so
7019 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7020 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007021 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007022 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007023 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7024 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007025 ShouldExpand, RetainExpansion,
7026 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007027 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007028
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007029 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007030 return SemaRef.Owned(E);
7031
7032 // We now know the length of the parameter pack, so build a new expression
7033 // that stores that length.
7034 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7035 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007036 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007037}
7038
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007039template<typename Derived>
7040ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007041TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7042 SubstNonTypeTemplateParmPackExpr *E) {
7043 // Default behavior is to do nothing with this transformation.
7044 return SemaRef.Owned(E);
7045}
7046
7047template<typename Derived>
7048ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007049TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007050 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007051}
7052
Mike Stump11289f42009-09-09 15:08:12 +00007053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007054ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007055TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007056 TypeSourceInfo *EncodedTypeInfo
7057 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7058 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007060
Douglas Gregora16548e2009-08-11 05:31:07 +00007061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007062 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007063 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007064
7065 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007066 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007067 E->getRParenLoc());
7068}
Mike Stump11289f42009-09-09 15:08:12 +00007069
Douglas Gregora16548e2009-08-11 05:31:07 +00007070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007072TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007073 // Transform arguments.
7074 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007075 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007076 Args.reserve(E->getNumArgs());
7077 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7078 &ArgChanged))
7079 return ExprError();
7080
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007081 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7082 // Class message: transform the receiver type.
7083 TypeSourceInfo *ReceiverTypeInfo
7084 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7085 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007086 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007087
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007088 // If nothing changed, just retain the existing message send.
7089 if (!getDerived().AlwaysRebuild() &&
7090 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007091 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007092
7093 // Build a new class message send.
7094 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7095 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007096 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007097 E->getMethodDecl(),
7098 E->getLeftLoc(),
7099 move_arg(Args),
7100 E->getRightLoc());
7101 }
7102
7103 // Instance message: transform the receiver
7104 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7105 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007106 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007107 = getDerived().TransformExpr(E->getInstanceReceiver());
7108 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007109 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007110
7111 // If nothing changed, just retain the existing message send.
7112 if (!getDerived().AlwaysRebuild() &&
7113 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007114 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007115
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007116 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007117 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007118 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007119 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007120 E->getMethodDecl(),
7121 E->getLeftLoc(),
7122 move_arg(Args),
7123 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007129 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007130}
7131
Mike Stump11289f42009-09-09 15:08:12 +00007132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007134TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007135 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007136}
7137
Mike Stump11289f42009-09-09 15:08:12 +00007138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007140TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007141 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007142 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007143 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007144 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007145
7146 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007147
Douglas Gregord51d90d2010-04-26 20:11:03 +00007148 // If nothing changed, just retain the existing expression.
7149 if (!getDerived().AlwaysRebuild() &&
7150 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007151 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007152
John McCallb268a282010-08-23 23:25:46 +00007153 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007154 E->getLocation(),
7155 E->isArrow(), E->isFreeIvar());
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>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007161 // 'super' and types never change. Property never changes. Just
7162 // retain the existing expression.
7163 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007164 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007165
Douglas Gregor9faee212010-04-26 20:47:02 +00007166 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007167 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007168 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007169 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007170
Douglas Gregor9faee212010-04-26 20:47:02 +00007171 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007172
Douglas Gregor9faee212010-04-26 20:47:02 +00007173 // If nothing changed, just retain the existing expression.
7174 if (!getDerived().AlwaysRebuild() &&
7175 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007176 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007177
John McCallb7bd14f2010-12-02 01:19:52 +00007178 if (E->isExplicitProperty())
7179 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7180 E->getExplicitProperty(),
7181 E->getLocation());
7182
7183 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7184 E->getType(),
7185 E->getImplicitPropertyGetter(),
7186 E->getImplicitPropertySetter(),
7187 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007188}
7189
Mike Stump11289f42009-09-09 15:08:12 +00007190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007192TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007193 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007194 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007195 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007196 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007197
Douglas Gregord51d90d2010-04-26 20:11:03 +00007198 // If nothing changed, just retain the existing expression.
7199 if (!getDerived().AlwaysRebuild() &&
7200 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007201 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007202
John McCallb268a282010-08-23 23:25:46 +00007203 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007204 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007205}
7206
Mike Stump11289f42009-09-09 15:08:12 +00007207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007208ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007209TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007210 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007211 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007212 SubExprs.reserve(E->getNumSubExprs());
7213 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7214 SubExprs, &ArgumentChanged))
7215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007216
Douglas Gregora16548e2009-08-11 05:31:07 +00007217 if (!getDerived().AlwaysRebuild() &&
7218 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007219 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007220
Douglas Gregora16548e2009-08-11 05:31:07 +00007221 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7222 move_arg(SubExprs),
7223 E->getRParenLoc());
7224}
7225
Mike Stump11289f42009-09-09 15:08:12 +00007226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007227ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007228TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007229 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007230
John McCall490112f2011-02-04 18:33:18 +00007231 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7232 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7233
7234 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7235 llvm::SmallVector<ParmVarDecl*, 4> params;
7236 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007237
7238 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007239 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7240 oldBlock->param_begin(),
7241 oldBlock->param_size(),
7242 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007243 return true;
John McCall490112f2011-02-04 18:33:18 +00007244
7245 const FunctionType *exprFunctionType = E->getFunctionType();
7246 QualType exprResultType = exprFunctionType->getResultType();
7247 if (!exprResultType.isNull()) {
7248 if (!exprResultType->isDependentType())
7249 blockScope->ReturnType = exprResultType;
7250 else if (exprResultType != getSema().Context.DependentTy)
7251 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007252 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007253
7254 // If the return type has not been determined yet, leave it as a dependent
7255 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007256 if (blockScope->ReturnType.isNull())
7257 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007258
7259 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007260 if (blockScope->ReturnType->isObjCObjectType()) {
7261 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007262 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007263 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007264 return ExprError();
7265 }
John McCall3882ace2011-01-05 12:14:39 +00007266
John McCall490112f2011-02-04 18:33:18 +00007267 QualType functionType = getDerived().RebuildFunctionProtoType(
7268 blockScope->ReturnType,
7269 paramTypes.data(),
7270 paramTypes.size(),
7271 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007272 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007273 exprFunctionType->getExtInfo());
7274 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007275
7276 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007277 if (!params.empty())
7278 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007279
7280 // If the return type wasn't explicitly set, it will have been marked as a
7281 // dependent type (DependentTy); clear out the return type setting so
7282 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007283 if (blockScope->ReturnType == getSema().Context.DependentTy)
7284 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007285
John McCall3882ace2011-01-05 12:14:39 +00007286 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007287 StmtResult body = getDerived().TransformStmt(E->getBody());
7288 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007289 return ExprError();
7290
John McCall490112f2011-02-04 18:33:18 +00007291#ifndef NDEBUG
7292 // In builds with assertions, make sure that we captured everything we
7293 // captured before.
7294
7295 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7296
7297 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7298 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007299 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007300
7301 // Ignore parameter packs.
7302 if (isa<ParmVarDecl>(oldCapture) &&
7303 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7304 continue;
7305
7306 VarDecl *newCapture =
7307 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7308 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007309 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007310 }
7311#endif
7312
7313 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7314 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007315}
7316
Mike Stump11289f42009-09-09 15:08:12 +00007317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007319TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007320 NestedNameSpecifier *Qualifier = 0;
7321
7322 ValueDecl *ND
7323 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7324 E->getDecl()));
7325 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007326 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007327
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007328 if (!getDerived().AlwaysRebuild() &&
7329 ND == E->getDecl()) {
7330 // Mark it referenced in the new context regardless.
7331 // FIXME: this is a bit instantiation-specific.
7332 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7333
John McCallc3007a22010-10-26 07:05:15 +00007334 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007335 }
7336
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007337 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007338 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007339 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007340}
Mike Stump11289f42009-09-09 15:08:12 +00007341
Douglas Gregora16548e2009-08-11 05:31:07 +00007342//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007343// Type reconstruction
7344//===----------------------------------------------------------------------===//
7345
Mike Stump11289f42009-09-09 15:08:12 +00007346template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007347QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7348 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007349 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007350 getDerived().getBaseEntity());
7351}
7352
Mike Stump11289f42009-09-09 15:08:12 +00007353template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007354QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7355 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007356 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007357 getDerived().getBaseEntity());
7358}
7359
Mike Stump11289f42009-09-09 15:08:12 +00007360template<typename Derived>
7361QualType
John McCall70dd5f62009-10-30 00:06:24 +00007362TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7363 bool WrittenAsLValue,
7364 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007365 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007366 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007367}
7368
7369template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007370QualType
John McCall70dd5f62009-10-30 00:06:24 +00007371TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7372 QualType ClassType,
7373 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007374 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007375 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007376}
7377
7378template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007379QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007380TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7381 ArrayType::ArraySizeModifier SizeMod,
7382 const llvm::APInt *Size,
7383 Expr *SizeExpr,
7384 unsigned IndexTypeQuals,
7385 SourceRange BracketsRange) {
7386 if (SizeExpr || !Size)
7387 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7388 IndexTypeQuals, BracketsRange,
7389 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007390
7391 QualType Types[] = {
7392 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7393 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7394 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007395 };
7396 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7397 QualType SizeType;
7398 for (unsigned I = 0; I != NumTypes; ++I)
7399 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7400 SizeType = Types[I];
7401 break;
7402 }
Mike Stump11289f42009-09-09 15:08:12 +00007403
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007404 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7405 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007406 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007407 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007408 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007409}
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregord6ff3322009-08-04 16:50:30 +00007411template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007412QualType
7413TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007414 ArrayType::ArraySizeModifier SizeMod,
7415 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007416 unsigned IndexTypeQuals,
7417 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007418 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007419 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007420}
7421
7422template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007423QualType
Mike Stump11289f42009-09-09 15:08:12 +00007424TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007425 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007426 unsigned IndexTypeQuals,
7427 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007428 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007429 IndexTypeQuals, BracketsRange);
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>
Mike Stump11289f42009-09-09 15:08:12 +00007433QualType
7434TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007435 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007436 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007437 unsigned IndexTypeQuals,
7438 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007439 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007440 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007441 IndexTypeQuals, BracketsRange);
7442}
7443
7444template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007445QualType
7446TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007447 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007448 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007449 unsigned IndexTypeQuals,
7450 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007451 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007452 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007453 IndexTypeQuals, BracketsRange);
7454}
7455
7456template<typename Derived>
7457QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007458 unsigned NumElements,
7459 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007460 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007461 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007462}
Mike Stump11289f42009-09-09 15:08:12 +00007463
Douglas Gregord6ff3322009-08-04 16:50:30 +00007464template<typename Derived>
7465QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7466 unsigned NumElements,
7467 SourceLocation AttributeLoc) {
7468 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7469 NumElements, true);
7470 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007471 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7472 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007473 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007474}
Mike Stump11289f42009-09-09 15:08:12 +00007475
Douglas Gregord6ff3322009-08-04 16:50:30 +00007476template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007477QualType
7478TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007479 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007480 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007481 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007482}
Mike Stump11289f42009-09-09 15:08:12 +00007483
Douglas Gregord6ff3322009-08-04 16:50:30 +00007484template<typename Derived>
7485QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007486 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007487 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007488 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007489 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007490 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007491 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007492 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007493 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007494 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007495 getDerived().getBaseEntity(),
7496 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007497}
Mike Stump11289f42009-09-09 15:08:12 +00007498
Douglas Gregord6ff3322009-08-04 16:50:30 +00007499template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007500QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7501 return SemaRef.Context.getFunctionNoProtoType(T);
7502}
7503
7504template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007505QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7506 assert(D && "no decl found");
7507 if (D->isInvalidDecl()) return QualType();
7508
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007509 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007510 TypeDecl *Ty;
7511 if (isa<UsingDecl>(D)) {
7512 UsingDecl *Using = cast<UsingDecl>(D);
7513 assert(Using->isTypeName() &&
7514 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7515
7516 // A valid resolved using typename decl points to exactly one type decl.
7517 assert(++Using->shadow_begin() == Using->shadow_end());
7518 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007519
John McCallb96ec562009-12-04 22:46:56 +00007520 } else {
7521 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7522 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7523 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7524 }
7525
7526 return SemaRef.Context.getTypeDeclType(Ty);
7527}
7528
7529template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007530QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7531 SourceLocation Loc) {
7532 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007533}
7534
7535template<typename Derived>
7536QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7537 return SemaRef.Context.getTypeOfType(Underlying);
7538}
7539
7540template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007541QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7542 SourceLocation Loc) {
7543 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007544}
7545
7546template<typename Derived>
7547QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007548 TemplateName Template,
7549 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007550 const TemplateArgumentListInfo &TemplateArgs) {
7551 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007552}
Mike Stump11289f42009-09-09 15:08:12 +00007553
Douglas Gregor1135c352009-08-06 05:28:30 +00007554template<typename Derived>
7555NestedNameSpecifier *
7556TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7557 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007558 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007559 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007560 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007561 CXXScopeSpec SS;
7562 // FIXME: The source location information is all wrong.
7563 SS.setRange(Range);
7564 SS.setScopeRep(Prefix);
7565 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007566 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007567 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007568 ObjectType,
7569 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007570 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007571}
7572
7573template<typename Derived>
7574NestedNameSpecifier *
7575TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7576 SourceRange Range,
7577 NamespaceDecl *NS) {
7578 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7579}
7580
7581template<typename Derived>
7582NestedNameSpecifier *
7583TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7584 SourceRange Range,
7585 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007586 QualType T) {
7587 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007588 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007589 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007590 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7591 T.getTypePtr());
7592 }
Mike Stump11289f42009-09-09 15:08:12 +00007593
Douglas Gregor1135c352009-08-06 05:28:30 +00007594 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7595 return 0;
7596}
Mike Stump11289f42009-09-09 15:08:12 +00007597
Douglas Gregor71dc5092009-08-06 06:41:21 +00007598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007599TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007600TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7601 bool TemplateKW,
7602 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007603 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007604 Template);
7605}
7606
7607template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007608TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007609TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007610 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007611 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007612 QualType ObjectType,
7613 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007614 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007615 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007616 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007617 UnqualifiedId Name;
7618 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007619 Sema::TemplateTy Template;
7620 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7621 /*FIXME:*/getDerived().getBaseLocation(),
7622 SS,
7623 Name,
John McCallba7bf592010-08-24 05:47:05 +00007624 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007625 /*EnteringContext=*/false,
7626 Template);
John McCall31f82722010-11-12 08:19:04 +00007627 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007628}
Mike Stump11289f42009-09-09 15:08:12 +00007629
Douglas Gregora16548e2009-08-11 05:31:07 +00007630template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007631TemplateName
7632TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7633 OverloadedOperatorKind Operator,
7634 QualType ObjectType) {
7635 CXXScopeSpec SS;
7636 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7637 SS.setScopeRep(Qualifier);
7638 UnqualifiedId Name;
7639 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7640 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7641 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007642 Sema::TemplateTy Template;
7643 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007644 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007645 SS,
7646 Name,
John McCallba7bf592010-08-24 05:47:05 +00007647 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007648 /*EnteringContext=*/false,
7649 Template);
7650 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007651}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007652
Douglas Gregor71395fa2009-11-04 00:56:37 +00007653template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007654ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007655TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7656 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007657 Expr *OrigCallee,
7658 Expr *First,
7659 Expr *Second) {
7660 Expr *Callee = OrigCallee->IgnoreParenCasts();
7661 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007664 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007665 if (!First->getType()->isOverloadableType() &&
7666 !Second->getType()->isOverloadableType())
7667 return getSema().CreateBuiltinArraySubscriptExpr(First,
7668 Callee->getLocStart(),
7669 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007670 } else if (Op == OO_Arrow) {
7671 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007672 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7673 } else if (Second == 0 || isPostIncDec) {
7674 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007675 // The argument is not of overloadable type, so try to create a
7676 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007677 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007679
John McCallb268a282010-08-23 23:25:46 +00007680 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007681 }
7682 } else {
John McCallb268a282010-08-23 23:25:46 +00007683 if (!First->getType()->isOverloadableType() &&
7684 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007685 // Neither of the arguments is an overloadable type, so try to
7686 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007687 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007688 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007689 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007692
Douglas Gregora16548e2009-08-11 05:31:07 +00007693 return move(Result);
7694 }
7695 }
Mike Stump11289f42009-09-09 15:08:12 +00007696
7697 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007698 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007699 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007700
John McCallb268a282010-08-23 23:25:46 +00007701 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007702 assert(ULE->requiresADL());
7703
7704 // FIXME: Do we have to check
7705 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007706 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007707 } else {
John McCallb268a282010-08-23 23:25:46 +00007708 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007709 }
Mike Stump11289f42009-09-09 15:08:12 +00007710
Douglas Gregora16548e2009-08-11 05:31:07 +00007711 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007712 Expr *Args[2] = { First, Second };
7713 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007714
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 // Create the overloaded operator invocation for unary operators.
7716 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007717 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007719 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007720 }
Mike Stump11289f42009-09-09 15:08:12 +00007721
Sebastian Redladba46e2009-10-29 20:17:01 +00007722 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007723 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007724 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007725 First,
7726 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007727
Douglas Gregora16548e2009-08-11 05:31:07 +00007728 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007729 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007730 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007731 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7732 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007734
Mike Stump11289f42009-09-09 15:08:12 +00007735 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007736}
Mike Stump11289f42009-09-09 15:08:12 +00007737
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007739ExprResult
John McCallb268a282010-08-23 23:25:46 +00007740TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007741 SourceLocation OperatorLoc,
7742 bool isArrow,
7743 NestedNameSpecifier *Qualifier,
7744 SourceRange QualifierRange,
7745 TypeSourceInfo *ScopeType,
7746 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007747 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007748 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007749 CXXScopeSpec SS;
7750 if (Qualifier) {
7751 SS.setRange(QualifierRange);
7752 SS.setScopeRep(Qualifier);
7753 }
7754
John McCallb268a282010-08-23 23:25:46 +00007755 QualType BaseType = Base->getType();
7756 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007757 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007758 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007759 !BaseType->getAs<PointerType>()->getPointeeType()
7760 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007761 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007762 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007763 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007764 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007765 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007766 /*FIXME?*/true);
7767 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007768
Douglas Gregor678f90d2010-02-25 01:56:36 +00007769 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007770 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7771 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7772 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7773 NameInfo.setNamedTypeInfo(DestroyedType);
7774
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007775 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007776
John McCallb268a282010-08-23 23:25:46 +00007777 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007778 OperatorLoc, isArrow,
7779 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007780 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007781 /*TemplateArgs*/ 0);
7782}
7783
Douglas Gregord6ff3322009-08-04 16:50:30 +00007784} // end namespace clang
7785
7786#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H