blob: 04ec04110be35a823f515d760ca5e4b9cb8daafa [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) {
Richard Smith2abf6762011-02-23 00:37:57 +00001086 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1087 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001088 }
Mike Stump11289f42009-09-09 15:08:12 +00001089
Anders Carlssonaaeef072010-01-24 05:50:09 +00001090 /// \brief Build a new inline asm statement.
1091 ///
1092 /// By default, performs semantic analysis to build the new statement.
1093 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001094 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001095 bool IsSimple,
1096 bool IsVolatile,
1097 unsigned NumOutputs,
1098 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001099 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001100 MultiExprArg Constraints,
1101 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001102 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001103 MultiExprArg Clobbers,
1104 SourceLocation RParenLoc,
1105 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001106 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001107 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001108 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001109 RParenLoc, MSAsm);
1110 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001111
1112 /// \brief Build a new Objective-C @try statement.
1113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001116 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001117 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001118 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001119 Stmt *Finally) {
1120 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1121 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001122 }
1123
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001124 /// \brief Rebuild an Objective-C exception declaration.
1125 ///
1126 /// By default, performs semantic analysis to build the new declaration.
1127 /// Subclasses may override this routine to provide different behavior.
1128 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1129 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130 return getSema().BuildObjCExceptionDecl(TInfo, T,
1131 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001132 ExceptionDecl->getLocation());
1133 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001134
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001135 /// \brief Build a new Objective-C @catch statement.
1136 ///
1137 /// By default, performs semantic analysis to build the new statement.
1138 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001139 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001140 SourceLocation RParenLoc,
1141 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001142 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001143 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001144 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001145 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001146
Douglas Gregor306de2f2010-04-22 23:59:56 +00001147 /// \brief Build a new Objective-C @finally statement.
1148 ///
1149 /// By default, performs semantic analysis to build the new statement.
1150 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001151 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001152 Stmt *Body) {
1153 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001154 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001155
Douglas Gregor6148de72010-04-22 22:01:21 +00001156 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001157 ///
1158 /// By default, performs semantic analysis to build the new statement.
1159 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001160 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001161 Expr *Operand) {
1162 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001163 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001164
Douglas Gregor6148de72010-04-22 22:01:21 +00001165 /// \brief Build a new Objective-C @synchronized statement.
1166 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001167 /// By default, performs semantic analysis to build the new statement.
1168 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001169 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001170 Expr *Object,
1171 Stmt *Body) {
1172 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1173 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001174 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001175
1176 /// \brief Build a new Objective-C fast enumeration statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001181 SourceLocation LParenLoc,
1182 Stmt *Element,
1183 Expr *Collection,
1184 SourceLocation RParenLoc,
1185 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001186 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001187 Element,
1188 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001189 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001190 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001191 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Build a new C++ exception declaration.
1194 ///
1195 /// By default, performs semantic analysis to build the new decaration.
1196 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001197 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001198 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001200 SourceLocation Loc) {
1201 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 }
1203
1204 /// \brief Build a new C++ catch statement.
1205 ///
1206 /// By default, performs semantic analysis to build the new statement.
1207 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001208 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001209 VarDecl *ExceptionDecl,
1210 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001211 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1212 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 }
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregorebe10102009-08-20 07:17:43 +00001215 /// \brief Build a new C++ try statement.
1216 ///
1217 /// By default, performs semantic analysis to build the new statement.
1218 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001219 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001220 Stmt *TryBlock,
1221 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001222 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 /// \brief Build a new expression that references a declaration.
1226 ///
1227 /// By default, performs semantic analysis to build the new expression.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001230 LookupResult &R,
1231 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001232 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1233 }
1234
1235
1236 /// \brief Build a new expression that references a declaration.
1237 ///
1238 /// By default, performs semantic analysis to build the new expression.
1239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001240 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001241 SourceRange QualifierRange,
1242 ValueDecl *VD,
1243 const DeclarationNameInfo &NameInfo,
1244 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001245 CXXScopeSpec SS;
1246 SS.setScopeRep(Qualifier);
1247 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001248
1249 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001250
1251 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 }
Mike Stump11289f42009-09-09 15:08:12 +00001253
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001255 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001256 /// By default, performs semantic analysis to build the new expression.
1257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001258 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001260 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 }
1262
Douglas Gregorad8a3362009-09-04 17:36:40 +00001263 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001264 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001267 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001268 SourceLocation OperatorLoc,
1269 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001270 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001271 SourceRange QualifierRange,
1272 TypeSourceInfo *ScopeType,
1273 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001274 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001275 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001276
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001278 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// By default, performs semantic analysis to build the new expression.
1280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001281 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001282 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001283 Expr *SubExpr) {
1284 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregor882211c2010-04-28 22:16:22 +00001287 /// \brief Build a new builtin offsetof expression.
1288 ///
1289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001291 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001292 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001293 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001294 unsigned NumComponents,
1295 SourceLocation RParenLoc) {
1296 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1297 NumComponents, RParenLoc);
1298 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001299
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, performs semantic analysis to build the new expression.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001305 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001307 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 }
1309
Mike Stump11289f42009-09-09 15:08:12 +00001310 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001312 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001315 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001317 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001318 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001320 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 return move(Result);
1323 }
Mike Stump11289f42009-09-09 15:08:12 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001326 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001329 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001333 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1334 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 RBracketLoc);
1336 }
1337
1338 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001339 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// By default, performs semantic analysis to build the new expression.
1341 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001342 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001344 SourceLocation RParenLoc,
1345 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001346 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001347 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 }
1349
1350 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001351 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001355 bool isArrow,
1356 NestedNameSpecifier *Qualifier,
1357 SourceRange QualifierRange,
1358 const DeclarationNameInfo &MemberNameInfo,
1359 ValueDecl *Member,
1360 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001361 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001362 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001363 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001364 // We have a reference to an unnamed field. This is always the
1365 // base of an anonymous struct/union member access, i.e. the
1366 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001367 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001368 assert(Member->getType()->isRecordType() &&
1369 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001370
John McCallb268a282010-08-23 23:25:46 +00001371 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001372 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001373 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001374
John McCall7decc9e2010-11-18 06:31:45 +00001375 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001376 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001377 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001378 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001379 cast<FieldDecl>(Member)->getType(),
1380 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001381 return getSema().Owned(ME);
1382 }
Mike Stump11289f42009-09-09 15:08:12 +00001383
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001384 CXXScopeSpec SS;
1385 if (Qualifier) {
1386 SS.setRange(QualifierRange);
1387 SS.setScopeRep(Qualifier);
1388 }
1389
John McCallb268a282010-08-23 23:25:46 +00001390 getSema().DefaultFunctionArrayConversion(Base);
1391 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001392
John McCall16df1e52010-03-30 21:47:33 +00001393 // FIXME: this involves duplicating earlier analysis in a lot of
1394 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001395 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001396 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001397 R.resolveKind();
1398
John McCallb268a282010-08-23 23:25:46 +00001399 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001400 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001401 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 }
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001405 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001408 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001409 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001410 Expr *LHS, Expr *RHS) {
1411 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 }
1413
1414 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001415 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 /// By default, performs semantic analysis to build the new expression.
1417 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001418 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001419 SourceLocation QuestionLoc,
1420 Expr *LHS,
1421 SourceLocation ColonLoc,
1422 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001423 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1424 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 }
1426
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001428 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 /// By default, performs semantic analysis to build the new expression.
1430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001431 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001432 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001434 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001435 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001436 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 }
Mike Stump11289f42009-09-09 15:08:12 +00001438
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001440 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001443 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001444 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001446 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001447 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001448 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 }
Mike Stump11289f42009-09-09 15:08:12 +00001450
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001452 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 SourceLocation OpLoc,
1457 SourceLocation AccessorLoc,
1458 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001459
John McCall10eae182009-11-30 22:42:35 +00001460 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001461 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001462 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001463 OpLoc, /*IsArrow*/ false,
1464 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001465 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001466 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 }
Mike Stump11289f42009-09-09 15:08:12 +00001468
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001470 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001473 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001475 SourceLocation RBraceLoc,
1476 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001477 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001478 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1479 if (Result.isInvalid() || ResultTy->isDependentType())
1480 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001481
Douglas Gregord3d93062009-11-09 17:16:50 +00001482 // Patch in the result type we were given, which may have been computed
1483 // when the initial InitListExpr was built.
1484 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1485 ILE->setType(ResultTy);
1486 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
Mike Stump11289f42009-09-09 15:08:12 +00001488
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001490 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001493 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 MultiExprArg ArrayExprs,
1495 SourceLocation EqualOrColonLoc,
1496 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001497 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001498 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001500 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001501 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001502 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 ArrayExprs.release();
1505 return move(Result);
1506 }
Mike Stump11289f42009-09-09 15:08:12 +00001507
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001509 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001510 /// By default, builds the implicit value initialization without performing
1511 /// any semantic analysis. Subclasses may override this routine to provide
1512 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001513 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1515 }
Mike Stump11289f42009-09-09 15:08:12 +00001516
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001518 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001521 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001522 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001523 SourceLocation RParenLoc) {
1524 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001525 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001526 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 }
1528
1529 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001530 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 /// By default, performs semantic analysis to build the new expression.
1532 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001533 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 MultiExprArg SubExprs,
1535 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001536 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001537 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 }
Mike Stump11289f42009-09-09 15:08:12 +00001539
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001541 ///
1542 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// rather than attempting to map the label statement itself.
1544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001545 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001546 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001547 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 }
Mike Stump11289f42009-09-09 15:08:12 +00001549
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001551 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 /// By default, performs semantic analysis to build the new expression.
1553 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001554 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001555 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001557 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 }
Mike Stump11289f42009-09-09 15:08:12 +00001559
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// \brief Build a new __builtin_choose_expr expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001564 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001565 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 SourceLocation RParenLoc) {
1567 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001568 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 RParenLoc);
1570 }
Mike Stump11289f42009-09-09 15:08:12 +00001571
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 /// \brief Build a new overloaded operator call expression.
1573 ///
1574 /// By default, performs semantic analysis to build the new expression.
1575 /// The semantic analysis provides the behavior of template instantiation,
1576 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001577 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 /// argument-dependent lookup, etc. Subclasses may override this routine to
1579 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001580 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001582 Expr *Callee,
1583 Expr *First,
1584 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001585
1586 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// reinterpret_cast.
1588 ///
1589 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001590 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001592 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 Stmt::StmtClass Class,
1594 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001595 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 SourceLocation RAngleLoc,
1597 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001598 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001599 SourceLocation RParenLoc) {
1600 switch (Class) {
1601 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001602 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001603 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001604 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001605
1606 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001607 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001608 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001609 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001610
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001612 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001613 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001614 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001615 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001618 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001619 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001620 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001621
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 default:
1623 assert(false && "Invalid C++ named cast");
1624 break;
1625 }
Mike Stump11289f42009-09-09 15:08:12 +00001626
John McCallfaf5fb42010-08-26 23:41:50 +00001627 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 }
Mike Stump11289f42009-09-09 15:08:12 +00001629
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 /// \brief Build a new C++ static_cast expression.
1631 ///
1632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001634 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001636 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 SourceLocation RAngleLoc,
1638 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001639 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001641 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001642 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001643 SourceRange(LAngleLoc, RAngleLoc),
1644 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 }
1646
1647 /// \brief Build a new C++ dynamic_cast expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001651 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001653 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RAngleLoc,
1655 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001656 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001658 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001659 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001660 SourceRange(LAngleLoc, RAngleLoc),
1661 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 }
1663
1664 /// \brief Build a new C++ reinterpret_cast expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001670 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 SourceLocation RAngleLoc,
1672 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001673 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001675 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001676 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001677 SourceRange(LAngleLoc, RAngleLoc),
1678 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new C++ const_cast expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001685 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation RAngleLoc,
1689 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001692 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001693 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001694 SourceRange(LAngleLoc, RAngleLoc),
1695 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
Mike Stump11289f42009-09-09 15:08:12 +00001697
Douglas Gregora16548e2009-08-11 05:31:07 +00001698 /// \brief Build a new C++ functional-style cast expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001702 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1703 SourceLocation LParenLoc,
1704 Expr *Sub,
1705 SourceLocation RParenLoc) {
1706 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001707 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 RParenLoc);
1709 }
Mike Stump11289f42009-09-09 15:08:12 +00001710
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 /// \brief Build a new C++ typeid(type) expression.
1712 ///
1713 /// By default, performs semantic analysis to build the new expression.
1714 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001715 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001716 SourceLocation TypeidLoc,
1717 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001719 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001720 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 }
Mike Stump11289f42009-09-09 15:08:12 +00001722
Francois Pichet9f4f2072010-09-08 12:20:18 +00001723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 /// \brief Build a new C++ typeid(expr) expression.
1725 ///
1726 /// By default, performs semantic analysis to build the new expression.
1727 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001728 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001729 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001730 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001731 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001732 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001733 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001734 }
1735
Francois Pichet9f4f2072010-09-08 12:20:18 +00001736 /// \brief Build a new C++ __uuidof(type) expression.
1737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
1740 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1741 SourceLocation TypeidLoc,
1742 TypeSourceInfo *Operand,
1743 SourceLocation RParenLoc) {
1744 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1745 RParenLoc);
1746 }
1747
1748 /// \brief Build a new C++ __uuidof(expr) expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
1752 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1753 SourceLocation TypeidLoc,
1754 Expr *Operand,
1755 SourceLocation RParenLoc) {
1756 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1757 RParenLoc);
1758 }
1759
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 /// \brief Build a new C++ "this" expression.
1761 ///
1762 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001763 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001765 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001766 QualType ThisType,
1767 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001769 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1770 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new C++ throw expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001777 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001778 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 }
1780
1781 /// \brief Build a new C++ default-argument expression.
1782 ///
1783 /// By default, builds a new default-argument expression, which does not
1784 /// require any semantic analysis. Subclasses may override this routine to
1785 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001787 ParmVarDecl *Param) {
1788 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1789 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 }
1791
1792 /// \brief Build a new C++ zero-initialization expression.
1793 ///
1794 /// By default, performs semantic analysis to build the new expression.
1795 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001796 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1797 SourceLocation LParenLoc,
1798 SourceLocation RParenLoc) {
1799 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001800 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001801 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001802 }
Mike Stump11289f42009-09-09 15:08:12 +00001803
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 /// \brief Build a new C++ "new" expression.
1805 ///
1806 /// By default, performs semantic analysis to build the new expression.
1807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001808 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001809 bool UseGlobal,
1810 SourceLocation PlacementLParen,
1811 MultiExprArg PlacementArgs,
1812 SourceLocation PlacementRParen,
1813 SourceRange TypeIdParens,
1814 QualType AllocatedType,
1815 TypeSourceInfo *AllocatedTypeInfo,
1816 Expr *ArraySize,
1817 SourceLocation ConstructorLParen,
1818 MultiExprArg ConstructorArgs,
1819 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001820 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 PlacementLParen,
1822 move(PlacementArgs),
1823 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001824 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001825 AllocatedType,
1826 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001827 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 ConstructorLParen,
1829 move(ConstructorArgs),
1830 ConstructorRParen);
1831 }
Mike Stump11289f42009-09-09 15:08:12 +00001832
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// \brief Build a new C++ "delete" expression.
1834 ///
1835 /// By default, performs semantic analysis to build the new expression.
1836 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001837 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 bool IsGlobalDelete,
1839 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001840 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001841 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001842 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 }
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 /// \brief Build a new unary type trait expression.
1846 ///
1847 /// By default, performs semantic analysis to build the new expression.
1848 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001849 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001850 SourceLocation StartLoc,
1851 TypeSourceInfo *T,
1852 SourceLocation RParenLoc) {
1853 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001854 }
1855
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001856 /// \brief Build a new binary type trait expression.
1857 ///
1858 /// By default, performs semantic analysis to build the new expression.
1859 /// Subclasses may override this routine to provide different behavior.
1860 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1861 SourceLocation StartLoc,
1862 TypeSourceInfo *LhsT,
1863 TypeSourceInfo *RhsT,
1864 SourceLocation RParenLoc) {
1865 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1866 }
1867
Mike Stump11289f42009-09-09 15:08:12 +00001868 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001873 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001874 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001875 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001876 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001877 CXXScopeSpec SS;
1878 SS.setRange(QualifierRange);
1879 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001880
1881 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001882 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001883 *TemplateArgs);
1884
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001885 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 }
1887
1888 /// \brief Build a new template-id expression.
1889 ///
1890 /// By default, performs semantic analysis to build the new expression.
1891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001893 LookupResult &R,
1894 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001895 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001896 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 }
1898
1899 /// \brief Build a new object-construction expression.
1900 ///
1901 /// By default, performs semantic analysis to build the new expression.
1902 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001903 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001904 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 CXXConstructorDecl *Constructor,
1906 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001907 MultiExprArg Args,
1908 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001909 CXXConstructExpr::ConstructionKind ConstructKind,
1910 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001911 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001912 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001913 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001914 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001915
Douglas Gregordb121ba2009-12-14 16:27:04 +00001916 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001917 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001918 RequiresZeroInit, ConstructKind,
1919 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001920 }
1921
1922 /// \brief Build a new object-construction expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001926 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1927 SourceLocation LParenLoc,
1928 MultiExprArg Args,
1929 SourceLocation RParenLoc) {
1930 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001931 LParenLoc,
1932 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001933 RParenLoc);
1934 }
1935
1936 /// \brief Build a new object-construction expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001940 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1941 SourceLocation LParenLoc,
1942 MultiExprArg Args,
1943 SourceLocation RParenLoc) {
1944 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001945 LParenLoc,
1946 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 RParenLoc);
1948 }
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregora16548e2009-08-11 05:31:07 +00001950 /// \brief Build a new member reference expression.
1951 ///
1952 /// By default, performs semantic analysis to build the new expression.
1953 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001954 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001955 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 bool IsArrow,
1957 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001958 NestedNameSpecifier *Qualifier,
1959 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001960 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001961 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001962 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001964 SS.setRange(QualifierRange);
1965 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001966
John McCallb268a282010-08-23 23:25:46 +00001967 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001968 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001969 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001970 MemberNameInfo,
1971 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 }
1973
John McCall10eae182009-11-30 22:42:35 +00001974 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001975 ///
1976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001978 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001979 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001980 SourceLocation OperatorLoc,
1981 bool IsArrow,
1982 NestedNameSpecifier *Qualifier,
1983 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001984 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001985 LookupResult &R,
1986 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001987 CXXScopeSpec SS;
1988 SS.setRange(QualifierRange);
1989 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001990
John McCallb268a282010-08-23 23:25:46 +00001991 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001992 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001993 SS, FirstQualifierInScope,
1994 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001995 }
Mike Stump11289f42009-09-09 15:08:12 +00001996
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001997 /// \brief Build a new noexcept expression.
1998 ///
1999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
2001 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2002 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2003 }
2004
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002005 /// \brief Build a new expression to compute the length of a parameter pack.
2006 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2007 SourceLocation PackLoc,
2008 SourceLocation RParenLoc,
2009 unsigned Length) {
2010 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2011 OperatorLoc, Pack, PackLoc,
2012 RParenLoc, Length);
2013 }
2014
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 /// \brief Build a new Objective-C @encode expression.
2016 ///
2017 /// By default, performs semantic analysis to build the new expression.
2018 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002019 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002020 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002022 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002024 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002025
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002026 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002027 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002028 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002029 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002030 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002031 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002032 MultiExprArg Args,
2033 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002034 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2035 ReceiverTypeInfo->getType(),
2036 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002037 Sel, Method, LBracLoc, SelectorLoc,
2038 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002039 }
2040
2041 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002042 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002043 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002044 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002045 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002046 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002047 MultiExprArg Args,
2048 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002049 return SemaRef.BuildInstanceMessage(Receiver,
2050 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002051 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002052 Sel, Method, LBracLoc, SelectorLoc,
2053 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002054 }
2055
Douglas Gregord51d90d2010-04-26 20:11:03 +00002056 /// \brief Build a new Objective-C ivar reference expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002060 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002061 SourceLocation IvarLoc,
2062 bool IsArrow, bool IsFreeIvar) {
2063 // FIXME: We lose track of the IsFreeIvar bit.
2064 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002065 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002066 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2067 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002068 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002069 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002070 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002071 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002072 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002073 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002074
Douglas Gregord51d90d2010-04-26 20:11:03 +00002075 if (Result.get())
2076 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002077
John McCallb268a282010-08-23 23:25:46 +00002078 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002079 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002080 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002081 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002082 /*TemplateArgs=*/0);
2083 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002084
2085 /// \brief Build a new Objective-C property reference expression.
2086 ///
2087 /// By default, performs semantic analysis to build the new expression.
2088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002089 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002090 ObjCPropertyDecl *Property,
2091 SourceLocation PropertyLoc) {
2092 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002093 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002094 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2095 Sema::LookupMemberName);
2096 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002097 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002098 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002099 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002100 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002101 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002102
Douglas Gregor9faee212010-04-26 20:47:02 +00002103 if (Result.get())
2104 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002105
John McCallb268a282010-08-23 23:25:46 +00002106 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002107 /*FIXME:*/PropertyLoc, IsArrow,
2108 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002109 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002110 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002111 /*TemplateArgs=*/0);
2112 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002113
John McCallb7bd14f2010-12-02 01:19:52 +00002114 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002115 ///
2116 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002117 /// Subclasses may override this routine to provide different behavior.
2118 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2119 ObjCMethodDecl *Getter,
2120 ObjCMethodDecl *Setter,
2121 SourceLocation PropertyLoc) {
2122 // Since these expressions can only be value-dependent, we do not
2123 // need to perform semantic analysis again.
2124 return Owned(
2125 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2126 VK_LValue, OK_ObjCProperty,
2127 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002128 }
2129
Douglas Gregord51d90d2010-04-26 20:11:03 +00002130 /// \brief Build a new Objective-C "isa" expression.
2131 ///
2132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002134 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002135 bool IsArrow) {
2136 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002137 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002138 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2139 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002141 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002142 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002143 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002144 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002145
Douglas Gregord51d90d2010-04-26 20:11:03 +00002146 if (Result.get())
2147 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002148
John McCallb268a282010-08-23 23:25:46 +00002149 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002150 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002151 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002152 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002153 /*TemplateArgs=*/0);
2154 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 /// \brief Build a new shuffle vector expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002160 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002161 MultiExprArg SubExprs,
2162 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002164 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2166 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2167 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2168 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 // Build a reference to the __builtin_shufflevector builtin
2171 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002172 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002174 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002175 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002176
2177 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 unsigned NumSubExprs = SubExprs.size();
2179 Expr **Subs = (Expr **)SubExprs.release();
2180 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2181 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002182 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002183 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002185 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002193 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
John McCall31f82722010-11-12 08:19:04 +00002195
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002196 /// \brief Build a new template argument pack expansion.
2197 ///
2198 /// By default, performs semantic analysis to build a new pack expansion
2199 /// for a template argument. Subclasses may override this routine to provide
2200 /// different behavior.
2201 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002202 SourceLocation EllipsisLoc,
2203 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002204 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002205 case TemplateArgument::Expression: {
2206 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002207 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2208 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002209 if (Result.isInvalid())
2210 return TemplateArgumentLoc();
2211
2212 return TemplateArgumentLoc(Result.get(), Result.get());
2213 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002214
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002215 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002216 return TemplateArgumentLoc(TemplateArgument(
2217 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002218 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002219 Pattern.getTemplateQualifierRange(),
2220 Pattern.getTemplateNameLoc(),
2221 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002222
2223 case TemplateArgument::Null:
2224 case TemplateArgument::Integral:
2225 case TemplateArgument::Declaration:
2226 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002227 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002228 llvm_unreachable("Pack expansion pattern has no parameter packs");
2229
2230 case TemplateArgument::Type:
2231 if (TypeSourceInfo *Expansion
2232 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002233 EllipsisLoc,
2234 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002235 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2236 Expansion);
2237 break;
2238 }
2239
2240 return TemplateArgumentLoc();
2241 }
2242
Douglas Gregor968f23a2011-01-03 19:31:53 +00002243 /// \brief Build a new expression pack expansion.
2244 ///
2245 /// By default, performs semantic analysis to build a new pack expansion
2246 /// for an expression. Subclasses may override this routine to provide
2247 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002248 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2249 llvm::Optional<unsigned> NumExpansions) {
2250 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002251 }
2252
John McCall31f82722010-11-12 08:19:04 +00002253private:
2254 QualType TransformTypeInObjectScope(QualType T,
2255 QualType ObjectType,
2256 NamedDecl *FirstQualifierInScope,
2257 NestedNameSpecifier *Prefix);
2258
2259 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2260 QualType ObjectType,
2261 NamedDecl *FirstQualifierInScope,
2262 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002263};
Douglas Gregora16548e2009-08-11 05:31:07 +00002264
Douglas Gregorebe10102009-08-20 07:17:43 +00002265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002266StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002267 if (!S)
2268 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002269
Douglas Gregorebe10102009-08-20 07:17:43 +00002270 switch (S->getStmtClass()) {
2271 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregorebe10102009-08-20 07:17:43 +00002273 // Transform individual statement nodes
2274#define STMT(Node, Parent) \
2275 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002276#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002277#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002278#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002279
Douglas Gregorebe10102009-08-20 07:17:43 +00002280 // Transform expressions by calling TransformExpr.
2281#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002282#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002283#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002284#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002285 {
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002287 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002288 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002289
John McCallb268a282010-08-23 23:25:46 +00002290 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002291 }
Mike Stump11289f42009-09-09 15:08:12 +00002292 }
2293
John McCallc3007a22010-10-26 07:05:15 +00002294 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002295}
Mike Stump11289f42009-09-09 15:08:12 +00002296
2297
Douglas Gregore922c772009-08-04 22:27:00 +00002298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002299ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 if (!E)
2301 return SemaRef.Owned(E);
2302
2303 switch (E->getStmtClass()) {
2304 case Stmt::NoStmtClass: break;
2305#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002306#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002307#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002308 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002309#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002310 }
2311
John McCallc3007a22010-10-26 07:05:15 +00002312 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002313}
2314
2315template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002316bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2317 unsigned NumInputs,
2318 bool IsCall,
2319 llvm::SmallVectorImpl<Expr *> &Outputs,
2320 bool *ArgChanged) {
2321 for (unsigned I = 0; I != NumInputs; ++I) {
2322 // If requested, drop call arguments that need to be dropped.
2323 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2324 if (ArgChanged)
2325 *ArgChanged = true;
2326
2327 break;
2328 }
2329
Douglas Gregor968f23a2011-01-03 19:31:53 +00002330 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2331 Expr *Pattern = Expansion->getPattern();
2332
2333 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2334 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2335 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2336
2337 // Determine whether the set of unexpanded parameter packs can and should
2338 // be expanded.
2339 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002340 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002341 llvm::Optional<unsigned> OrigNumExpansions
2342 = Expansion->getNumExpansions();
2343 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002344 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2345 Pattern->getSourceRange(),
2346 Unexpanded.data(),
2347 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002348 Expand, RetainExpansion,
2349 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002350 return true;
2351
2352 if (!Expand) {
2353 // The transform has determined that we should perform a simple
2354 // transformation on the pack expansion, producing another pack
2355 // expansion.
2356 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2357 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2358 if (OutPattern.isInvalid())
2359 return true;
2360
2361 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002362 Expansion->getEllipsisLoc(),
2363 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002364 if (Out.isInvalid())
2365 return true;
2366
2367 if (ArgChanged)
2368 *ArgChanged = true;
2369 Outputs.push_back(Out.get());
2370 continue;
2371 }
2372
2373 // The transform has determined that we should perform an elementwise
2374 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002375 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002376 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2377 ExprResult Out = getDerived().TransformExpr(Pattern);
2378 if (Out.isInvalid())
2379 return true;
2380
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002381 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002382 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2383 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002384 if (Out.isInvalid())
2385 return true;
2386 }
2387
Douglas Gregor968f23a2011-01-03 19:31:53 +00002388 if (ArgChanged)
2389 *ArgChanged = true;
2390 Outputs.push_back(Out.get());
2391 }
2392
2393 continue;
2394 }
2395
Douglas Gregora3efea12011-01-03 19:04:46 +00002396 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2397 if (Result.isInvalid())
2398 return true;
2399
2400 if (Result.get() != Inputs[I] && ArgChanged)
2401 *ArgChanged = true;
2402
2403 Outputs.push_back(Result.get());
2404 }
2405
2406 return false;
2407}
2408
2409template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002410NestedNameSpecifier *
2411TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002412 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002413 QualType ObjectType,
2414 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002415 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002416
Douglas Gregorebe10102009-08-20 07:17:43 +00002417 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002418 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002419 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002420 ObjectType,
2421 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002422 if (!Prefix)
2423 return 0;
2424 }
Mike Stump11289f42009-09-09 15:08:12 +00002425
Douglas Gregor1135c352009-08-06 05:28:30 +00002426 switch (NNS->getKind()) {
2427 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002428 if (Prefix) {
2429 // The object type and qualifier-in-scope really apply to the
2430 // leftmost entity.
2431 ObjectType = QualType();
2432 FirstQualifierInScope = 0;
2433 }
2434
Mike Stump11289f42009-09-09 15:08:12 +00002435 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002436 "Identifier nested-name-specifier with no prefix or object type");
2437 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2438 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002439 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002440
2441 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002442 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002443 ObjectType,
2444 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregor1135c352009-08-06 05:28:30 +00002446 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002447 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002448 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002449 getDerived().TransformDecl(Range.getBegin(),
2450 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002451 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002452 Prefix == NNS->getPrefix() &&
2453 NS == NNS->getAsNamespace())
2454 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002455
Douglas Gregor1135c352009-08-06 05:28:30 +00002456 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2457 }
Mike Stump11289f42009-09-09 15:08:12 +00002458
Douglas Gregor1135c352009-08-06 05:28:30 +00002459 case NestedNameSpecifier::Global:
2460 // There is no meaningful transformation that one could perform on the
2461 // global scope.
2462 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002463
Douglas Gregor1135c352009-08-06 05:28:30 +00002464 case NestedNameSpecifier::TypeSpecWithTemplate:
2465 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002466 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002467 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2468 ObjectType,
2469 FirstQualifierInScope,
2470 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002471 if (T.isNull())
2472 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002473
Douglas Gregor1135c352009-08-06 05:28:30 +00002474 if (!getDerived().AlwaysRebuild() &&
2475 Prefix == NNS->getPrefix() &&
2476 T == QualType(NNS->getAsType(), 0))
2477 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002478
2479 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2480 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002481 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002482 }
2483 }
Mike Stump11289f42009-09-09 15:08:12 +00002484
Douglas Gregor1135c352009-08-06 05:28:30 +00002485 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002486 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002487}
2488
2489template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002490DeclarationNameInfo
2491TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002492::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002493 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002494 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002495 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002496
2497 switch (Name.getNameKind()) {
2498 case DeclarationName::Identifier:
2499 case DeclarationName::ObjCZeroArgSelector:
2500 case DeclarationName::ObjCOneArgSelector:
2501 case DeclarationName::ObjCMultiArgSelector:
2502 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002503 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002504 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002505 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002506
Douglas Gregorf816bd72009-09-03 22:13:48 +00002507 case DeclarationName::CXXConstructorName:
2508 case DeclarationName::CXXDestructorName:
2509 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002510 TypeSourceInfo *NewTInfo;
2511 CanQualType NewCanTy;
2512 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002513 NewTInfo = getDerived().TransformType(OldTInfo);
2514 if (!NewTInfo)
2515 return DeclarationNameInfo();
2516 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002517 }
2518 else {
2519 NewTInfo = 0;
2520 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002521 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002522 if (NewT.isNull())
2523 return DeclarationNameInfo();
2524 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2525 }
Mike Stump11289f42009-09-09 15:08:12 +00002526
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002527 DeclarationName NewName
2528 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2529 NewCanTy);
2530 DeclarationNameInfo NewNameInfo(NameInfo);
2531 NewNameInfo.setName(NewName);
2532 NewNameInfo.setNamedTypeInfo(NewTInfo);
2533 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002534 }
Mike Stump11289f42009-09-09 15:08:12 +00002535 }
2536
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002537 assert(0 && "Unknown name kind.");
2538 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002539}
2540
2541template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002542TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002543TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002544 QualType ObjectType,
2545 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002546 SourceLocation Loc = getDerived().getBaseLocation();
2547
Douglas Gregor71dc5092009-08-06 06:41:21 +00002548 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002549 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002550 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002551 /*FIXME*/ SourceRange(Loc),
2552 ObjectType,
2553 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002554 if (!NNS)
2555 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002556
Douglas Gregor71dc5092009-08-06 06:41:21 +00002557 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002558 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002559 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002560 if (!TransTemplate)
2561 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002562
Douglas Gregor71dc5092009-08-06 06:41:21 +00002563 if (!getDerived().AlwaysRebuild() &&
2564 NNS == QTN->getQualifier() &&
2565 TransTemplate == Template)
2566 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregor71dc5092009-08-06 06:41:21 +00002568 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2569 TransTemplate);
2570 }
Mike Stump11289f42009-09-09 15:08:12 +00002571
John McCalle66edc12009-11-24 19:00:30 +00002572 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002573 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002574 }
Mike Stump11289f42009-09-09 15:08:12 +00002575
Douglas Gregor71dc5092009-08-06 06:41:21 +00002576 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002577 NestedNameSpecifier *NNS = DTN->getQualifier();
2578 if (NNS) {
2579 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2580 /*FIXME:*/SourceRange(Loc),
2581 ObjectType,
2582 FirstQualifierInScope);
2583 if (!NNS) return TemplateName();
2584
2585 // These apply to the scope specifier, not the template.
2586 ObjectType = QualType();
2587 FirstQualifierInScope = 0;
2588 }
Mike Stump11289f42009-09-09 15:08:12 +00002589
Douglas Gregor71dc5092009-08-06 06:41:21 +00002590 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002591 NNS == DTN->getQualifier() &&
2592 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002593 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002594
Douglas Gregora5614c52010-09-08 23:56:00 +00002595 if (DTN->isIdentifier()) {
2596 // FIXME: Bad range
2597 SourceRange QualifierRange(getDerived().getBaseLocation());
2598 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2599 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002600 ObjectType,
2601 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002602 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002603
2604 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002605 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002606 }
Mike Stump11289f42009-09-09 15:08:12 +00002607
Douglas Gregor71dc5092009-08-06 06:41:21 +00002608 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002609 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002610 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002611 if (!TransTemplate)
2612 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002613
Douglas Gregor71dc5092009-08-06 06:41:21 +00002614 if (!getDerived().AlwaysRebuild() &&
2615 TransTemplate == Template)
2616 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002617
Douglas Gregor71dc5092009-08-06 06:41:21 +00002618 return TemplateName(TransTemplate);
2619 }
Mike Stump11289f42009-09-09 15:08:12 +00002620
Douglas Gregor5590be02011-01-15 06:45:20 +00002621 if (SubstTemplateTemplateParmPackStorage *SubstPack
2622 = Name.getAsSubstTemplateTemplateParmPack()) {
2623 TemplateTemplateParmDecl *TransParam
2624 = cast_or_null<TemplateTemplateParmDecl>(
2625 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2626 if (!TransParam)
2627 return TemplateName();
2628
2629 if (!getDerived().AlwaysRebuild() &&
2630 TransParam == SubstPack->getParameterPack())
2631 return Name;
2632
2633 return getDerived().RebuildTemplateName(TransParam,
2634 SubstPack->getArgumentPack());
2635 }
2636
John McCalle66edc12009-11-24 19:00:30 +00002637 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002638 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002639 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002640}
2641
2642template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002643void TreeTransform<Derived>::InventTemplateArgumentLoc(
2644 const TemplateArgument &Arg,
2645 TemplateArgumentLoc &Output) {
2646 SourceLocation Loc = getDerived().getBaseLocation();
2647 switch (Arg.getKind()) {
2648 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002649 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002650 break;
2651
2652 case TemplateArgument::Type:
2653 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002654 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002655
John McCall0ad16662009-10-29 08:12:44 +00002656 break;
2657
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002658 case TemplateArgument::Template:
2659 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2660 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002661
2662 case TemplateArgument::TemplateExpansion:
2663 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2664 break;
2665
John McCall0ad16662009-10-29 08:12:44 +00002666 case TemplateArgument::Expression:
2667 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2668 break;
2669
2670 case TemplateArgument::Declaration:
2671 case TemplateArgument::Integral:
2672 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002673 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002674 break;
2675 }
2676}
2677
2678template<typename Derived>
2679bool TreeTransform<Derived>::TransformTemplateArgument(
2680 const TemplateArgumentLoc &Input,
2681 TemplateArgumentLoc &Output) {
2682 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002683 switch (Arg.getKind()) {
2684 case TemplateArgument::Null:
2685 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002686 Output = Input;
2687 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002688
Douglas Gregore922c772009-08-04 22:27:00 +00002689 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002690 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002691 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002692 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002693
2694 DI = getDerived().TransformType(DI);
2695 if (!DI) return true;
2696
2697 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2698 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002699 }
Mike Stump11289f42009-09-09 15:08:12 +00002700
Douglas Gregore922c772009-08-04 22:27:00 +00002701 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002702 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002703 DeclarationName Name;
2704 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2705 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002706 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002707 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002708 if (!D) return true;
2709
John McCall0d07eb32009-10-29 18:45:58 +00002710 Expr *SourceExpr = Input.getSourceDeclExpression();
2711 if (SourceExpr) {
2712 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002713 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002714 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002715 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002716 }
2717
2718 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002719 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002720 }
Mike Stump11289f42009-09-09 15:08:12 +00002721
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002722 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002723 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002724 TemplateName Template
2725 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2726 if (Template.isNull())
2727 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002728
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002729 Output = TemplateArgumentLoc(TemplateArgument(Template),
2730 Input.getTemplateQualifierRange(),
2731 Input.getTemplateNameLoc());
2732 return false;
2733 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002734
2735 case TemplateArgument::TemplateExpansion:
2736 llvm_unreachable("Caller should expand pack expansions");
2737
Douglas Gregore922c772009-08-04 22:27:00 +00002738 case TemplateArgument::Expression: {
2739 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002740 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002741 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002742
John McCall0ad16662009-10-29 08:12:44 +00002743 Expr *InputExpr = Input.getSourceExpression();
2744 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2745
John McCalldadc5752010-08-24 06:29:42 +00002746 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002747 = getDerived().TransformExpr(InputExpr);
2748 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002749 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002750 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002751 }
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregore922c772009-08-04 22:27:00 +00002753 case TemplateArgument::Pack: {
2754 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2755 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002756 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002757 AEnd = Arg.pack_end();
2758 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCall0ad16662009-10-29 08:12:44 +00002760 // FIXME: preserve source information here when we start
2761 // caring about parameter packs.
2762
John McCall0d07eb32009-10-29 18:45:58 +00002763 TemplateArgumentLoc InputArg;
2764 TemplateArgumentLoc OutputArg;
2765 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2766 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002767 return true;
2768
John McCall0d07eb32009-10-29 18:45:58 +00002769 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002770 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002771
2772 TemplateArgument *TransformedArgsPtr
2773 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2774 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2775 TransformedArgsPtr);
2776 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2777 TransformedArgs.size()),
2778 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002779 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002780 }
2781 }
Mike Stump11289f42009-09-09 15:08:12 +00002782
Douglas Gregore922c772009-08-04 22:27:00 +00002783 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002784 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002785}
2786
Douglas Gregorfe921a72010-12-20 23:36:19 +00002787/// \brief Iterator adaptor that invents template argument location information
2788/// for each of the template arguments in its underlying iterator.
2789template<typename Derived, typename InputIterator>
2790class TemplateArgumentLocInventIterator {
2791 TreeTransform<Derived> &Self;
2792 InputIterator Iter;
2793
2794public:
2795 typedef TemplateArgumentLoc value_type;
2796 typedef TemplateArgumentLoc reference;
2797 typedef typename std::iterator_traits<InputIterator>::difference_type
2798 difference_type;
2799 typedef std::input_iterator_tag iterator_category;
2800
2801 class pointer {
2802 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002803
Douglas Gregorfe921a72010-12-20 23:36:19 +00002804 public:
2805 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2806
2807 const TemplateArgumentLoc *operator->() const { return &Arg; }
2808 };
2809
2810 TemplateArgumentLocInventIterator() { }
2811
2812 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2813 InputIterator Iter)
2814 : Self(Self), Iter(Iter) { }
2815
2816 TemplateArgumentLocInventIterator &operator++() {
2817 ++Iter;
2818 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002819 }
2820
Douglas Gregorfe921a72010-12-20 23:36:19 +00002821 TemplateArgumentLocInventIterator operator++(int) {
2822 TemplateArgumentLocInventIterator Old(*this);
2823 ++(*this);
2824 return Old;
2825 }
2826
2827 reference operator*() const {
2828 TemplateArgumentLoc Result;
2829 Self.InventTemplateArgumentLoc(*Iter, Result);
2830 return Result;
2831 }
2832
2833 pointer operator->() const { return pointer(**this); }
2834
2835 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2836 const TemplateArgumentLocInventIterator &Y) {
2837 return X.Iter == Y.Iter;
2838 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002839
Douglas Gregorfe921a72010-12-20 23:36:19 +00002840 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2841 const TemplateArgumentLocInventIterator &Y) {
2842 return X.Iter != Y.Iter;
2843 }
2844};
2845
Douglas Gregor42cafa82010-12-20 17:42:22 +00002846template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002847template<typename InputIterator>
2848bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2849 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002850 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002851 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002852 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002853 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002854
2855 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2856 // Unpack argument packs, which we translate them into separate
2857 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002858 // FIXME: We could do much better if we could guarantee that the
2859 // TemplateArgumentLocInfo for the pack expansion would be usable for
2860 // all of the template arguments in the argument pack.
2861 typedef TemplateArgumentLocInventIterator<Derived,
2862 TemplateArgument::pack_iterator>
2863 PackLocIterator;
2864 if (TransformTemplateArguments(PackLocIterator(*this,
2865 In.getArgument().pack_begin()),
2866 PackLocIterator(*this,
2867 In.getArgument().pack_end()),
2868 Outputs))
2869 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002870
2871 continue;
2872 }
2873
2874 if (In.getArgument().isPackExpansion()) {
2875 // We have a pack expansion, for which we will be substituting into
2876 // the pattern.
2877 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002878 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002879 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002880 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2881 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002882
2883 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2884 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2885 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2886
2887 // Determine whether the set of unexpanded parameter packs can and should
2888 // be expanded.
2889 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002890 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002891 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002892 if (getDerived().TryExpandParameterPacks(Ellipsis,
2893 Pattern.getSourceRange(),
2894 Unexpanded.data(),
2895 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002896 Expand,
2897 RetainExpansion,
2898 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002899 return true;
2900
2901 if (!Expand) {
2902 // The transform has determined that we should perform a simple
2903 // transformation on the pack expansion, producing another pack
2904 // expansion.
2905 TemplateArgumentLoc OutPattern;
2906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2907 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2908 return true;
2909
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002910 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2911 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002912 if (Out.getArgument().isNull())
2913 return true;
2914
2915 Outputs.addArgument(Out);
2916 continue;
2917 }
2918
2919 // The transform has determined that we should perform an elementwise
2920 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002921 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002922 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2923
2924 if (getDerived().TransformTemplateArgument(Pattern, Out))
2925 return true;
2926
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002927 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002928 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2929 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002930 if (Out.getArgument().isNull())
2931 return true;
2932 }
2933
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002934 Outputs.addArgument(Out);
2935 }
2936
Douglas Gregor48d24112011-01-10 20:53:55 +00002937 // If we're supposed to retain a pack expansion, do so by temporarily
2938 // forgetting the partially-substituted parameter pack.
2939 if (RetainExpansion) {
2940 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2941
2942 if (getDerived().TransformTemplateArgument(Pattern, Out))
2943 return true;
2944
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002945 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
2946 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00002947 if (Out.getArgument().isNull())
2948 return true;
2949
2950 Outputs.addArgument(Out);
2951 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002952
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002953 continue;
2954 }
2955
2956 // The simple case:
2957 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002958 return true;
2959
2960 Outputs.addArgument(Out);
2961 }
2962
2963 return false;
2964
2965}
2966
Douglas Gregord6ff3322009-08-04 16:50:30 +00002967//===----------------------------------------------------------------------===//
2968// Type transformation
2969//===----------------------------------------------------------------------===//
2970
2971template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002972QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002973 if (getDerived().AlreadyTransformed(T))
2974 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002975
John McCall550e0c22009-10-21 00:40:46 +00002976 // Temporary workaround. All of these transformations should
2977 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00002978 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
2979 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002980
John McCall31f82722010-11-12 08:19:04 +00002981 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002982
John McCall550e0c22009-10-21 00:40:46 +00002983 if (!NewDI)
2984 return QualType();
2985
2986 return NewDI->getType();
2987}
2988
2989template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002990TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002991 if (getDerived().AlreadyTransformed(DI->getType()))
2992 return DI;
2993
2994 TypeLocBuilder TLB;
2995
2996 TypeLoc TL = DI->getTypeLoc();
2997 TLB.reserve(TL.getFullDataSize());
2998
John McCall31f82722010-11-12 08:19:04 +00002999 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003000 if (Result.isNull())
3001 return 0;
3002
John McCallbcd03502009-12-07 02:54:59 +00003003 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003004}
3005
3006template<typename Derived>
3007QualType
John McCall31f82722010-11-12 08:19:04 +00003008TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003009 switch (T.getTypeLocClass()) {
3010#define ABSTRACT_TYPELOC(CLASS, PARENT)
3011#define TYPELOC(CLASS, PARENT) \
3012 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003013 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003014#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003015 }
Mike Stump11289f42009-09-09 15:08:12 +00003016
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003017 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003018 return QualType();
3019}
3020
3021/// FIXME: By default, this routine adds type qualifiers only to types
3022/// that can have qualifiers, and silently suppresses those qualifiers
3023/// that are not permitted (e.g., qualifiers on reference or function
3024/// types). This is the right thing for template instantiation, but
3025/// probably not for other clients.
3026template<typename Derived>
3027QualType
3028TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003029 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003030 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003031
John McCall31f82722010-11-12 08:19:04 +00003032 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003033 if (Result.isNull())
3034 return QualType();
3035
3036 // Silently suppress qualifiers if the result type can't be qualified.
3037 // FIXME: this is the right thing for template instantiation, but
3038 // probably not for other clients.
3039 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003040 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003041
John McCallcb0f89a2010-06-05 06:41:15 +00003042 if (!Quals.empty()) {
3043 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3044 TLB.push<QualifiedTypeLoc>(Result);
3045 // No location information to preserve.
3046 }
John McCall550e0c22009-10-21 00:40:46 +00003047
3048 return Result;
3049}
3050
John McCall31f82722010-11-12 08:19:04 +00003051/// \brief Transforms a type that was written in a scope specifier,
3052/// given an object type, the results of unqualified lookup, and
3053/// an already-instantiated prefix.
3054///
3055/// The object type is provided iff the scope specifier qualifies the
3056/// member of a dependent member-access expression. The prefix is
3057/// provided iff the the scope specifier in which this appears has a
3058/// prefix.
3059///
3060/// This is private to TreeTransform.
3061template<typename Derived>
3062QualType
3063TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3064 QualType ObjectType,
3065 NamedDecl *UnqualLookup,
3066 NestedNameSpecifier *Prefix) {
3067 if (getDerived().AlreadyTransformed(T))
3068 return T;
3069
3070 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003071 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003072
3073 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3074 UnqualLookup, Prefix);
3075 if (!TSI) return QualType();
3076 return TSI->getType();
3077}
3078
3079template<typename Derived>
3080TypeSourceInfo *
3081TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3082 QualType ObjectType,
3083 NamedDecl *UnqualLookup,
3084 NestedNameSpecifier *Prefix) {
3085 // TODO: in some cases, we might be some verification to do here.
3086 if (ObjectType.isNull())
3087 return getDerived().TransformType(TSI);
3088
3089 QualType T = TSI->getType();
3090 if (getDerived().AlreadyTransformed(T))
3091 return TSI;
3092
3093 TypeLocBuilder TLB;
3094 QualType Result;
3095
3096 if (isa<TemplateSpecializationType>(T)) {
3097 TemplateSpecializationTypeLoc TL
3098 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3099
3100 TemplateName Template =
3101 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3102 ObjectType, UnqualLookup);
3103 if (Template.isNull()) return 0;
3104
3105 Result = getDerived()
3106 .TransformTemplateSpecializationType(TLB, TL, Template);
3107 } else if (isa<DependentTemplateSpecializationType>(T)) {
3108 DependentTemplateSpecializationTypeLoc TL
3109 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3110
3111 Result = getDerived()
3112 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3113 } else {
3114 // Nothing special needs to be done for these.
3115 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3116 }
3117
3118 if (Result.isNull()) return 0;
3119 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3120}
3121
John McCall550e0c22009-10-21 00:40:46 +00003122template <class TyLoc> static inline
3123QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3124 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3125 NewT.setNameLoc(T.getNameLoc());
3126 return T.getType();
3127}
3128
John McCall550e0c22009-10-21 00:40:46 +00003129template<typename Derived>
3130QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003131 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003132 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3133 NewT.setBuiltinLoc(T.getBuiltinLoc());
3134 if (T.needsExtraLocalData())
3135 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3136 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003137}
Mike Stump11289f42009-09-09 15:08:12 +00003138
Douglas Gregord6ff3322009-08-04 16:50:30 +00003139template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003140QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003141 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003142 // FIXME: recurse?
3143 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144}
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003147QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003148 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003149 QualType PointeeType
3150 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003151 if (PointeeType.isNull())
3152 return QualType();
3153
3154 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003155 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003156 // A dependent pointer type 'T *' has is being transformed such
3157 // that an Objective-C class type is being replaced for 'T'. The
3158 // resulting pointer type is an ObjCObjectPointerType, not a
3159 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003160 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003161
John McCall8b07ec22010-05-15 11:32:37 +00003162 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3163 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003164 return Result;
3165 }
John McCall31f82722010-11-12 08:19:04 +00003166
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003167 if (getDerived().AlwaysRebuild() ||
3168 PointeeType != TL.getPointeeLoc().getType()) {
3169 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3170 if (Result.isNull())
3171 return QualType();
3172 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003173
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003174 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3175 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003176 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003177}
Mike Stump11289f42009-09-09 15:08:12 +00003178
3179template<typename Derived>
3180QualType
John McCall550e0c22009-10-21 00:40:46 +00003181TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003182 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003183 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003184 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3185 if (PointeeType.isNull())
3186 return QualType();
3187
3188 QualType Result = TL.getType();
3189 if (getDerived().AlwaysRebuild() ||
3190 PointeeType != TL.getPointeeLoc().getType()) {
3191 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003192 TL.getSigilLoc());
3193 if (Result.isNull())
3194 return QualType();
3195 }
3196
Douglas Gregor049211a2010-04-22 16:50:51 +00003197 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003198 NewT.setSigilLoc(TL.getSigilLoc());
3199 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003200}
3201
John McCall70dd5f62009-10-30 00:06:24 +00003202/// Transforms a reference type. Note that somewhat paradoxically we
3203/// don't care whether the type itself is an l-value type or an r-value
3204/// type; we only care if the type was *written* as an l-value type
3205/// or an r-value type.
3206template<typename Derived>
3207QualType
3208TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003209 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003210 const ReferenceType *T = TL.getTypePtr();
3211
3212 // Note that this works with the pointee-as-written.
3213 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3214 if (PointeeType.isNull())
3215 return QualType();
3216
3217 QualType Result = TL.getType();
3218 if (getDerived().AlwaysRebuild() ||
3219 PointeeType != T->getPointeeTypeAsWritten()) {
3220 Result = getDerived().RebuildReferenceType(PointeeType,
3221 T->isSpelledAsLValue(),
3222 TL.getSigilLoc());
3223 if (Result.isNull())
3224 return QualType();
3225 }
3226
3227 // r-value references can be rebuilt as l-value references.
3228 ReferenceTypeLoc NewTL;
3229 if (isa<LValueReferenceType>(Result))
3230 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3231 else
3232 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3233 NewTL.setSigilLoc(TL.getSigilLoc());
3234
3235 return Result;
3236}
3237
Mike Stump11289f42009-09-09 15:08:12 +00003238template<typename Derived>
3239QualType
John McCall550e0c22009-10-21 00:40:46 +00003240TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003241 LValueReferenceTypeLoc TL) {
3242 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003243}
3244
Mike Stump11289f42009-09-09 15:08:12 +00003245template<typename Derived>
3246QualType
John McCall550e0c22009-10-21 00:40:46 +00003247TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003248 RValueReferenceTypeLoc TL) {
3249 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003250}
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregord6ff3322009-08-04 16:50:30 +00003252template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003253QualType
John McCall550e0c22009-10-21 00:40:46 +00003254TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003255 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003256 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003257
3258 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003259 if (PointeeType.isNull())
3260 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003261
John McCall550e0c22009-10-21 00:40:46 +00003262 // TODO: preserve source information for this.
3263 QualType ClassType
3264 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003265 if (ClassType.isNull())
3266 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003267
John McCall550e0c22009-10-21 00:40:46 +00003268 QualType Result = TL.getType();
3269 if (getDerived().AlwaysRebuild() ||
3270 PointeeType != T->getPointeeType() ||
3271 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003272 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3273 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003274 if (Result.isNull())
3275 return QualType();
3276 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003277
John McCall550e0c22009-10-21 00:40:46 +00003278 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3279 NewTL.setSigilLoc(TL.getSigilLoc());
3280
3281 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282}
3283
Mike Stump11289f42009-09-09 15:08:12 +00003284template<typename Derived>
3285QualType
John McCall550e0c22009-10-21 00:40:46 +00003286TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003287 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003288 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003289 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290 if (ElementType.isNull())
3291 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003292
John McCall550e0c22009-10-21 00:40:46 +00003293 QualType Result = TL.getType();
3294 if (getDerived().AlwaysRebuild() ||
3295 ElementType != T->getElementType()) {
3296 Result = getDerived().RebuildConstantArrayType(ElementType,
3297 T->getSizeModifier(),
3298 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003299 T->getIndexTypeCVRQualifiers(),
3300 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003301 if (Result.isNull())
3302 return QualType();
3303 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003304
John McCall550e0c22009-10-21 00:40:46 +00003305 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3306 NewTL.setLBracketLoc(TL.getLBracketLoc());
3307 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003308
John McCall550e0c22009-10-21 00:40:46 +00003309 Expr *Size = TL.getSizeExpr();
3310 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003311 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003312 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3313 }
3314 NewTL.setSizeExpr(Size);
3315
3316 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317}
Mike Stump11289f42009-09-09 15:08:12 +00003318
Douglas Gregord6ff3322009-08-04 16:50:30 +00003319template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003321 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003322 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003323 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003324 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325 if (ElementType.isNull())
3326 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003327
John McCall550e0c22009-10-21 00:40:46 +00003328 QualType Result = TL.getType();
3329 if (getDerived().AlwaysRebuild() ||
3330 ElementType != T->getElementType()) {
3331 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003333 T->getIndexTypeCVRQualifiers(),
3334 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003335 if (Result.isNull())
3336 return QualType();
3337 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003338
John McCall550e0c22009-10-21 00:40:46 +00003339 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3340 NewTL.setLBracketLoc(TL.getLBracketLoc());
3341 NewTL.setRBracketLoc(TL.getRBracketLoc());
3342 NewTL.setSizeExpr(0);
3343
3344 return Result;
3345}
3346
3347template<typename Derived>
3348QualType
3349TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003350 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003351 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003352 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3353 if (ElementType.isNull())
3354 return QualType();
3355
3356 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003357 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003358
John McCalldadc5752010-08-24 06:29:42 +00003359 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003360 = getDerived().TransformExpr(T->getSizeExpr());
3361 if (SizeResult.isInvalid())
3362 return QualType();
3363
John McCallb268a282010-08-23 23:25:46 +00003364 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003365
3366 QualType Result = TL.getType();
3367 if (getDerived().AlwaysRebuild() ||
3368 ElementType != T->getElementType() ||
3369 Size != T->getSizeExpr()) {
3370 Result = getDerived().RebuildVariableArrayType(ElementType,
3371 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003372 Size,
John McCall550e0c22009-10-21 00:40:46 +00003373 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003374 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003375 if (Result.isNull())
3376 return QualType();
3377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003378
John McCall550e0c22009-10-21 00:40:46 +00003379 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3380 NewTL.setLBracketLoc(TL.getLBracketLoc());
3381 NewTL.setRBracketLoc(TL.getRBracketLoc());
3382 NewTL.setSizeExpr(Size);
3383
3384 return Result;
3385}
3386
3387template<typename Derived>
3388QualType
3389TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003390 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003391 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003392 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3393 if (ElementType.isNull())
3394 return QualType();
3395
3396 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003398
John McCall33ddac02011-01-19 10:06:00 +00003399 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3400 Expr *origSize = TL.getSizeExpr();
3401 if (!origSize) origSize = T->getSizeExpr();
3402
3403 ExprResult sizeResult
3404 = getDerived().TransformExpr(origSize);
3405 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003406 return QualType();
3407
John McCall33ddac02011-01-19 10:06:00 +00003408 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003409
3410 QualType Result = TL.getType();
3411 if (getDerived().AlwaysRebuild() ||
3412 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003413 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003414 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3415 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003416 size,
John McCall550e0c22009-10-21 00:40:46 +00003417 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003418 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003419 if (Result.isNull())
3420 return QualType();
3421 }
John McCall550e0c22009-10-21 00:40:46 +00003422
3423 // We might have any sort of array type now, but fortunately they
3424 // all have the same location layout.
3425 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3426 NewTL.setLBracketLoc(TL.getLBracketLoc());
3427 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003428 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003429
3430 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003431}
Mike Stump11289f42009-09-09 15:08:12 +00003432
3433template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003434QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003435 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003436 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003437 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003438
3439 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003440 QualType ElementType = getDerived().TransformType(T->getElementType());
3441 if (ElementType.isNull())
3442 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003443
Douglas Gregore922c772009-08-04 22:27:00 +00003444 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003445 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003446
John McCalldadc5752010-08-24 06:29:42 +00003447 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003448 if (Size.isInvalid())
3449 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003450
John McCall550e0c22009-10-21 00:40:46 +00003451 QualType Result = TL.getType();
3452 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003453 ElementType != T->getElementType() ||
3454 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003455 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003456 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003457 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003458 if (Result.isNull())
3459 return QualType();
3460 }
John McCall550e0c22009-10-21 00:40:46 +00003461
3462 // Result might be dependent or not.
3463 if (isa<DependentSizedExtVectorType>(Result)) {
3464 DependentSizedExtVectorTypeLoc NewTL
3465 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3466 NewTL.setNameLoc(TL.getNameLoc());
3467 } else {
3468 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3469 NewTL.setNameLoc(TL.getNameLoc());
3470 }
3471
3472 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003473}
Mike Stump11289f42009-09-09 15:08:12 +00003474
3475template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003476QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003477 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003478 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003479 QualType ElementType = getDerived().TransformType(T->getElementType());
3480 if (ElementType.isNull())
3481 return QualType();
3482
John McCall550e0c22009-10-21 00:40:46 +00003483 QualType Result = TL.getType();
3484 if (getDerived().AlwaysRebuild() ||
3485 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003486 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003487 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003488 if (Result.isNull())
3489 return QualType();
3490 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003491
John McCall550e0c22009-10-21 00:40:46 +00003492 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3493 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003494
John McCall550e0c22009-10-21 00:40:46 +00003495 return Result;
3496}
3497
3498template<typename Derived>
3499QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003500 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003501 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003502 QualType ElementType = getDerived().TransformType(T->getElementType());
3503 if (ElementType.isNull())
3504 return QualType();
3505
3506 QualType Result = TL.getType();
3507 if (getDerived().AlwaysRebuild() ||
3508 ElementType != T->getElementType()) {
3509 Result = getDerived().RebuildExtVectorType(ElementType,
3510 T->getNumElements(),
3511 /*FIXME*/ SourceLocation());
3512 if (Result.isNull())
3513 return QualType();
3514 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003515
John McCall550e0c22009-10-21 00:40:46 +00003516 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3517 NewTL.setNameLoc(TL.getNameLoc());
3518
3519 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003520}
Mike Stump11289f42009-09-09 15:08:12 +00003521
3522template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003523ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003524TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3525 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003526 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003527 TypeSourceInfo *NewDI = 0;
3528
3529 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3530 // If we're substituting into a pack expansion type and we know the
3531 TypeLoc OldTL = OldDI->getTypeLoc();
3532 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3533
3534 TypeLocBuilder TLB;
3535 TypeLoc NewTL = OldDI->getTypeLoc();
3536 TLB.reserve(NewTL.getFullDataSize());
3537
3538 QualType Result = getDerived().TransformType(TLB,
3539 OldExpansionTL.getPatternLoc());
3540 if (Result.isNull())
3541 return 0;
3542
3543 Result = RebuildPackExpansionType(Result,
3544 OldExpansionTL.getPatternLoc().getSourceRange(),
3545 OldExpansionTL.getEllipsisLoc(),
3546 NumExpansions);
3547 if (Result.isNull())
3548 return 0;
3549
3550 PackExpansionTypeLoc NewExpansionTL
3551 = TLB.push<PackExpansionTypeLoc>(Result);
3552 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3553 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3554 } else
3555 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003556 if (!NewDI)
3557 return 0;
3558
3559 if (NewDI == OldDI)
3560 return OldParm;
3561 else
3562 return ParmVarDecl::Create(SemaRef.Context,
3563 OldParm->getDeclContext(),
3564 OldParm->getLocation(),
3565 OldParm->getIdentifier(),
3566 NewDI->getType(),
3567 NewDI,
3568 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003569 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003570 /* DefArg */ NULL);
3571}
3572
3573template<typename Derived>
3574bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003575 TransformFunctionTypeParams(SourceLocation Loc,
3576 ParmVarDecl **Params, unsigned NumParams,
3577 const QualType *ParamTypes,
3578 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3579 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3580 for (unsigned i = 0; i != NumParams; ++i) {
3581 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003582 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003583 if (OldParm->isParameterPack()) {
3584 // We have a function parameter pack that may need to be expanded.
3585 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003586
Douglas Gregor5499af42011-01-05 23:12:31 +00003587 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003588 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3589 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3590 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3591 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003592
3593 // Determine whether we should expand the parameter packs.
3594 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003595 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003596 llvm::Optional<unsigned> OrigNumExpansions
3597 = ExpansionTL.getTypePtr()->getNumExpansions();
3598 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003599 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3600 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003601 Unexpanded.data(),
3602 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003603 ShouldExpand,
3604 RetainExpansion,
3605 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003606 return true;
3607 }
3608
3609 if (ShouldExpand) {
3610 // Expand the function parameter pack into multiple, separate
3611 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003612 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003613 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003614 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3615 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003616 = getDerived().TransformFunctionTypeParam(OldParm,
3617 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003618 if (!NewParm)
3619 return true;
3620
Douglas Gregordd472162011-01-07 00:20:55 +00003621 OutParamTypes.push_back(NewParm->getType());
3622 if (PVars)
3623 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003624 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003625
3626 // If we're supposed to retain a pack expansion, do so by temporarily
3627 // forgetting the partially-substituted parameter pack.
3628 if (RetainExpansion) {
3629 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3630 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003631 = getDerived().TransformFunctionTypeParam(OldParm,
3632 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003633 if (!NewParm)
3634 return true;
3635
3636 OutParamTypes.push_back(NewParm->getType());
3637 if (PVars)
3638 PVars->push_back(NewParm);
3639 }
3640
Douglas Gregor5499af42011-01-05 23:12:31 +00003641 // We're done with the pack expansion.
3642 continue;
3643 }
3644
3645 // We'll substitute the parameter now without expanding the pack
3646 // expansion.
3647 }
3648
3649 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003650 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3651 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003652 if (!NewParm)
3653 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003654
Douglas Gregordd472162011-01-07 00:20:55 +00003655 OutParamTypes.push_back(NewParm->getType());
3656 if (PVars)
3657 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003658 continue;
3659 }
John McCall58f10c32010-03-11 09:03:00 +00003660
3661 // Deal with the possibility that we don't have a parameter
3662 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003663 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003664 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003665 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003666 if (const PackExpansionType *Expansion
3667 = dyn_cast<PackExpansionType>(OldType)) {
3668 // We have a function parameter pack that may need to be expanded.
3669 QualType Pattern = Expansion->getPattern();
3670 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3671 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3672
3673 // Determine whether we should expand the parameter packs.
3674 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003675 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003676 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003677 Unexpanded.data(),
3678 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003679 ShouldExpand,
3680 RetainExpansion,
3681 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003682 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003683 }
3684
3685 if (ShouldExpand) {
3686 // Expand the function parameter pack into multiple, separate
3687 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003688 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003689 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3690 QualType NewType = getDerived().TransformType(Pattern);
3691 if (NewType.isNull())
3692 return true;
John McCall58f10c32010-03-11 09:03:00 +00003693
Douglas Gregordd472162011-01-07 00:20:55 +00003694 OutParamTypes.push_back(NewType);
3695 if (PVars)
3696 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003697 }
3698
3699 // We're done with the pack expansion.
3700 continue;
3701 }
3702
Douglas Gregor48d24112011-01-10 20:53:55 +00003703 // If we're supposed to retain a pack expansion, do so by temporarily
3704 // forgetting the partially-substituted parameter pack.
3705 if (RetainExpansion) {
3706 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3707 QualType NewType = getDerived().TransformType(Pattern);
3708 if (NewType.isNull())
3709 return true;
3710
3711 OutParamTypes.push_back(NewType);
3712 if (PVars)
3713 PVars->push_back(0);
3714 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003715
Douglas Gregor5499af42011-01-05 23:12:31 +00003716 // We'll substitute the parameter now without expanding the pack
3717 // expansion.
3718 OldType = Expansion->getPattern();
3719 IsPackExpansion = true;
3720 }
3721
3722 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3723 QualType NewType = getDerived().TransformType(OldType);
3724 if (NewType.isNull())
3725 return true;
3726
3727 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003728 NewType = getSema().Context.getPackExpansionType(NewType,
3729 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003730
Douglas Gregordd472162011-01-07 00:20:55 +00003731 OutParamTypes.push_back(NewType);
3732 if (PVars)
3733 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003734 }
3735
3736 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003737 }
John McCall58f10c32010-03-11 09:03:00 +00003738
3739template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003740QualType
John McCall550e0c22009-10-21 00:40:46 +00003741TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003742 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003743 // Transform the parameters and return type.
3744 //
3745 // We instantiate in source order, with the return type first followed by
3746 // the parameters, because users tend to expect this (even if they shouldn't
3747 // rely on it!).
3748 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003749 // When the function has a trailing return type, we instantiate the
3750 // parameters before the return type, since the return type can then refer
3751 // to the parameters themselves (via decltype, sizeof, etc.).
3752 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003753 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003754 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003755 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003756
Douglas Gregor7fb25412010-10-01 18:44:50 +00003757 QualType ResultType;
3758
3759 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003760 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3761 TL.getParmArray(),
3762 TL.getNumArgs(),
3763 TL.getTypePtr()->arg_type_begin(),
3764 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003765 return QualType();
3766
3767 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3768 if (ResultType.isNull())
3769 return QualType();
3770 }
3771 else {
3772 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3773 if (ResultType.isNull())
3774 return QualType();
3775
Douglas Gregordd472162011-01-07 00:20:55 +00003776 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3777 TL.getParmArray(),
3778 TL.getNumArgs(),
3779 TL.getTypePtr()->arg_type_begin(),
3780 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003781 return QualType();
3782 }
3783
John McCall550e0c22009-10-21 00:40:46 +00003784 QualType Result = TL.getType();
3785 if (getDerived().AlwaysRebuild() ||
3786 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003787 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003788 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3789 Result = getDerived().RebuildFunctionProtoType(ResultType,
3790 ParamTypes.data(),
3791 ParamTypes.size(),
3792 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003793 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003794 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003795 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003796 if (Result.isNull())
3797 return QualType();
3798 }
Mike Stump11289f42009-09-09 15:08:12 +00003799
John McCall550e0c22009-10-21 00:40:46 +00003800 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3801 NewTL.setLParenLoc(TL.getLParenLoc());
3802 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003803 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003804 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3805 NewTL.setArg(i, ParamDecls[i]);
3806
3807 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003808}
Mike Stump11289f42009-09-09 15:08:12 +00003809
Douglas Gregord6ff3322009-08-04 16:50:30 +00003810template<typename Derived>
3811QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003812 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003813 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003814 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003815 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3816 if (ResultType.isNull())
3817 return QualType();
3818
3819 QualType Result = TL.getType();
3820 if (getDerived().AlwaysRebuild() ||
3821 ResultType != T->getResultType())
3822 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3823
3824 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3825 NewTL.setLParenLoc(TL.getLParenLoc());
3826 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003827 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003828
3829 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003830}
Mike Stump11289f42009-09-09 15:08:12 +00003831
John McCallb96ec562009-12-04 22:46:56 +00003832template<typename Derived> QualType
3833TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003834 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003835 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003836 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003837 if (!D)
3838 return QualType();
3839
3840 QualType Result = TL.getType();
3841 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3842 Result = getDerived().RebuildUnresolvedUsingType(D);
3843 if (Result.isNull())
3844 return QualType();
3845 }
3846
3847 // We might get an arbitrary type spec type back. We should at
3848 // least always get a type spec type, though.
3849 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3850 NewTL.setNameLoc(TL.getNameLoc());
3851
3852 return Result;
3853}
3854
Douglas Gregord6ff3322009-08-04 16:50:30 +00003855template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003856QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003857 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003858 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003859 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003860 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3861 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862 if (!Typedef)
3863 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003864
John McCall550e0c22009-10-21 00:40:46 +00003865 QualType Result = TL.getType();
3866 if (getDerived().AlwaysRebuild() ||
3867 Typedef != T->getDecl()) {
3868 Result = getDerived().RebuildTypedefType(Typedef);
3869 if (Result.isNull())
3870 return QualType();
3871 }
Mike Stump11289f42009-09-09 15:08:12 +00003872
John McCall550e0c22009-10-21 00:40:46 +00003873 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3874 NewTL.setNameLoc(TL.getNameLoc());
3875
3876 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003877}
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregord6ff3322009-08-04 16:50:30 +00003879template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003880QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003881 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003882 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003883 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003884
John McCalldadc5752010-08-24 06:29:42 +00003885 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003886 if (E.isInvalid())
3887 return QualType();
3888
John McCall550e0c22009-10-21 00:40:46 +00003889 QualType Result = TL.getType();
3890 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003891 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003892 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003893 if (Result.isNull())
3894 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003895 }
John McCall550e0c22009-10-21 00:40:46 +00003896 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003897
John McCall550e0c22009-10-21 00:40:46 +00003898 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003899 NewTL.setTypeofLoc(TL.getTypeofLoc());
3900 NewTL.setLParenLoc(TL.getLParenLoc());
3901 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003902
3903 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003904}
Mike Stump11289f42009-09-09 15:08:12 +00003905
3906template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003907QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003908 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003909 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3910 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3911 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003912 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003913
John McCall550e0c22009-10-21 00:40:46 +00003914 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003915 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3916 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003917 if (Result.isNull())
3918 return QualType();
3919 }
Mike Stump11289f42009-09-09 15:08:12 +00003920
John McCall550e0c22009-10-21 00:40:46 +00003921 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003922 NewTL.setTypeofLoc(TL.getTypeofLoc());
3923 NewTL.setLParenLoc(TL.getLParenLoc());
3924 NewTL.setRParenLoc(TL.getRParenLoc());
3925 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003926
3927 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003928}
Mike Stump11289f42009-09-09 15:08:12 +00003929
3930template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003931QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003932 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003933 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003934
Douglas Gregore922c772009-08-04 22:27:00 +00003935 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003936 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003937
John McCalldadc5752010-08-24 06:29:42 +00003938 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003939 if (E.isInvalid())
3940 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003941
John McCall550e0c22009-10-21 00:40:46 +00003942 QualType Result = TL.getType();
3943 if (getDerived().AlwaysRebuild() ||
3944 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003945 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003946 if (Result.isNull())
3947 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003948 }
John McCall550e0c22009-10-21 00:40:46 +00003949 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003950
John McCall550e0c22009-10-21 00:40:46 +00003951 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3952 NewTL.setNameLoc(TL.getNameLoc());
3953
3954 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003955}
3956
3957template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00003958QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
3959 AutoTypeLoc TL) {
3960 const AutoType *T = TL.getTypePtr();
3961 QualType OldDeduced = T->getDeducedType();
3962 QualType NewDeduced;
3963 if (!OldDeduced.isNull()) {
3964 NewDeduced = getDerived().TransformType(OldDeduced);
3965 if (NewDeduced.isNull())
3966 return QualType();
3967 }
3968
3969 QualType Result = TL.getType();
3970 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
3971 Result = getDerived().RebuildAutoType(NewDeduced);
3972 if (Result.isNull())
3973 return QualType();
3974 }
3975
3976 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
3977 NewTL.setNameLoc(TL.getNameLoc());
3978
3979 return Result;
3980}
3981
3982template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003983QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003984 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003985 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003987 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3988 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003989 if (!Record)
3990 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003991
John McCall550e0c22009-10-21 00:40:46 +00003992 QualType Result = TL.getType();
3993 if (getDerived().AlwaysRebuild() ||
3994 Record != T->getDecl()) {
3995 Result = getDerived().RebuildRecordType(Record);
3996 if (Result.isNull())
3997 return QualType();
3998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
John McCall550e0c22009-10-21 00:40:46 +00004000 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4001 NewTL.setNameLoc(TL.getNameLoc());
4002
4003 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004004}
Mike Stump11289f42009-09-09 15:08:12 +00004005
4006template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004007QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004008 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004009 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004010 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004011 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4012 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004013 if (!Enum)
4014 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004015
John McCall550e0c22009-10-21 00:40:46 +00004016 QualType Result = TL.getType();
4017 if (getDerived().AlwaysRebuild() ||
4018 Enum != T->getDecl()) {
4019 Result = getDerived().RebuildEnumType(Enum);
4020 if (Result.isNull())
4021 return QualType();
4022 }
Mike Stump11289f42009-09-09 15:08:12 +00004023
John McCall550e0c22009-10-21 00:40:46 +00004024 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4025 NewTL.setNameLoc(TL.getNameLoc());
4026
4027 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004028}
John McCallfcc33b02009-09-05 00:15:47 +00004029
John McCalle78aac42010-03-10 03:28:59 +00004030template<typename Derived>
4031QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4032 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004033 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004034 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4035 TL.getTypePtr()->getDecl());
4036 if (!D) return QualType();
4037
4038 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4039 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4040 return T;
4041}
4042
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043template<typename Derived>
4044QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004045 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004046 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004047 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004048}
4049
Mike Stump11289f42009-09-09 15:08:12 +00004050template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004051QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004052 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004053 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004054 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004055}
4056
4057template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004058QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4059 TypeLocBuilder &TLB,
4060 SubstTemplateTypeParmPackTypeLoc TL) {
4061 return TransformTypeSpecType(TLB, TL);
4062}
4063
4064template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004065QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004066 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004067 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004068 const TemplateSpecializationType *T = TL.getTypePtr();
4069
Mike Stump11289f42009-09-09 15:08:12 +00004070 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004071 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004072 if (Template.isNull())
4073 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004074
John McCall31f82722010-11-12 08:19:04 +00004075 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4076}
4077
Douglas Gregorfe921a72010-12-20 23:36:19 +00004078namespace {
4079 /// \brief Simple iterator that traverses the template arguments in a
4080 /// container that provides a \c getArgLoc() member function.
4081 ///
4082 /// This iterator is intended to be used with the iterator form of
4083 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4084 template<typename ArgLocContainer>
4085 class TemplateArgumentLocContainerIterator {
4086 ArgLocContainer *Container;
4087 unsigned Index;
4088
4089 public:
4090 typedef TemplateArgumentLoc value_type;
4091 typedef TemplateArgumentLoc reference;
4092 typedef int difference_type;
4093 typedef std::input_iterator_tag iterator_category;
4094
4095 class pointer {
4096 TemplateArgumentLoc Arg;
4097
4098 public:
4099 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4100
4101 const TemplateArgumentLoc *operator->() const {
4102 return &Arg;
4103 }
4104 };
4105
4106
4107 TemplateArgumentLocContainerIterator() {}
4108
4109 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4110 unsigned Index)
4111 : Container(&Container), Index(Index) { }
4112
4113 TemplateArgumentLocContainerIterator &operator++() {
4114 ++Index;
4115 return *this;
4116 }
4117
4118 TemplateArgumentLocContainerIterator operator++(int) {
4119 TemplateArgumentLocContainerIterator Old(*this);
4120 ++(*this);
4121 return Old;
4122 }
4123
4124 TemplateArgumentLoc operator*() const {
4125 return Container->getArgLoc(Index);
4126 }
4127
4128 pointer operator->() const {
4129 return pointer(Container->getArgLoc(Index));
4130 }
4131
4132 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004133 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004134 return X.Container == Y.Container && X.Index == Y.Index;
4135 }
4136
4137 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004138 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004139 return !(X == Y);
4140 }
4141 };
4142}
4143
4144
John McCall31f82722010-11-12 08:19:04 +00004145template <typename Derived>
4146QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4147 TypeLocBuilder &TLB,
4148 TemplateSpecializationTypeLoc TL,
4149 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004150 TemplateArgumentListInfo NewTemplateArgs;
4151 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4152 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004153 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4154 ArgIterator;
4155 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4156 ArgIterator(TL, TL.getNumArgs()),
4157 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004158 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall0ad16662009-10-29 08:12:44 +00004160 // FIXME: maybe don't rebuild if all the template arguments are the same.
4161
4162 QualType Result =
4163 getDerived().RebuildTemplateSpecializationType(Template,
4164 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004165 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004166
4167 if (!Result.isNull()) {
4168 TemplateSpecializationTypeLoc NewTL
4169 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4170 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4171 NewTL.setLAngleLoc(TL.getLAngleLoc());
4172 NewTL.setRAngleLoc(TL.getRAngleLoc());
4173 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4174 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175 }
Mike Stump11289f42009-09-09 15:08:12 +00004176
John McCall0ad16662009-10-29 08:12:44 +00004177 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004178}
Mike Stump11289f42009-09-09 15:08:12 +00004179
4180template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004181QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004182TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004183 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004184 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004185
4186 NestedNameSpecifier *NNS = 0;
4187 // NOTE: the qualifier in an ElaboratedType is optional.
4188 if (T->getQualifier() != 0) {
4189 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004190 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004191 if (!NNS)
4192 return QualType();
4193 }
Mike Stump11289f42009-09-09 15:08:12 +00004194
John McCall31f82722010-11-12 08:19:04 +00004195 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4196 if (NamedT.isNull())
4197 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004198
John McCall550e0c22009-10-21 00:40:46 +00004199 QualType Result = TL.getType();
4200 if (getDerived().AlwaysRebuild() ||
4201 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004202 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004203 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4204 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004205 if (Result.isNull())
4206 return QualType();
4207 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004208
Abramo Bagnara6150c882010-05-11 21:36:43 +00004209 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004210 NewTL.setKeywordLoc(TL.getKeywordLoc());
4211 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004212
4213 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004214}
Mike Stump11289f42009-09-09 15:08:12 +00004215
4216template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004217QualType TreeTransform<Derived>::TransformAttributedType(
4218 TypeLocBuilder &TLB,
4219 AttributedTypeLoc TL) {
4220 const AttributedType *oldType = TL.getTypePtr();
4221 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4222 if (modifiedType.isNull())
4223 return QualType();
4224
4225 QualType result = TL.getType();
4226
4227 // FIXME: dependent operand expressions?
4228 if (getDerived().AlwaysRebuild() ||
4229 modifiedType != oldType->getModifiedType()) {
4230 // TODO: this is really lame; we should really be rebuilding the
4231 // equivalent type from first principles.
4232 QualType equivalentType
4233 = getDerived().TransformType(oldType->getEquivalentType());
4234 if (equivalentType.isNull())
4235 return QualType();
4236 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4237 modifiedType,
4238 equivalentType);
4239 }
4240
4241 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4242 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4243 if (TL.hasAttrOperand())
4244 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4245 if (TL.hasAttrExprOperand())
4246 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4247 else if (TL.hasAttrEnumOperand())
4248 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4249
4250 return result;
4251}
4252
4253template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004254QualType
4255TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4256 ParenTypeLoc TL) {
4257 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4258 if (Inner.isNull())
4259 return QualType();
4260
4261 QualType Result = TL.getType();
4262 if (getDerived().AlwaysRebuild() ||
4263 Inner != TL.getInnerLoc().getType()) {
4264 Result = getDerived().RebuildParenType(Inner);
4265 if (Result.isNull())
4266 return QualType();
4267 }
4268
4269 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4270 NewTL.setLParenLoc(TL.getLParenLoc());
4271 NewTL.setRParenLoc(TL.getRParenLoc());
4272 return Result;
4273}
4274
4275template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004276QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004277 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004278 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004279
Douglas Gregord6ff3322009-08-04 16:50:30 +00004280 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004281 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004282 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004283 if (!NNS)
4284 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004285
John McCallc392f372010-06-11 00:33:02 +00004286 QualType Result
4287 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4288 T->getIdentifier(),
4289 TL.getKeywordLoc(),
4290 TL.getQualifierRange(),
4291 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004292 if (Result.isNull())
4293 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004294
Abramo Bagnarad7548482010-05-19 21:37:53 +00004295 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4296 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004297 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4298
Abramo Bagnarad7548482010-05-19 21:37:53 +00004299 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4300 NewTL.setKeywordLoc(TL.getKeywordLoc());
4301 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004302 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004303 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4304 NewTL.setKeywordLoc(TL.getKeywordLoc());
4305 NewTL.setQualifierRange(TL.getQualifierRange());
4306 NewTL.setNameLoc(TL.getNameLoc());
4307 }
John McCall550e0c22009-10-21 00:40:46 +00004308 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregord6ff3322009-08-04 16:50:30 +00004311template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004312QualType TreeTransform<Derived>::
4313 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004314 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004315 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004316
4317 NestedNameSpecifier *NNS
4318 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004319 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004320 if (!NNS)
4321 return QualType();
4322
John McCall31f82722010-11-12 08:19:04 +00004323 return getDerived()
4324 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4325}
4326
4327template<typename Derived>
4328QualType TreeTransform<Derived>::
4329 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4330 DependentTemplateSpecializationTypeLoc TL,
4331 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004332 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004333
John McCallc392f372010-06-11 00:33:02 +00004334 TemplateArgumentListInfo NewTemplateArgs;
4335 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4336 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004337
4338 typedef TemplateArgumentLocContainerIterator<
4339 DependentTemplateSpecializationTypeLoc> ArgIterator;
4340 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4341 ArgIterator(TL, TL.getNumArgs()),
4342 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004343 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004344
Douglas Gregora5614c52010-09-08 23:56:00 +00004345 QualType Result
4346 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4347 NNS,
4348 TL.getQualifierRange(),
4349 T->getIdentifier(),
4350 TL.getNameLoc(),
4351 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004352 if (Result.isNull())
4353 return QualType();
4354
4355 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4356 QualType NamedT = ElabT->getNamedType();
4357
4358 // Copy information relevant to the template specialization.
4359 TemplateSpecializationTypeLoc NamedTL
4360 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4361 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4362 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4363 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4364 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4365
4366 // Copy information relevant to the elaborated type.
4367 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4368 NewTL.setKeywordLoc(TL.getKeywordLoc());
4369 NewTL.setQualifierRange(TL.getQualifierRange());
4370 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004371 TypeLoc NewTL(Result, TL.getOpaqueData());
4372 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004373 }
4374 return Result;
4375}
4376
4377template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004378QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4379 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004380 QualType Pattern
4381 = getDerived().TransformType(TLB, TL.getPatternLoc());
4382 if (Pattern.isNull())
4383 return QualType();
4384
4385 QualType Result = TL.getType();
4386 if (getDerived().AlwaysRebuild() ||
4387 Pattern != TL.getPatternLoc().getType()) {
4388 Result = getDerived().RebuildPackExpansionType(Pattern,
4389 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004390 TL.getEllipsisLoc(),
4391 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004392 if (Result.isNull())
4393 return QualType();
4394 }
4395
4396 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4397 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4398 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004399}
4400
4401template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004402QualType
4403TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004404 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004405 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004406 TLB.pushFullCopy(TL);
4407 return TL.getType();
4408}
4409
4410template<typename Derived>
4411QualType
4412TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004413 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004414 // ObjCObjectType is never dependent.
4415 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004416 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004417}
Mike Stump11289f42009-09-09 15:08:12 +00004418
4419template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004420QualType
4421TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004422 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004423 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004424 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004425 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004426}
4427
Douglas Gregord6ff3322009-08-04 16:50:30 +00004428//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004429// Statement transformation
4430//===----------------------------------------------------------------------===//
4431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004432StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004433TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004434 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004435}
4436
4437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004438StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004439TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4440 return getDerived().TransformCompoundStmt(S, false);
4441}
4442
4443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004444StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004445TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004446 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004447 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004448 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004449 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004450 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4451 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004452 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004453 if (Result.isInvalid()) {
4454 // Immediately fail if this was a DeclStmt, since it's very
4455 // likely that this will cause problems for future statements.
4456 if (isa<DeclStmt>(*B))
4457 return StmtError();
4458
4459 // Otherwise, just keep processing substatements and fail later.
4460 SubStmtInvalid = true;
4461 continue;
4462 }
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregorebe10102009-08-20 07:17:43 +00004464 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4465 Statements.push_back(Result.takeAs<Stmt>());
4466 }
Mike Stump11289f42009-09-09 15:08:12 +00004467
John McCall1ababa62010-08-27 19:56:05 +00004468 if (SubStmtInvalid)
4469 return StmtError();
4470
Douglas Gregorebe10102009-08-20 07:17:43 +00004471 if (!getDerived().AlwaysRebuild() &&
4472 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004473 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004474
4475 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4476 move_arg(Statements),
4477 S->getRBracLoc(),
4478 IsStmtExpr);
4479}
Mike Stump11289f42009-09-09 15:08:12 +00004480
Douglas Gregorebe10102009-08-20 07:17:43 +00004481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004482StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004483TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004484 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004485 {
4486 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004487 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004488
Eli Friedman06577382009-11-19 03:14:00 +00004489 // Transform the left-hand case value.
4490 LHS = getDerived().TransformExpr(S->getLHS());
4491 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004492 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004493
Eli Friedman06577382009-11-19 03:14:00 +00004494 // Transform the right-hand case value (for the GNU case-range extension).
4495 RHS = getDerived().TransformExpr(S->getRHS());
4496 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004497 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004498 }
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregorebe10102009-08-20 07:17:43 +00004500 // Build the case statement.
4501 // Case statements are always rebuilt so that they will attached to their
4502 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004503 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004504 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004505 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004506 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004507 S->getColonLoc());
4508 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004509 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregorebe10102009-08-20 07:17:43 +00004511 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004512 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004513 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004514 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004515
Douglas Gregorebe10102009-08-20 07:17:43 +00004516 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004517 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004518}
4519
4520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004521StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004522TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004523 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004524 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004525 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004526 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregorebe10102009-08-20 07:17:43 +00004528 // Default statements are always rebuilt
4529 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004530 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004531}
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregorebe10102009-08-20 07:17:43 +00004533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004534StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004535TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004536 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004537 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004538 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004539
Chris Lattnercab02a62011-02-17 20:34:02 +00004540 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4541 S->getDecl());
4542 if (!LD)
4543 return StmtError();
4544
4545
Douglas Gregorebe10102009-08-20 07:17:43 +00004546 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004547 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004548 cast<LabelDecl>(LD), SourceLocation(),
4549 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004550}
Mike Stump11289f42009-09-09 15:08:12 +00004551
Douglas Gregorebe10102009-08-20 07:17:43 +00004552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004553StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004554TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004555 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004556 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004557 VarDecl *ConditionVar = 0;
4558 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004559 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004560 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004561 getDerived().TransformDefinition(
4562 S->getConditionVariable()->getLocation(),
4563 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004564 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004565 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004566 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004567 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004568
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004569 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004570 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004571
4572 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004573 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004574 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4575 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004576 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004577 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004578
John McCallb268a282010-08-23 23:25:46 +00004579 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004580 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004581 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004582
John McCallb268a282010-08-23 23:25:46 +00004583 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4584 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004585 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004586
Douglas Gregorebe10102009-08-20 07:17:43 +00004587 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004588 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004589 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004590 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregorebe10102009-08-20 07:17:43 +00004592 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004593 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004594 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004595 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregorebe10102009-08-20 07:17:43 +00004597 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004598 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004599 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004600 Then.get() == S->getThen() &&
4601 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004602 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004603
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004604 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004605 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004606 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004607}
4608
4609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004610StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004611TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004612 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004613 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004614 VarDecl *ConditionVar = 0;
4615 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004616 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004617 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004618 getDerived().TransformDefinition(
4619 S->getConditionVariable()->getLocation(),
4620 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004621 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004622 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004623 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004624 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004625
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004626 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004627 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004628 }
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregorebe10102009-08-20 07:17:43 +00004630 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004631 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004632 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004633 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004634 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004635 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregorebe10102009-08-20 07:17:43 +00004637 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004638 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004639 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004640 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregorebe10102009-08-20 07:17:43 +00004642 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004643 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4644 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004645}
Mike Stump11289f42009-09-09 15:08:12 +00004646
Douglas Gregorebe10102009-08-20 07:17:43 +00004647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004648StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004649TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004650 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004651 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004652 VarDecl *ConditionVar = 0;
4653 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004654 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004655 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004656 getDerived().TransformDefinition(
4657 S->getConditionVariable()->getLocation(),
4658 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004659 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004660 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004661 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004662 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004663
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004664 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004665 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004666
4667 if (S->getCond()) {
4668 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004669 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4670 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004671 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004672 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004673 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004674 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004675 }
Mike Stump11289f42009-09-09 15:08:12 +00004676
John McCallb268a282010-08-23 23:25:46 +00004677 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4678 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004679 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004680
Douglas Gregorebe10102009-08-20 07:17:43 +00004681 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004682 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004683 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004684 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregorebe10102009-08-20 07:17:43 +00004686 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004687 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004688 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004689 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004690 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004692 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004693 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004694}
Mike Stump11289f42009-09-09 15:08:12 +00004695
Douglas Gregorebe10102009-08-20 07:17:43 +00004696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004697StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004698TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004700 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004701 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004702 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004703
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004704 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004705 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004706 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004707 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004708
Douglas Gregorebe10102009-08-20 07:17:43 +00004709 if (!getDerived().AlwaysRebuild() &&
4710 Cond.get() == S->getCond() &&
4711 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004712 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004713
John McCallb268a282010-08-23 23:25:46 +00004714 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4715 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004716 S->getRParenLoc());
4717}
Mike Stump11289f42009-09-09 15:08:12 +00004718
Douglas Gregorebe10102009-08-20 07:17:43 +00004719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004720StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004721TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004722 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004723 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004724 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004725 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregorebe10102009-08-20 07:17:43 +00004727 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004728 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004729 VarDecl *ConditionVar = 0;
4730 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004731 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004732 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004733 getDerived().TransformDefinition(
4734 S->getConditionVariable()->getLocation(),
4735 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004736 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004737 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004738 } else {
4739 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004740
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004741 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004742 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004743
4744 if (S->getCond()) {
4745 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004746 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4747 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004748 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004749 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004750
John McCallb268a282010-08-23 23:25:46 +00004751 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004752 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004753 }
Mike Stump11289f42009-09-09 15:08:12 +00004754
John McCallb268a282010-08-23 23:25:46 +00004755 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4756 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004757 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004758
Douglas Gregorebe10102009-08-20 07:17:43 +00004759 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004760 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004761 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004762 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004763
John McCallb268a282010-08-23 23:25:46 +00004764 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4765 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004766 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004767
Douglas Gregorebe10102009-08-20 07:17:43 +00004768 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004769 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004770 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004771 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 if (!getDerived().AlwaysRebuild() &&
4774 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004775 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004776 Inc.get() == S->getInc() &&
4777 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004778 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregorebe10102009-08-20 07:17:43 +00004780 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004781 Init.get(), FullCond, ConditionVar,
4782 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004783}
4784
4785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004786StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004787TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004788 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4789 S->getLabel());
4790 if (!LD)
4791 return StmtError();
4792
Douglas Gregorebe10102009-08-20 07:17:43 +00004793 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004794 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004795 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004796}
4797
4798template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004799StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004800TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004801 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004802 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregorebe10102009-08-20 07:17:43 +00004805 if (!getDerived().AlwaysRebuild() &&
4806 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004807 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004808
4809 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004810 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004811}
4812
4813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004814StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004815TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004816 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004817}
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregorebe10102009-08-20 07:17:43 +00004819template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004820StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004821TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004822 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004823}
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregorebe10102009-08-20 07:17:43 +00004825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004826StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004827TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004828 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004829 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004830 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004831
Mike Stump11289f42009-09-09 15:08:12 +00004832 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004833 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004834 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004835}
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregorebe10102009-08-20 07:17:43 +00004837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004838StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004839TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004840 bool DeclChanged = false;
4841 llvm::SmallVector<Decl *, 4> Decls;
4842 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4843 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004844 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4845 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004846 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004847 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregorebe10102009-08-20 07:17:43 +00004849 if (Transformed != *D)
4850 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregorebe10102009-08-20 07:17:43 +00004852 Decls.push_back(Transformed);
4853 }
Mike Stump11289f42009-09-09 15:08:12 +00004854
Douglas Gregorebe10102009-08-20 07:17:43 +00004855 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004856 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004857
4858 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004859 S->getStartLoc(), S->getEndLoc());
4860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregorebe10102009-08-20 07:17:43 +00004862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004863StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004864TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004865
John McCall37ad5512010-08-23 06:44:23 +00004866 ASTOwningVector<Expr*> Constraints(getSema());
4867 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004868 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004869
John McCalldadc5752010-08-24 06:29:42 +00004870 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004871 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004872
4873 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004874
Anders Carlssonaaeef072010-01-24 05:50:09 +00004875 // Go through the outputs.
4876 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004877 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004878
Anders Carlssonaaeef072010-01-24 05:50:09 +00004879 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004880 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004881
Anders Carlssonaaeef072010-01-24 05:50:09 +00004882 // Transform the output expr.
4883 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004884 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004885 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004886 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004887
Anders Carlssonaaeef072010-01-24 05:50:09 +00004888 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004889
John McCallb268a282010-08-23 23:25:46 +00004890 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004891 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004892
Anders Carlssonaaeef072010-01-24 05:50:09 +00004893 // Go through the inputs.
4894 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004895 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004896
Anders Carlssonaaeef072010-01-24 05:50:09 +00004897 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004898 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004899
Anders Carlssonaaeef072010-01-24 05:50:09 +00004900 // Transform the input expr.
4901 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004902 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004903 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004904 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004905
Anders Carlssonaaeef072010-01-24 05:50:09 +00004906 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004907
John McCallb268a282010-08-23 23:25:46 +00004908 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004909 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004910
Anders Carlssonaaeef072010-01-24 05:50:09 +00004911 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004912 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004913
4914 // Go through the clobbers.
4915 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004916 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004917
4918 // No need to transform the asm string literal.
4919 AsmString = SemaRef.Owned(S->getAsmString());
4920
4921 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4922 S->isSimple(),
4923 S->isVolatile(),
4924 S->getNumOutputs(),
4925 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004926 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004927 move_arg(Constraints),
4928 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004929 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004930 move_arg(Clobbers),
4931 S->getRParenLoc(),
4932 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004933}
4934
4935
4936template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004937StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004938TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004939 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004940 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004941 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004942 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004943
Douglas Gregor96c79492010-04-23 22:50:49 +00004944 // Transform the @catch statements (if present).
4945 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004946 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004947 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004948 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004949 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004950 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004951 if (Catch.get() != S->getCatchStmt(I))
4952 AnyCatchChanged = true;
4953 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004954 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004955
Douglas Gregor306de2f2010-04-22 23:59:56 +00004956 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004957 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004958 if (S->getFinallyStmt()) {
4959 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4960 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004961 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004962 }
4963
4964 // If nothing changed, just retain this statement.
4965 if (!getDerived().AlwaysRebuild() &&
4966 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004967 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004968 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004969 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004970
Douglas Gregor306de2f2010-04-22 23:59:56 +00004971 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004972 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4973 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004974}
Mike Stump11289f42009-09-09 15:08:12 +00004975
Douglas Gregorebe10102009-08-20 07:17:43 +00004976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004977StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004978TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004979 // Transform the @catch parameter, if there is one.
4980 VarDecl *Var = 0;
4981 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4982 TypeSourceInfo *TSInfo = 0;
4983 if (FromVar->getTypeSourceInfo()) {
4984 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4985 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004986 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004987 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004988
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004989 QualType T;
4990 if (TSInfo)
4991 T = TSInfo->getType();
4992 else {
4993 T = getDerived().TransformType(FromVar->getType());
4994 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004995 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004996 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004997
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004998 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4999 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005001 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005002
John McCalldadc5752010-08-24 06:29:42 +00005003 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005004 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005005 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005006
5007 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005008 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005009 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005010}
Mike Stump11289f42009-09-09 15:08:12 +00005011
Douglas Gregorebe10102009-08-20 07:17:43 +00005012template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005013StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005014TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005015 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005016 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005017 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005019
Douglas Gregor306de2f2010-04-22 23:59:56 +00005020 // If nothing changed, just retain this statement.
5021 if (!getDerived().AlwaysRebuild() &&
5022 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005023 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005024
5025 // Build a new statement.
5026 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005027 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005028}
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregorebe10102009-08-20 07:17:43 +00005030template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005031StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005032TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005033 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005034 if (S->getThrowExpr()) {
5035 Operand = getDerived().TransformExpr(S->getThrowExpr());
5036 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005037 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005038 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005039
Douglas Gregor2900c162010-04-22 21:44:01 +00005040 if (!getDerived().AlwaysRebuild() &&
5041 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005042 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005043
John McCallb268a282010-08-23 23:25:46 +00005044 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005045}
Mike Stump11289f42009-09-09 15:08:12 +00005046
Douglas Gregorebe10102009-08-20 07:17:43 +00005047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005048StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005049TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005050 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005051 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005052 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005053 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005054 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005055
Douglas Gregor6148de72010-04-22 22:01:21 +00005056 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005057 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005058 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005059 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005060
Douglas Gregor6148de72010-04-22 22:01:21 +00005061 // If nothing change, just retain the current statement.
5062 if (!getDerived().AlwaysRebuild() &&
5063 Object.get() == S->getSynchExpr() &&
5064 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005065 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005066
5067 // Build a new statement.
5068 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005069 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005070}
5071
5072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005073StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005074TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005075 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005076 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005077 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005078 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005079 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005080
Douglas Gregorf68a5082010-04-22 23:10:45 +00005081 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005082 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005083 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005084 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005085
Douglas Gregorf68a5082010-04-22 23:10:45 +00005086 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005087 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005088 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005089 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005090
Douglas Gregorf68a5082010-04-22 23:10:45 +00005091 // If nothing changed, just retain this statement.
5092 if (!getDerived().AlwaysRebuild() &&
5093 Element.get() == S->getElement() &&
5094 Collection.get() == S->getCollection() &&
5095 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005096 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005097
Douglas Gregorf68a5082010-04-22 23:10:45 +00005098 // Build a new statement.
5099 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5100 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005101 Element.get(),
5102 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005103 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005104 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005105}
5106
5107
5108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005109StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005110TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5111 // Transform the exception declaration, if any.
5112 VarDecl *Var = 0;
5113 if (S->getExceptionDecl()) {
5114 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005115 TypeSourceInfo *T = getDerived().TransformType(
5116 ExceptionDecl->getTypeSourceInfo());
5117 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005118 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005120 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005121 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005122 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005123 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005125 }
Mike Stump11289f42009-09-09 15:08:12 +00005126
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005128 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005129 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregorebe10102009-08-20 07:17:43 +00005132 if (!getDerived().AlwaysRebuild() &&
5133 !Var &&
5134 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005135 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005136
5137 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5138 Var,
John McCallb268a282010-08-23 23:25:46 +00005139 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005140}
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregorebe10102009-08-20 07:17:43 +00005142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005143StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005144TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5145 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005146 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005147 = getDerived().TransformCompoundStmt(S->getTryBlock());
5148 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005149 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregorebe10102009-08-20 07:17:43 +00005151 // Transform the handlers.
5152 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005153 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005154 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005155 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005156 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5157 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005158 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregorebe10102009-08-20 07:17:43 +00005160 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5161 Handlers.push_back(Handler.takeAs<Stmt>());
5162 }
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregorebe10102009-08-20 07:17:43 +00005164 if (!getDerived().AlwaysRebuild() &&
5165 TryBlock.get() == S->getTryBlock() &&
5166 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005167 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005168
John McCallb268a282010-08-23 23:25:46 +00005169 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005170 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005171}
Mike Stump11289f42009-09-09 15:08:12 +00005172
Douglas Gregorebe10102009-08-20 07:17:43 +00005173//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005174// Expression transformation
5175//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005176template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005177ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005178TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005179 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005180}
Mike Stump11289f42009-09-09 15:08:12 +00005181
5182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005184TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005185 NestedNameSpecifier *Qualifier = 0;
5186 if (E->getQualifier()) {
5187 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005188 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005189 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005190 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005191 }
John McCallce546572009-12-08 09:08:17 +00005192
5193 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005194 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5195 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005196 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005198
John McCall815039a2010-08-17 21:27:17 +00005199 DeclarationNameInfo NameInfo = E->getNameInfo();
5200 if (NameInfo.getName()) {
5201 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5202 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005203 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005204 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005205
5206 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005207 Qualifier == E->getQualifier() &&
5208 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005209 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005210 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005211
5212 // Mark it referenced in the new context regardless.
5213 // FIXME: this is a bit instantiation-specific.
5214 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5215
John McCallc3007a22010-10-26 07:05:15 +00005216 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005217 }
John McCallce546572009-12-08 09:08:17 +00005218
5219 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005220 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005221 TemplateArgs = &TransArgs;
5222 TransArgs.setLAngleLoc(E->getLAngleLoc());
5223 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005224 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5225 E->getNumTemplateArgs(),
5226 TransArgs))
5227 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005228 }
5229
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005230 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005231 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005232}
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregora16548e2009-08-11 05:31:07 +00005234template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005235ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005236TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005237 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005238}
Mike Stump11289f42009-09-09 15:08:12 +00005239
Douglas Gregora16548e2009-08-11 05:31:07 +00005240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005241ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005242TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005243 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005244}
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregora16548e2009-08-11 05:31:07 +00005246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005248TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005249 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005250}
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregora16548e2009-08-11 05:31:07 +00005252template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005253ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005255 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005256}
Mike Stump11289f42009-09-09 15:08:12 +00005257
Douglas Gregora16548e2009-08-11 05:31:07 +00005258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005259ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005260TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005261 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005262}
5263
5264template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005265ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005266TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005267 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005269 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005272 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005273
John McCallb268a282010-08-23 23:25:46 +00005274 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005275 E->getRParen());
5276}
5277
Mike Stump11289f42009-09-09 15:08:12 +00005278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005280TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005281 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005284
Douglas Gregora16548e2009-08-11 05:31:07 +00005285 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005286 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005287
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5289 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005290 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005291}
Mike Stump11289f42009-09-09 15:08:12 +00005292
Douglas Gregora16548e2009-08-11 05:31:07 +00005293template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005294ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005295TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5296 // Transform the type.
5297 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5298 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005299 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005300
Douglas Gregor882211c2010-04-28 22:16:22 +00005301 // Transform all of the components into components similar to what the
5302 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005303 // FIXME: It would be slightly more efficient in the non-dependent case to
5304 // just map FieldDecls, rather than requiring the rebuilder to look for
5305 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005306 // template code that we don't care.
5307 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005308 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005309 typedef OffsetOfExpr::OffsetOfNode Node;
5310 llvm::SmallVector<Component, 4> Components;
5311 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5312 const Node &ON = E->getComponent(I);
5313 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005314 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005315 Comp.LocStart = ON.getRange().getBegin();
5316 Comp.LocEnd = ON.getRange().getEnd();
5317 switch (ON.getKind()) {
5318 case Node::Array: {
5319 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005320 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005321 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005322 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregor882211c2010-04-28 22:16:22 +00005324 ExprChanged = ExprChanged || Index.get() != FromIndex;
5325 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005326 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005327 break;
5328 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005329
Douglas Gregor882211c2010-04-28 22:16:22 +00005330 case Node::Field:
5331 case Node::Identifier:
5332 Comp.isBrackets = false;
5333 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005334 if (!Comp.U.IdentInfo)
5335 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005336
Douglas Gregor882211c2010-04-28 22:16:22 +00005337 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005338
Douglas Gregord1702062010-04-29 00:18:15 +00005339 case Node::Base:
5340 // Will be recomputed during the rebuild.
5341 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005342 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005343
Douglas Gregor882211c2010-04-28 22:16:22 +00005344 Components.push_back(Comp);
5345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005346
Douglas Gregor882211c2010-04-28 22:16:22 +00005347 // If nothing changed, retain the existing expression.
5348 if (!getDerived().AlwaysRebuild() &&
5349 Type == E->getTypeSourceInfo() &&
5350 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005351 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005352
Douglas Gregor882211c2010-04-28 22:16:22 +00005353 // Build a new offsetof expression.
5354 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5355 Components.data(), Components.size(),
5356 E->getRParenLoc());
5357}
5358
5359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005360ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005361TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5362 assert(getDerived().AlreadyTransformed(E->getType()) &&
5363 "opaque value expression requires transformation");
5364 return SemaRef.Owned(E);
5365}
5366
5367template<typename Derived>
5368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005369TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005370 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005371 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005372
John McCallbcd03502009-12-07 02:54:59 +00005373 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005374 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005375 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005376
John McCall4c98fd82009-11-04 07:28:41 +00005377 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005378 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005379
John McCall4c98fd82009-11-04 07:28:41 +00005380 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005381 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 E->getSourceRange());
5383 }
Mike Stump11289f42009-09-09 15:08:12 +00005384
John McCalldadc5752010-08-24 06:29:42 +00005385 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005386 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 // C++0x [expr.sizeof]p1:
5388 // The operand is either an expression, which is an unevaluated operand
5389 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005390 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregora16548e2009-08-11 05:31:07 +00005392 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5393 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005394 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005397 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 }
Mike Stump11289f42009-09-09 15:08:12 +00005399
John McCallb268a282010-08-23 23:25:46 +00005400 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005401 E->isSizeOf(),
5402 E->getSourceRange());
5403}
Mike Stump11289f42009-09-09 15:08:12 +00005404
Douglas Gregora16548e2009-08-11 05:31:07 +00005405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005406ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005407TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005408 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005411
John McCalldadc5752010-08-24 06:29:42 +00005412 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005415
5416
Douglas Gregora16548e2009-08-11 05:31:07 +00005417 if (!getDerived().AlwaysRebuild() &&
5418 LHS.get() == E->getLHS() &&
5419 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005420 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005421
John McCallb268a282010-08-23 23:25:46 +00005422 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005423 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005424 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005425 E->getRBracketLoc());
5426}
Mike Stump11289f42009-09-09 15:08:12 +00005427
5428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005429ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005430TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005431 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005432 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005435
5436 // Transform arguments.
5437 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005438 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005439 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5440 &ArgChanged))
5441 return ExprError();
5442
Douglas Gregora16548e2009-08-11 05:31:07 +00005443 if (!getDerived().AlwaysRebuild() &&
5444 Callee.get() == E->getCallee() &&
5445 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005446 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005449 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005451 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005452 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005453 E->getRParenLoc());
5454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
5456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005458TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005459 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005460 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005463 NestedNameSpecifier *Qualifier = 0;
5464 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005465 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005466 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005467 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005468 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005470 }
Mike Stump11289f42009-09-09 15:08:12 +00005471
Eli Friedman2cfcef62009-12-04 06:40:45 +00005472 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005473 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5474 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005475 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005477
John McCall16df1e52010-03-30 21:47:33 +00005478 NamedDecl *FoundDecl = E->getFoundDecl();
5479 if (FoundDecl == E->getMemberDecl()) {
5480 FoundDecl = Member;
5481 } else {
5482 FoundDecl = cast_or_null<NamedDecl>(
5483 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5484 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005486 }
5487
Douglas Gregora16548e2009-08-11 05:31:07 +00005488 if (!getDerived().AlwaysRebuild() &&
5489 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005490 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005491 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005492 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005493 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005494
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005495 // Mark it referenced in the new context regardless.
5496 // FIXME: this is a bit instantiation-specific.
5497 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005498 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005499 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005500
John McCall6b51f282009-11-23 01:53:49 +00005501 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005502 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005503 TransArgs.setLAngleLoc(E->getLAngleLoc());
5504 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005505 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5506 E->getNumTemplateArgs(),
5507 TransArgs))
5508 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005509 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005510
Douglas Gregora16548e2009-08-11 05:31:07 +00005511 // FIXME: Bogus source location for the operator
5512 SourceLocation FakeOperatorLoc
5513 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5514
John McCall38836f02010-01-15 08:34:02 +00005515 // FIXME: to do this check properly, we will need to preserve the
5516 // first-qualifier-in-scope here, just in case we had a dependent
5517 // base (and therefore couldn't do the check) and a
5518 // nested-name-qualifier (and therefore could do the lookup).
5519 NamedDecl *FirstQualifierInScope = 0;
5520
John McCallb268a282010-08-23 23:25:46 +00005521 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005523 Qualifier,
5524 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005525 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005526 Member,
John McCall16df1e52010-03-30 21:47:33 +00005527 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005528 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005529 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005530 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005531}
Mike Stump11289f42009-09-09 15:08:12 +00005532
Douglas Gregora16548e2009-08-11 05:31:07 +00005533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005534ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005535TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005536 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005537 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005539
John McCalldadc5752010-08-24 06:29:42 +00005540 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005543
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 if (!getDerived().AlwaysRebuild() &&
5545 LHS.get() == E->getLHS() &&
5546 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005547 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005550 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005551}
5552
Mike Stump11289f42009-09-09 15:08:12 +00005553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005554ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005555TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005556 CompoundAssignOperator *E) {
5557 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005561ExprResult TreeTransform<Derived>::
5562TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5563 // Just rebuild the common and RHS expressions and see whether we
5564 // get any changes.
5565
5566 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5567 if (commonExpr.isInvalid())
5568 return ExprError();
5569
5570 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5571 if (rhs.isInvalid())
5572 return ExprError();
5573
5574 if (!getDerived().AlwaysRebuild() &&
5575 commonExpr.get() == e->getCommon() &&
5576 rhs.get() == e->getFalseExpr())
5577 return SemaRef.Owned(e);
5578
5579 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5580 e->getQuestionLoc(),
5581 0,
5582 e->getColonLoc(),
5583 rhs.get());
5584}
5585
5586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005588TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005589 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005590 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005592
John McCalldadc5752010-08-24 06:29:42 +00005593 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005594 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005595 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005596
John McCalldadc5752010-08-24 06:29:42 +00005597 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregora16548e2009-08-11 05:31:07 +00005601 if (!getDerived().AlwaysRebuild() &&
5602 Cond.get() == E->getCond() &&
5603 LHS.get() == E->getLHS() &&
5604 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005605 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005606
John McCallb268a282010-08-23 23:25:46 +00005607 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005608 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005609 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005610 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005611 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
5614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005617 // Implicit casts are eliminated during transformation, since they
5618 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005619 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005620}
Mike Stump11289f42009-09-09 15:08:12 +00005621
Douglas Gregora16548e2009-08-11 05:31:07 +00005622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005625 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5626 if (!Type)
5627 return ExprError();
5628
John McCalldadc5752010-08-24 06:29:42 +00005629 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005630 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005632 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005635 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005637 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005638
John McCall97513962010-01-15 18:39:57 +00005639 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005640 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005641 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005642 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005643}
Mike Stump11289f42009-09-09 15:08:12 +00005644
Douglas Gregora16548e2009-08-11 05:31:07 +00005645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005647TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005648 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5649 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5650 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCalldadc5752010-08-24 06:29:42 +00005653 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005658 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005659 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005660 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005661
John McCall5d7aa7f2010-01-19 22:33:45 +00005662 // Note: the expression type doesn't necessarily match the
5663 // type-as-written, but that's okay, because it should always be
5664 // derivable from the initializer.
5665
John McCalle15bbff2010-01-18 19:35:47 +00005666 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005668 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005669}
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005672ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005673TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005674 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 if (!getDerived().AlwaysRebuild() &&
5679 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005680 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005683 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005685 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 E->getAccessorLoc(),
5687 E->getAccessor());
5688}
Mike Stump11289f42009-09-09 15:08:12 +00005689
Douglas Gregora16548e2009-08-11 05:31:07 +00005690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005692TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005693 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005694
John McCall37ad5512010-08-23 06:44:23 +00005695 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005696 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5697 Inits, &InitChanged))
5698 return ExprError();
5699
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005701 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005704 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005709TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005710 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregorebe10102009-08-20 07:17:43 +00005712 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005713 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005715 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregorebe10102009-08-20 07:17:43 +00005717 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005718 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 bool ExprChanged = false;
5720 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5721 DEnd = E->designators_end();
5722 D != DEnd; ++D) {
5723 if (D->isFieldDesignator()) {
5724 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5725 D->getDotLoc(),
5726 D->getFieldLoc()));
5727 continue;
5728 }
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005731 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005732 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005734
5735 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5739 ArrayExprs.push_back(Index.release());
5740 continue;
5741 }
Mike Stump11289f42009-09-09 15:08:12 +00005742
Douglas Gregora16548e2009-08-11 05:31:07 +00005743 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005744 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5746 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005748
John McCalldadc5752010-08-24 06:29:42 +00005749 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005752
5753 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005754 End.get(),
5755 D->getLBracketLoc(),
5756 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregora16548e2009-08-11 05:31:07 +00005758 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5759 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005760
Douglas Gregora16548e2009-08-11 05:31:07 +00005761 ArrayExprs.push_back(Start.release());
5762 ArrayExprs.push_back(End.release());
5763 }
Mike Stump11289f42009-09-09 15:08:12 +00005764
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 if (!getDerived().AlwaysRebuild() &&
5766 Init.get() == E->getInit() &&
5767 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005768 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005769
Douglas Gregora16548e2009-08-11 05:31:07 +00005770 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5771 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005772 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005773}
Mike Stump11289f42009-09-09 15:08:12 +00005774
Douglas Gregora16548e2009-08-11 05:31:07 +00005775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005776ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005777TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005778 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005779 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005780
Douglas Gregor3da3c062009-10-28 00:29:27 +00005781 // FIXME: Will we ever have proper type location here? Will we actually
5782 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 QualType T = getDerived().TransformType(E->getType());
5784 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005786
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 if (!getDerived().AlwaysRebuild() &&
5788 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005789 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 return getDerived().RebuildImplicitValueInitExpr(T);
5792}
Mike Stump11289f42009-09-09 15:08:12 +00005793
Douglas Gregora16548e2009-08-11 05:31:07 +00005794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005795ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005796TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005797 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5798 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005800
John McCalldadc5752010-08-24 06:29:42 +00005801 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005806 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005808 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005809
John McCallb268a282010-08-23 23:25:46 +00005810 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005811 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005812}
5813
5814template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005815ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005816TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005818 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005819 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5820 &ArgumentChanged))
5821 return ExprError();
5822
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5824 move_arg(Inits),
5825 E->getRParenLoc());
5826}
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828/// \brief Transform an address-of-label expression.
5829///
5830/// By default, the transformation of an address-of-label expression always
5831/// rebuilds the expression, so that the label identifier can be resolved to
5832/// the corresponding label statement by semantic analysis.
5833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005835TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005836 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
5837 E->getLabel());
5838 if (!LD)
5839 return ExprError();
5840
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005842 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00005843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
5845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005847TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005848 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005849 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5850 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005852
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 if (!getDerived().AlwaysRebuild() &&
5854 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005855 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005856
5857 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005858 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005859 E->getRParenLoc());
5860}
Mike Stump11289f42009-09-09 15:08:12 +00005861
Douglas Gregora16548e2009-08-11 05:31:07 +00005862template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005864TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005865 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005867 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005868
John McCalldadc5752010-08-24 06:29:42 +00005869 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005870 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005872
John McCalldadc5752010-08-24 06:29:42 +00005873 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005875 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregora16548e2009-08-11 05:31:07 +00005877 if (!getDerived().AlwaysRebuild() &&
5878 Cond.get() == E->getCond() &&
5879 LHS.get() == E->getLHS() &&
5880 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005881 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005882
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005884 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005885 E->getRParenLoc());
5886}
Mike Stump11289f42009-09-09 15:08:12 +00005887
Douglas Gregora16548e2009-08-11 05:31:07 +00005888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005890TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005891 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005892}
5893
5894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005896TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005897 switch (E->getOperator()) {
5898 case OO_New:
5899 case OO_Delete:
5900 case OO_Array_New:
5901 case OO_Array_Delete:
5902 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005904
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005905 case OO_Call: {
5906 // This is a call to an object's operator().
5907 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5908
5909 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005910 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005911 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005912 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005913
5914 // FIXME: Poor location information
5915 SourceLocation FakeLParenLoc
5916 = SemaRef.PP.getLocForEndOfToken(
5917 static_cast<Expr *>(Object.get())->getLocEnd());
5918
5919 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005920 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005921 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5922 Args))
5923 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005924
John McCallb268a282010-08-23 23:25:46 +00005925 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005926 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005927 E->getLocEnd());
5928 }
5929
5930#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5931 case OO_##Name:
5932#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5933#include "clang/Basic/OperatorKinds.def"
5934 case OO_Subscript:
5935 // Handled below.
5936 break;
5937
5938 case OO_Conditional:
5939 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005940 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005941
5942 case OO_None:
5943 case NUM_OVERLOADED_OPERATORS:
5944 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005945 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005946 }
5947
John McCalldadc5752010-08-24 06:29:42 +00005948 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005949 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005951
John McCalldadc5752010-08-24 06:29:42 +00005952 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005953 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005954 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005955
John McCalldadc5752010-08-24 06:29:42 +00005956 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005957 if (E->getNumArgs() == 2) {
5958 Second = getDerived().TransformExpr(E->getArg(1));
5959 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005960 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005961 }
Mike Stump11289f42009-09-09 15:08:12 +00005962
Douglas Gregora16548e2009-08-11 05:31:07 +00005963 if (!getDerived().AlwaysRebuild() &&
5964 Callee.get() == E->getCallee() &&
5965 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005966 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005967 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005968
Douglas Gregora16548e2009-08-11 05:31:07 +00005969 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5970 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005971 Callee.get(),
5972 First.get(),
5973 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005974}
Mike Stump11289f42009-09-09 15:08:12 +00005975
Douglas Gregora16548e2009-08-11 05:31:07 +00005976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005977ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005978TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5979 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005980}
Mike Stump11289f42009-09-09 15:08:12 +00005981
Douglas Gregora16548e2009-08-11 05:31:07 +00005982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005983ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00005984TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
5985 // Transform the callee.
5986 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
5987 if (Callee.isInvalid())
5988 return ExprError();
5989
5990 // Transform exec config.
5991 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
5992 if (EC.isInvalid())
5993 return ExprError();
5994
5995 // Transform arguments.
5996 bool ArgChanged = false;
5997 ASTOwningVector<Expr*> Args(SemaRef);
5998 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5999 &ArgChanged))
6000 return ExprError();
6001
6002 if (!getDerived().AlwaysRebuild() &&
6003 Callee.get() == E->getCallee() &&
6004 !ArgChanged)
6005 return SemaRef.Owned(E);
6006
6007 // FIXME: Wrong source location information for the '('.
6008 SourceLocation FakeLParenLoc
6009 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6010 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6011 move_arg(Args),
6012 E->getRParenLoc(), EC.get());
6013}
6014
6015template<typename Derived>
6016ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006017TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006018 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6019 if (!Type)
6020 return ExprError();
6021
John McCalldadc5752010-08-24 06:29:42 +00006022 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006023 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006028 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006029 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006030 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006031
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006033 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6035 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6036 SourceLocation FakeRParenLoc
6037 = SemaRef.PP.getLocForEndOfToken(
6038 E->getSubExpr()->getSourceRange().getEnd());
6039 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006040 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006041 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006042 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006043 FakeRAngleLoc,
6044 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006045 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006046 FakeRParenLoc);
6047}
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregora16548e2009-08-11 05:31:07 +00006049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006051TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6052 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006053}
Mike Stump11289f42009-09-09 15:08:12 +00006054
6055template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006056ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006057TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6058 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006059}
6060
Douglas Gregora16548e2009-08-11 05:31:07 +00006061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006062ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006063TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006064 CXXReinterpretCastExpr *E) {
6065 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006066}
Mike Stump11289f42009-09-09 15:08:12 +00006067
Douglas Gregora16548e2009-08-11 05:31:07 +00006068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006069ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006070TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6071 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006072}
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006075ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006076TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006077 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006078 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6079 if (!Type)
6080 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006081
John McCalldadc5752010-08-24 06:29:42 +00006082 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006083 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006084 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006085 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006086
Douglas Gregora16548e2009-08-11 05:31:07 +00006087 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006088 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006090 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006092 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006093 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006094 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006095 E->getRParenLoc());
6096}
Mike Stump11289f42009-09-09 15:08:12 +00006097
Douglas Gregora16548e2009-08-11 05:31:07 +00006098template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006099ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006100TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006101 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006102 TypeSourceInfo *TInfo
6103 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6104 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006106
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006108 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006109 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006110
Douglas Gregor9da64192010-04-26 22:37:10 +00006111 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6112 E->getLocStart(),
6113 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006114 E->getLocEnd());
6115 }
Mike Stump11289f42009-09-09 15:08:12 +00006116
Douglas Gregora16548e2009-08-11 05:31:07 +00006117 // We don't know whether the expression is potentially evaluated until
6118 // after we perform semantic analysis, so the expression is potentially
6119 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006120 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006121 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006122
John McCalldadc5752010-08-24 06:29:42 +00006123 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006126
Douglas Gregora16548e2009-08-11 05:31:07 +00006127 if (!getDerived().AlwaysRebuild() &&
6128 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006129 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006130
Douglas Gregor9da64192010-04-26 22:37:10 +00006131 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6132 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006133 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006134 E->getLocEnd());
6135}
6136
6137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006138ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006139TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6140 if (E->isTypeOperand()) {
6141 TypeSourceInfo *TInfo
6142 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6143 if (!TInfo)
6144 return ExprError();
6145
6146 if (!getDerived().AlwaysRebuild() &&
6147 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006148 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006149
6150 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6151 E->getLocStart(),
6152 TInfo,
6153 E->getLocEnd());
6154 }
6155
6156 // We don't know whether the expression is potentially evaluated until
6157 // after we perform semantic analysis, so the expression is potentially
6158 // potentially evaluated.
6159 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6160
6161 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6162 if (SubExpr.isInvalid())
6163 return ExprError();
6164
6165 if (!getDerived().AlwaysRebuild() &&
6166 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006167 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006168
6169 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6170 E->getLocStart(),
6171 SubExpr.get(),
6172 E->getLocEnd());
6173}
6174
6175template<typename Derived>
6176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006177TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006178 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006179}
Mike Stump11289f42009-09-09 15:08:12 +00006180
Douglas Gregora16548e2009-08-11 05:31:07 +00006181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006182ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006183TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006184 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006185 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006186}
Mike Stump11289f42009-09-09 15:08:12 +00006187
Douglas Gregora16548e2009-08-11 05:31:07 +00006188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006189ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006191 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6192 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6193 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006195 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006196 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006197
Douglas Gregorb15af892010-01-07 23:12:05 +00006198 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006199}
Mike Stump11289f42009-09-09 15:08:12 +00006200
Douglas Gregora16548e2009-08-11 05:31:07 +00006201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006203TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006204 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006205 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006206 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006207
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 if (!getDerived().AlwaysRebuild() &&
6209 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006211
John McCallb268a282010-08-23 23:25:46 +00006212 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006213}
Mike Stump11289f42009-09-09 15:08:12 +00006214
Douglas Gregora16548e2009-08-11 05:31:07 +00006215template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006216ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006217TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006218 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006219 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6220 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006221 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006223
Chandler Carruth794da4c2010-02-08 06:42:49 +00006224 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006225 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006226 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006227
Douglas Gregor033f6752009-12-23 23:03:06 +00006228 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006229}
Mike Stump11289f42009-09-09 15:08:12 +00006230
Douglas Gregora16548e2009-08-11 05:31:07 +00006231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006232ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006233TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6234 CXXScalarValueInitExpr *E) {
6235 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6236 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006237 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006238
Douglas Gregora16548e2009-08-11 05:31:07 +00006239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006240 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006241 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006242
Douglas Gregor2b88c112010-09-08 00:15:04 +00006243 return getDerived().RebuildCXXScalarValueInitExpr(T,
6244 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006245 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006246}
Mike Stump11289f42009-09-09 15:08:12 +00006247
Douglas Gregora16548e2009-08-11 05:31:07 +00006248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006250TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006251 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006252 TypeSourceInfo *AllocTypeInfo
6253 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6254 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006258 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006259 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006261
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 // Transform the placement arguments (if any).
6263 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006264 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006265 if (getDerived().TransformExprs(E->getPlacementArgs(),
6266 E->getNumPlacementArgs(), true,
6267 PlacementArgs, &ArgumentChanged))
6268 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006269
Douglas Gregorebe10102009-08-20 07:17:43 +00006270 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006271 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006272 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6273 ConstructorArgs, &ArgumentChanged))
6274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregord2d9da02010-02-26 00:38:10 +00006276 // Transform constructor, new operator, and delete operator.
6277 CXXConstructorDecl *Constructor = 0;
6278 if (E->getConstructor()) {
6279 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006280 getDerived().TransformDecl(E->getLocStart(),
6281 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006282 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006283 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006284 }
6285
6286 FunctionDecl *OperatorNew = 0;
6287 if (E->getOperatorNew()) {
6288 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006289 getDerived().TransformDecl(E->getLocStart(),
6290 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006291 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006292 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006293 }
6294
6295 FunctionDecl *OperatorDelete = 0;
6296 if (E->getOperatorDelete()) {
6297 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006298 getDerived().TransformDecl(E->getLocStart(),
6299 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006300 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006301 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006302 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006303
Douglas Gregora16548e2009-08-11 05:31:07 +00006304 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006305 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006307 Constructor == E->getConstructor() &&
6308 OperatorNew == E->getOperatorNew() &&
6309 OperatorDelete == E->getOperatorDelete() &&
6310 !ArgumentChanged) {
6311 // Mark any declarations we need as referenced.
6312 // FIXME: instantiation-specific.
6313 if (Constructor)
6314 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6315 if (OperatorNew)
6316 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6317 if (OperatorDelete)
6318 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006319 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006320 }
Mike Stump11289f42009-09-09 15:08:12 +00006321
Douglas Gregor0744ef62010-09-07 21:49:58 +00006322 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006323 if (!ArraySize.get()) {
6324 // If no array size was specified, but the new expression was
6325 // instantiated with an array type (e.g., "new T" where T is
6326 // instantiated with "int[4]"), extract the outer bound from the
6327 // array type as our array size. We do this with constant and
6328 // dependently-sized array types.
6329 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6330 if (!ArrayT) {
6331 // Do nothing
6332 } else if (const ConstantArrayType *ConsArrayT
6333 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006334 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006335 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6336 ConsArrayT->getSize(),
6337 SemaRef.Context.getSizeType(),
6338 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006339 AllocType = ConsArrayT->getElementType();
6340 } else if (const DependentSizedArrayType *DepArrayT
6341 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6342 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006343 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006344 AllocType = DepArrayT->getElementType();
6345 }
6346 }
6347 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006348
Douglas Gregora16548e2009-08-11 05:31:07 +00006349 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6350 E->isGlobalNew(),
6351 /*FIXME:*/E->getLocStart(),
6352 move_arg(PlacementArgs),
6353 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006354 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006355 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006356 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006357 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 /*FIXME:*/E->getLocStart(),
6359 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006360 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006361}
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregora16548e2009-08-11 05:31:07 +00006363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006365TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006366 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006367 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregord2d9da02010-02-26 00:38:10 +00006370 // Transform the delete operator, if known.
6371 FunctionDecl *OperatorDelete = 0;
6372 if (E->getOperatorDelete()) {
6373 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006374 getDerived().TransformDecl(E->getLocStart(),
6375 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006376 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006377 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006378 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006379
Douglas Gregora16548e2009-08-11 05:31:07 +00006380 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006381 Operand.get() == E->getArgument() &&
6382 OperatorDelete == E->getOperatorDelete()) {
6383 // Mark any declarations we need as referenced.
6384 // FIXME: instantiation-specific.
6385 if (OperatorDelete)
6386 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006387
6388 if (!E->getArgument()->isTypeDependent()) {
6389 QualType Destroyed = SemaRef.Context.getBaseElementType(
6390 E->getDestroyedType());
6391 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6392 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6393 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6394 SemaRef.LookupDestructor(Record));
6395 }
6396 }
6397
John McCallc3007a22010-10-26 07:05:15 +00006398 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006399 }
Mike Stump11289f42009-09-09 15:08:12 +00006400
Douglas Gregora16548e2009-08-11 05:31:07 +00006401 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6402 E->isGlobalDelete(),
6403 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006404 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006405}
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregora16548e2009-08-11 05:31:07 +00006407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006408ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006409TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006410 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006411 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006412 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006413 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006414
John McCallba7bf592010-08-24 05:47:05 +00006415 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006416 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006417 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006418 E->getOperatorLoc(),
6419 E->isArrow()? tok::arrow : tok::period,
6420 ObjectTypePtr,
6421 MayBePseudoDestructor);
6422 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006424
John McCallba7bf592010-08-24 05:47:05 +00006425 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006426 NestedNameSpecifier *Qualifier = E->getQualifier();
6427 if (Qualifier) {
6428 Qualifier
6429 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6430 E->getQualifierRange(),
6431 ObjectType);
6432 if (!Qualifier)
6433 return ExprError();
6434 }
Mike Stump11289f42009-09-09 15:08:12 +00006435
Douglas Gregor678f90d2010-02-25 01:56:36 +00006436 PseudoDestructorTypeStorage Destroyed;
6437 if (E->getDestroyedTypeInfo()) {
6438 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006439 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6440 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006441 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006442 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006443 Destroyed = DestroyedTypeInfo;
6444 } else if (ObjectType->isDependentType()) {
6445 // We aren't likely to be able to resolve the identifier down to a type
6446 // now anyway, so just retain the identifier.
6447 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6448 E->getDestroyedTypeLoc());
6449 } else {
6450 // Look for a destructor known with the given name.
6451 CXXScopeSpec SS;
6452 if (Qualifier) {
6453 SS.setScopeRep(Qualifier);
6454 SS.setRange(E->getQualifierRange());
6455 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006456
John McCallba7bf592010-08-24 05:47:05 +00006457 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006458 *E->getDestroyedTypeIdentifier(),
6459 E->getDestroyedTypeLoc(),
6460 /*Scope=*/0,
6461 SS, ObjectTypePtr,
6462 false);
6463 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006464 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006465
Douglas Gregor678f90d2010-02-25 01:56:36 +00006466 Destroyed
6467 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6468 E->getDestroyedTypeLoc());
6469 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006470
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006471 TypeSourceInfo *ScopeTypeInfo = 0;
6472 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006473 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006474 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006476 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006477
John McCallb268a282010-08-23 23:25:46 +00006478 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006479 E->getOperatorLoc(),
6480 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006481 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006482 E->getQualifierRange(),
6483 ScopeTypeInfo,
6484 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006485 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006486 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006487}
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregorad8a3362009-09-04 17:36:40 +00006489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006490ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006491TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006492 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006493 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6494
6495 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6496 Sema::LookupOrdinaryName);
6497
6498 // Transform all the decls.
6499 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6500 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006501 NamedDecl *InstD = static_cast<NamedDecl*>(
6502 getDerived().TransformDecl(Old->getNameLoc(),
6503 *I));
John McCall84d87672009-12-10 09:41:52 +00006504 if (!InstD) {
6505 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6506 // This can happen because of dependent hiding.
6507 if (isa<UsingShadowDecl>(*I))
6508 continue;
6509 else
John McCallfaf5fb42010-08-26 23:41:50 +00006510 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006511 }
John McCalle66edc12009-11-24 19:00:30 +00006512
6513 // Expand using declarations.
6514 if (isa<UsingDecl>(InstD)) {
6515 UsingDecl *UD = cast<UsingDecl>(InstD);
6516 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6517 E = UD->shadow_end(); I != E; ++I)
6518 R.addDecl(*I);
6519 continue;
6520 }
6521
6522 R.addDecl(InstD);
6523 }
6524
6525 // Resolve a kind, but don't do any further analysis. If it's
6526 // ambiguous, the callee needs to deal with it.
6527 R.resolveKind();
6528
6529 // Rebuild the nested-name qualifier, if present.
6530 CXXScopeSpec SS;
6531 NestedNameSpecifier *Qualifier = 0;
6532 if (Old->getQualifier()) {
6533 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006534 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006535 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006536 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006537
John McCalle66edc12009-11-24 19:00:30 +00006538 SS.setScopeRep(Qualifier);
6539 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006540 }
6541
Douglas Gregor9262f472010-04-27 18:19:34 +00006542 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006543 CXXRecordDecl *NamingClass
6544 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6545 Old->getNameLoc(),
6546 Old->getNamingClass()));
6547 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006548 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006549
Douglas Gregorda7be082010-04-27 16:10:10 +00006550 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006551 }
6552
6553 // If we have no template arguments, it's a normal declaration name.
6554 if (!Old->hasExplicitTemplateArgs())
6555 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6556
6557 // If we have template arguments, rebuild them, then rebuild the
6558 // templateid expression.
6559 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006560 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6561 Old->getNumTemplateArgs(),
6562 TransArgs))
6563 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006564
6565 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6566 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006567}
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregora16548e2009-08-11 05:31:07 +00006569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006570ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006571TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006572 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6573 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006575
Douglas Gregora16548e2009-08-11 05:31:07 +00006576 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006577 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006578 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006579
Mike Stump11289f42009-09-09 15:08:12 +00006580 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006581 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006582 T,
6583 E->getLocEnd());
6584}
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregora16548e2009-08-11 05:31:07 +00006586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006587ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006588TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6589 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6590 if (!LhsT)
6591 return ExprError();
6592
6593 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6594 if (!RhsT)
6595 return ExprError();
6596
6597 if (!getDerived().AlwaysRebuild() &&
6598 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6599 return SemaRef.Owned(E);
6600
6601 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6602 E->getLocStart(),
6603 LhsT, RhsT,
6604 E->getLocEnd());
6605}
6606
6607template<typename Derived>
6608ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006609TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006610 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006612 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006613 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006614 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006615 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006616
John McCall31f82722010-11-12 08:19:04 +00006617 // TODO: If this is a conversion-function-id, verify that the
6618 // destination type name (if present) resolves the same way after
6619 // instantiation as it did in the local scope.
6620
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006621 DeclarationNameInfo NameInfo
6622 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6623 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006625
John McCalle66edc12009-11-24 19:00:30 +00006626 if (!E->hasExplicitTemplateArgs()) {
6627 if (!getDerived().AlwaysRebuild() &&
6628 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006629 // Note: it is sufficient to compare the Name component of NameInfo:
6630 // if name has not changed, DNLoc has not changed either.
6631 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006632 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006633
John McCalle66edc12009-11-24 19:00:30 +00006634 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6635 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006636 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006637 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006638 }
John McCall6b51f282009-11-23 01:53:49 +00006639
6640 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006641 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6642 E->getNumTemplateArgs(),
6643 TransArgs))
6644 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006645
John McCalle66edc12009-11-24 19:00:30 +00006646 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6647 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006648 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006649 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006650}
6651
6652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006655 // CXXConstructExprs are always implicit, so when we have a
6656 // 1-argument construction we just transform that argument.
6657 if (E->getNumArgs() == 1 ||
6658 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6659 return getDerived().TransformExpr(E->getArg(0));
6660
Douglas Gregora16548e2009-08-11 05:31:07 +00006661 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6662
6663 QualType T = getDerived().TransformType(E->getType());
6664 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006665 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006666
6667 CXXConstructorDecl *Constructor
6668 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006669 getDerived().TransformDecl(E->getLocStart(),
6670 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006671 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregora16548e2009-08-11 05:31:07 +00006674 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006675 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006676 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6677 &ArgumentChanged))
6678 return ExprError();
6679
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 if (!getDerived().AlwaysRebuild() &&
6681 T == E->getType() &&
6682 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006683 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006684 // Mark the constructor as referenced.
6685 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006686 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006688 }
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregordb121ba2009-12-14 16:27:04 +00006690 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6691 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006692 move_arg(Args),
6693 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006694 E->getConstructionKind(),
6695 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006696}
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregora16548e2009-08-11 05:31:07 +00006698/// \brief Transform a C++ temporary-binding expression.
6699///
Douglas Gregor363b1512009-12-24 18:51:59 +00006700/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6701/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006704TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006705 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006706}
Mike Stump11289f42009-09-09 15:08:12 +00006707
John McCall5d413782010-12-06 08:20:24 +00006708/// \brief Transform a C++ expression that contains cleanups that should
6709/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006710///
John McCall5d413782010-12-06 08:20:24 +00006711/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006712/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006714ExprResult
John McCall5d413782010-12-06 08:20:24 +00006715TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006716 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006717}
Mike Stump11289f42009-09-09 15:08:12 +00006718
Douglas Gregora16548e2009-08-11 05:31:07 +00006719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006720ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006721TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006722 CXXTemporaryObjectExpr *E) {
6723 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6724 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727 CXXConstructorDecl *Constructor
6728 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006729 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006730 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006731 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006733
Douglas Gregora16548e2009-08-11 05:31:07 +00006734 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006735 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006736 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006737 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6738 &ArgumentChanged))
6739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregora16548e2009-08-11 05:31:07 +00006741 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006742 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006743 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006744 !ArgumentChanged) {
6745 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006746 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006747 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006748 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006749
6750 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6751 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006752 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006753 E->getLocEnd());
6754}
Mike Stump11289f42009-09-09 15:08:12 +00006755
Douglas Gregora16548e2009-08-11 05:31:07 +00006756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006757ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006758TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006759 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006760 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6761 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006762 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006763
Douglas Gregora16548e2009-08-11 05:31:07 +00006764 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006765 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006766 Args.reserve(E->arg_size());
6767 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6768 &ArgumentChanged))
6769 return ExprError();
6770
Douglas Gregora16548e2009-08-11 05:31:07 +00006771 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006772 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006773 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006774 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006775
Douglas Gregora16548e2009-08-11 05:31:07 +00006776 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006777 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006778 E->getLParenLoc(),
6779 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006780 E->getRParenLoc());
6781}
Mike Stump11289f42009-09-09 15:08:12 +00006782
Douglas Gregora16548e2009-08-11 05:31:07 +00006783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006784ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006785TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006786 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006787 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006788 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006789 Expr *OldBase;
6790 QualType BaseType;
6791 QualType ObjectType;
6792 if (!E->isImplicitAccess()) {
6793 OldBase = E->getBase();
6794 Base = getDerived().TransformExpr(OldBase);
6795 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006797
John McCall2d74de92009-12-01 22:10:20 +00006798 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006799 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006800 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006801 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006802 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006803 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006804 ObjectTy,
6805 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006806 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006807 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006808
John McCallba7bf592010-08-24 05:47:05 +00006809 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006810 BaseType = ((Expr*) Base.get())->getType();
6811 } else {
6812 OldBase = 0;
6813 BaseType = getDerived().TransformType(E->getBaseType());
6814 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6815 }
Mike Stump11289f42009-09-09 15:08:12 +00006816
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006817 // Transform the first part of the nested-name-specifier that qualifies
6818 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006819 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006820 = getDerived().TransformFirstQualifierInScope(
6821 E->getFirstQualifierFoundInScope(),
6822 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006823
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006824 NestedNameSpecifier *Qualifier = 0;
6825 if (E->getQualifier()) {
6826 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6827 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006828 ObjectType,
6829 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006830 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006831 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006832 }
Mike Stump11289f42009-09-09 15:08:12 +00006833
John McCall31f82722010-11-12 08:19:04 +00006834 // TODO: If this is a conversion-function-id, verify that the
6835 // destination type name (if present) resolves the same way after
6836 // instantiation as it did in the local scope.
6837
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006838 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006839 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006840 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006842
John McCall2d74de92009-12-01 22:10:20 +00006843 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006844 // This is a reference to a member without an explicitly-specified
6845 // template argument list. Optimize for this common case.
6846 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006847 Base.get() == OldBase &&
6848 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006849 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006850 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006851 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006852 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006853
John McCallb268a282010-08-23 23:25:46 +00006854 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006855 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006856 E->isArrow(),
6857 E->getOperatorLoc(),
6858 Qualifier,
6859 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006860 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006861 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006862 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006863 }
6864
John McCall6b51f282009-11-23 01:53:49 +00006865 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006866 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6867 E->getNumTemplateArgs(),
6868 TransArgs))
6869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006870
John McCallb268a282010-08-23 23:25:46 +00006871 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006872 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006873 E->isArrow(),
6874 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006875 Qualifier,
6876 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006877 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006878 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006879 &TransArgs);
6880}
6881
6882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006883ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006884TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006885 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006886 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006887 QualType BaseType;
6888 if (!Old->isImplicitAccess()) {
6889 Base = getDerived().TransformExpr(Old->getBase());
6890 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006891 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006892 BaseType = ((Expr*) Base.get())->getType();
6893 } else {
6894 BaseType = getDerived().TransformType(Old->getBaseType());
6895 }
John McCall10eae182009-11-30 22:42:35 +00006896
6897 NestedNameSpecifier *Qualifier = 0;
6898 if (Old->getQualifier()) {
6899 Qualifier
6900 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006901 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006902 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006903 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006904 }
6905
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006906 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006907 Sema::LookupOrdinaryName);
6908
6909 // Transform all the decls.
6910 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6911 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006912 NamedDecl *InstD = static_cast<NamedDecl*>(
6913 getDerived().TransformDecl(Old->getMemberLoc(),
6914 *I));
John McCall84d87672009-12-10 09:41:52 +00006915 if (!InstD) {
6916 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6917 // This can happen because of dependent hiding.
6918 if (isa<UsingShadowDecl>(*I))
6919 continue;
6920 else
John McCallfaf5fb42010-08-26 23:41:50 +00006921 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006922 }
John McCall10eae182009-11-30 22:42:35 +00006923
6924 // Expand using declarations.
6925 if (isa<UsingDecl>(InstD)) {
6926 UsingDecl *UD = cast<UsingDecl>(InstD);
6927 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6928 E = UD->shadow_end(); I != E; ++I)
6929 R.addDecl(*I);
6930 continue;
6931 }
6932
6933 R.addDecl(InstD);
6934 }
6935
6936 R.resolveKind();
6937
Douglas Gregor9262f472010-04-27 18:19:34 +00006938 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006939 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006940 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006941 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006942 Old->getMemberLoc(),
6943 Old->getNamingClass()));
6944 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006945 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006946
Douglas Gregorda7be082010-04-27 16:10:10 +00006947 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006948 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006949
John McCall10eae182009-11-30 22:42:35 +00006950 TemplateArgumentListInfo TransArgs;
6951 if (Old->hasExplicitTemplateArgs()) {
6952 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6953 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006954 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6955 Old->getNumTemplateArgs(),
6956 TransArgs))
6957 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006958 }
John McCall38836f02010-01-15 08:34:02 +00006959
6960 // FIXME: to do this check properly, we will need to preserve the
6961 // first-qualifier-in-scope here, just in case we had a dependent
6962 // base (and therefore couldn't do the check) and a
6963 // nested-name-qualifier (and therefore could do the lookup).
6964 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006965
John McCallb268a282010-08-23 23:25:46 +00006966 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006967 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006968 Old->getOperatorLoc(),
6969 Old->isArrow(),
6970 Qualifier,
6971 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006972 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006973 R,
6974 (Old->hasExplicitTemplateArgs()
6975 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006976}
6977
6978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006979ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006980TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6981 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6982 if (SubExpr.isInvalid())
6983 return ExprError();
6984
6985 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006986 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006987
6988 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6989}
6990
6991template<typename Derived>
6992ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006993TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006994 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6995 if (Pattern.isInvalid())
6996 return ExprError();
6997
6998 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6999 return SemaRef.Owned(E);
7000
Douglas Gregorb8840002011-01-14 21:20:45 +00007001 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7002 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007003}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007004
7005template<typename Derived>
7006ExprResult
7007TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7008 // If E is not value-dependent, then nothing will change when we transform it.
7009 // Note: This is an instantiation-centric view.
7010 if (!E->isValueDependent())
7011 return SemaRef.Owned(E);
7012
7013 // Note: None of the implementations of TryExpandParameterPacks can ever
7014 // produce a diagnostic when given only a single unexpanded parameter pack,
7015 // so
7016 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7017 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007018 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007019 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007020 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7021 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007022 ShouldExpand, RetainExpansion,
7023 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007024 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007025
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007026 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007027 return SemaRef.Owned(E);
7028
7029 // We now know the length of the parameter pack, so build a new expression
7030 // that stores that length.
7031 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7032 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007033 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007034}
7035
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007036template<typename Derived>
7037ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007038TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7039 SubstNonTypeTemplateParmPackExpr *E) {
7040 // Default behavior is to do nothing with this transformation.
7041 return SemaRef.Owned(E);
7042}
7043
7044template<typename Derived>
7045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007046TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007047 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007048}
7049
Mike Stump11289f42009-09-09 15:08:12 +00007050template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007051ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007052TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007053 TypeSourceInfo *EncodedTypeInfo
7054 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7055 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregora16548e2009-08-11 05:31:07 +00007058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007059 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007060 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007061
7062 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007063 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007064 E->getRParenLoc());
7065}
Mike Stump11289f42009-09-09 15:08:12 +00007066
Douglas Gregora16548e2009-08-11 05:31:07 +00007067template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007068ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007069TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007070 // Transform arguments.
7071 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007072 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007073 Args.reserve(E->getNumArgs());
7074 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7075 &ArgChanged))
7076 return ExprError();
7077
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007078 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7079 // Class message: transform the receiver type.
7080 TypeSourceInfo *ReceiverTypeInfo
7081 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7082 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007084
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007085 // If nothing changed, just retain the existing message send.
7086 if (!getDerived().AlwaysRebuild() &&
7087 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007088 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007089
7090 // Build a new class message send.
7091 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7092 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007093 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007094 E->getMethodDecl(),
7095 E->getLeftLoc(),
7096 move_arg(Args),
7097 E->getRightLoc());
7098 }
7099
7100 // Instance message: transform the receiver
7101 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7102 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007103 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007104 = getDerived().TransformExpr(E->getInstanceReceiver());
7105 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007106 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007107
7108 // If nothing changed, just retain the existing message send.
7109 if (!getDerived().AlwaysRebuild() &&
7110 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007111 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007112
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007113 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007114 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007115 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007116 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007117 E->getMethodDecl(),
7118 E->getLeftLoc(),
7119 move_arg(Args),
7120 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007121}
7122
Mike Stump11289f42009-09-09 15:08:12 +00007123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007125TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007126 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007127}
7128
Mike Stump11289f42009-09-09 15:08:12 +00007129template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007130ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007131TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007132 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007133}
7134
Mike Stump11289f42009-09-09 15:08:12 +00007135template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007136ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007137TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007138 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007139 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007140 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007141 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007142
7143 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007144
Douglas Gregord51d90d2010-04-26 20:11:03 +00007145 // If nothing changed, just retain the existing expression.
7146 if (!getDerived().AlwaysRebuild() &&
7147 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007148 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007149
John McCallb268a282010-08-23 23:25:46 +00007150 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007151 E->getLocation(),
7152 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007153}
7154
Mike Stump11289f42009-09-09 15:08:12 +00007155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007157TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007158 // 'super' and types never change. Property never changes. Just
7159 // retain the existing expression.
7160 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007161 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007162
Douglas Gregor9faee212010-04-26 20:47:02 +00007163 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007164 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007165 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007166 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007167
Douglas Gregor9faee212010-04-26 20:47:02 +00007168 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007169
Douglas Gregor9faee212010-04-26 20:47:02 +00007170 // If nothing changed, just retain the existing expression.
7171 if (!getDerived().AlwaysRebuild() &&
7172 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007173 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007174
John McCallb7bd14f2010-12-02 01:19:52 +00007175 if (E->isExplicitProperty())
7176 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7177 E->getExplicitProperty(),
7178 E->getLocation());
7179
7180 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7181 E->getType(),
7182 E->getImplicitPropertyGetter(),
7183 E->getImplicitPropertySetter(),
7184 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007185}
7186
Mike Stump11289f42009-09-09 15:08:12 +00007187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007189TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007190 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007191 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007192 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007193 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007194
Douglas Gregord51d90d2010-04-26 20:11:03 +00007195 // If nothing changed, just retain the existing expression.
7196 if (!getDerived().AlwaysRebuild() &&
7197 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007198 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007199
John McCallb268a282010-08-23 23:25:46 +00007200 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007201 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007202}
7203
Mike Stump11289f42009-09-09 15:08:12 +00007204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007205ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007206TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007207 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007208 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007209 SubExprs.reserve(E->getNumSubExprs());
7210 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7211 SubExprs, &ArgumentChanged))
7212 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007213
Douglas Gregora16548e2009-08-11 05:31:07 +00007214 if (!getDerived().AlwaysRebuild() &&
7215 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007216 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007217
Douglas Gregora16548e2009-08-11 05:31:07 +00007218 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7219 move_arg(SubExprs),
7220 E->getRParenLoc());
7221}
7222
Mike Stump11289f42009-09-09 15:08:12 +00007223template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007225TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007226 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007227
John McCall490112f2011-02-04 18:33:18 +00007228 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7229 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7230
7231 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7232 llvm::SmallVector<ParmVarDecl*, 4> params;
7233 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007234
7235 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007236 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7237 oldBlock->param_begin(),
7238 oldBlock->param_size(),
7239 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007240 return true;
John McCall490112f2011-02-04 18:33:18 +00007241
7242 const FunctionType *exprFunctionType = E->getFunctionType();
7243 QualType exprResultType = exprFunctionType->getResultType();
7244 if (!exprResultType.isNull()) {
7245 if (!exprResultType->isDependentType())
7246 blockScope->ReturnType = exprResultType;
7247 else if (exprResultType != getSema().Context.DependentTy)
7248 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007249 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007250
7251 // If the return type has not been determined yet, leave it as a dependent
7252 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007253 if (blockScope->ReturnType.isNull())
7254 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007255
7256 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007257 if (blockScope->ReturnType->isObjCObjectType()) {
7258 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007259 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007260 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007261 return ExprError();
7262 }
John McCall3882ace2011-01-05 12:14:39 +00007263
John McCall490112f2011-02-04 18:33:18 +00007264 QualType functionType = getDerived().RebuildFunctionProtoType(
7265 blockScope->ReturnType,
7266 paramTypes.data(),
7267 paramTypes.size(),
7268 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007269 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007270 exprFunctionType->getExtInfo());
7271 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007272
7273 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007274 if (!params.empty())
7275 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007276
7277 // If the return type wasn't explicitly set, it will have been marked as a
7278 // dependent type (DependentTy); clear out the return type setting so
7279 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007280 if (blockScope->ReturnType == getSema().Context.DependentTy)
7281 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007282
John McCall3882ace2011-01-05 12:14:39 +00007283 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007284 StmtResult body = getDerived().TransformStmt(E->getBody());
7285 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007286 return ExprError();
7287
John McCall490112f2011-02-04 18:33:18 +00007288#ifndef NDEBUG
7289 // In builds with assertions, make sure that we captured everything we
7290 // captured before.
7291
7292 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7293
7294 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7295 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007296 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007297
7298 // Ignore parameter packs.
7299 if (isa<ParmVarDecl>(oldCapture) &&
7300 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7301 continue;
7302
7303 VarDecl *newCapture =
7304 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7305 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007306 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007307 }
7308#endif
7309
7310 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7311 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007312}
7313
Mike Stump11289f42009-09-09 15:08:12 +00007314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007317 NestedNameSpecifier *Qualifier = 0;
7318
7319 ValueDecl *ND
7320 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7321 E->getDecl()));
7322 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007323 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007324
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007325 if (!getDerived().AlwaysRebuild() &&
7326 ND == E->getDecl()) {
7327 // Mark it referenced in the new context regardless.
7328 // FIXME: this is a bit instantiation-specific.
7329 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7330
John McCallc3007a22010-10-26 07:05:15 +00007331 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007332 }
7333
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007334 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007335 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007336 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007337}
Mike Stump11289f42009-09-09 15:08:12 +00007338
Douglas Gregora16548e2009-08-11 05:31:07 +00007339//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007340// Type reconstruction
7341//===----------------------------------------------------------------------===//
7342
Mike Stump11289f42009-09-09 15:08:12 +00007343template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007344QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7345 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007346 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007347 getDerived().getBaseEntity());
7348}
7349
Mike Stump11289f42009-09-09 15:08:12 +00007350template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007351QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7352 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007353 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007354 getDerived().getBaseEntity());
7355}
7356
Mike Stump11289f42009-09-09 15:08:12 +00007357template<typename Derived>
7358QualType
John McCall70dd5f62009-10-30 00:06:24 +00007359TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7360 bool WrittenAsLValue,
7361 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007362 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007363 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007364}
7365
7366template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007367QualType
John McCall70dd5f62009-10-30 00:06:24 +00007368TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7369 QualType ClassType,
7370 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007371 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007372 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007373}
7374
7375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007376QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007377TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7378 ArrayType::ArraySizeModifier SizeMod,
7379 const llvm::APInt *Size,
7380 Expr *SizeExpr,
7381 unsigned IndexTypeQuals,
7382 SourceRange BracketsRange) {
7383 if (SizeExpr || !Size)
7384 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7385 IndexTypeQuals, BracketsRange,
7386 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007387
7388 QualType Types[] = {
7389 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7390 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7391 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007392 };
7393 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7394 QualType SizeType;
7395 for (unsigned I = 0; I != NumTypes; ++I)
7396 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7397 SizeType = Types[I];
7398 break;
7399 }
Mike Stump11289f42009-09-09 15:08:12 +00007400
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007401 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7402 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007403 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007404 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007405 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007406}
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregord6ff3322009-08-04 16:50:30 +00007408template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007409QualType
7410TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007411 ArrayType::ArraySizeModifier SizeMod,
7412 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007413 unsigned IndexTypeQuals,
7414 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007415 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007416 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007417}
7418
7419template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007420QualType
Mike Stump11289f42009-09-09 15:08:12 +00007421TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007422 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007423 unsigned IndexTypeQuals,
7424 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007425 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007426 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007427}
Mike Stump11289f42009-09-09 15:08:12 +00007428
Douglas Gregord6ff3322009-08-04 16:50:30 +00007429template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007430QualType
7431TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007432 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007433 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007434 unsigned IndexTypeQuals,
7435 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007436 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007437 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007438 IndexTypeQuals, BracketsRange);
7439}
7440
7441template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007442QualType
7443TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007444 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007445 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007446 unsigned IndexTypeQuals,
7447 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007448 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007449 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007450 IndexTypeQuals, BracketsRange);
7451}
7452
7453template<typename Derived>
7454QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007455 unsigned NumElements,
7456 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007457 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007458 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007459}
Mike Stump11289f42009-09-09 15:08:12 +00007460
Douglas Gregord6ff3322009-08-04 16:50:30 +00007461template<typename Derived>
7462QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7463 unsigned NumElements,
7464 SourceLocation AttributeLoc) {
7465 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7466 NumElements, true);
7467 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007468 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7469 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007470 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007471}
Mike Stump11289f42009-09-09 15:08:12 +00007472
Douglas Gregord6ff3322009-08-04 16:50:30 +00007473template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007474QualType
7475TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007476 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007477 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007478 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007479}
Mike Stump11289f42009-09-09 15:08:12 +00007480
Douglas Gregord6ff3322009-08-04 16:50:30 +00007481template<typename Derived>
7482QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007483 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007484 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007485 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007486 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007487 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007488 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007489 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007490 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007491 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007492 getDerived().getBaseEntity(),
7493 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007494}
Mike Stump11289f42009-09-09 15:08:12 +00007495
Douglas Gregord6ff3322009-08-04 16:50:30 +00007496template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007497QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7498 return SemaRef.Context.getFunctionNoProtoType(T);
7499}
7500
7501template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007502QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7503 assert(D && "no decl found");
7504 if (D->isInvalidDecl()) return QualType();
7505
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007506 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007507 TypeDecl *Ty;
7508 if (isa<UsingDecl>(D)) {
7509 UsingDecl *Using = cast<UsingDecl>(D);
7510 assert(Using->isTypeName() &&
7511 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7512
7513 // A valid resolved using typename decl points to exactly one type decl.
7514 assert(++Using->shadow_begin() == Using->shadow_end());
7515 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007516
John McCallb96ec562009-12-04 22:46:56 +00007517 } else {
7518 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7519 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7520 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7521 }
7522
7523 return SemaRef.Context.getTypeDeclType(Ty);
7524}
7525
7526template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007527QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7528 SourceLocation Loc) {
7529 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007530}
7531
7532template<typename Derived>
7533QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7534 return SemaRef.Context.getTypeOfType(Underlying);
7535}
7536
7537template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007538QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7539 SourceLocation Loc) {
7540 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007541}
7542
7543template<typename Derived>
7544QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007545 TemplateName Template,
7546 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007547 const TemplateArgumentListInfo &TemplateArgs) {
7548 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007549}
Mike Stump11289f42009-09-09 15:08:12 +00007550
Douglas Gregor1135c352009-08-06 05:28:30 +00007551template<typename Derived>
7552NestedNameSpecifier *
7553TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7554 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007555 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007556 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007557 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007558 CXXScopeSpec SS;
7559 // FIXME: The source location information is all wrong.
7560 SS.setRange(Range);
7561 SS.setScopeRep(Prefix);
7562 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007563 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007564 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007565 ObjectType,
7566 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007567 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007568}
7569
7570template<typename Derived>
7571NestedNameSpecifier *
7572TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7573 SourceRange Range,
7574 NamespaceDecl *NS) {
7575 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7576}
7577
7578template<typename Derived>
7579NestedNameSpecifier *
7580TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7581 SourceRange Range,
7582 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007583 QualType T) {
7584 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007585 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007586 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007587 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7588 T.getTypePtr());
7589 }
Mike Stump11289f42009-09-09 15:08:12 +00007590
Douglas Gregor1135c352009-08-06 05:28:30 +00007591 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7592 return 0;
7593}
Mike Stump11289f42009-09-09 15:08:12 +00007594
Douglas Gregor71dc5092009-08-06 06:41:21 +00007595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007596TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007597TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7598 bool TemplateKW,
7599 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007600 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007601 Template);
7602}
7603
7604template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007605TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007606TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007607 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007608 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007609 QualType ObjectType,
7610 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007611 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007612 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007613 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007614 UnqualifiedId Name;
7615 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007616 Sema::TemplateTy Template;
7617 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7618 /*FIXME:*/getDerived().getBaseLocation(),
7619 SS,
7620 Name,
John McCallba7bf592010-08-24 05:47:05 +00007621 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007622 /*EnteringContext=*/false,
7623 Template);
John McCall31f82722010-11-12 08:19:04 +00007624 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007625}
Mike Stump11289f42009-09-09 15:08:12 +00007626
Douglas Gregora16548e2009-08-11 05:31:07 +00007627template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007628TemplateName
7629TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7630 OverloadedOperatorKind Operator,
7631 QualType ObjectType) {
7632 CXXScopeSpec SS;
7633 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7634 SS.setScopeRep(Qualifier);
7635 UnqualifiedId Name;
7636 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7637 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7638 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007639 Sema::TemplateTy Template;
7640 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007641 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007642 SS,
7643 Name,
John McCallba7bf592010-08-24 05:47:05 +00007644 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007645 /*EnteringContext=*/false,
7646 Template);
7647 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007648}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007649
Douglas Gregor71395fa2009-11-04 00:56:37 +00007650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007651ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007652TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7653 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007654 Expr *OrigCallee,
7655 Expr *First,
7656 Expr *Second) {
7657 Expr *Callee = OrigCallee->IgnoreParenCasts();
7658 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007659
Douglas Gregora16548e2009-08-11 05:31:07 +00007660 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007661 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007662 if (!First->getType()->isOverloadableType() &&
7663 !Second->getType()->isOverloadableType())
7664 return getSema().CreateBuiltinArraySubscriptExpr(First,
7665 Callee->getLocStart(),
7666 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007667 } else if (Op == OO_Arrow) {
7668 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007669 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7670 } else if (Second == 0 || isPostIncDec) {
7671 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007672 // The argument is not of overloadable type, so try to create a
7673 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007674 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007675 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007676
John McCallb268a282010-08-23 23:25:46 +00007677 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007678 }
7679 } else {
John McCallb268a282010-08-23 23:25:46 +00007680 if (!First->getType()->isOverloadableType() &&
7681 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007682 // Neither of the arguments is an overloadable type, so try to
7683 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007684 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007685 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007686 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007687 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007688 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007689
Douglas Gregora16548e2009-08-11 05:31:07 +00007690 return move(Result);
7691 }
7692 }
Mike Stump11289f42009-09-09 15:08:12 +00007693
7694 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007695 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007696 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007697
John McCallb268a282010-08-23 23:25:46 +00007698 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007699 assert(ULE->requiresADL());
7700
7701 // FIXME: Do we have to check
7702 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007703 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007704 } else {
John McCallb268a282010-08-23 23:25:46 +00007705 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007706 }
Mike Stump11289f42009-09-09 15:08:12 +00007707
Douglas Gregora16548e2009-08-11 05:31:07 +00007708 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007709 Expr *Args[2] = { First, Second };
7710 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007711
Douglas Gregora16548e2009-08-11 05:31:07 +00007712 // Create the overloaded operator invocation for unary operators.
7713 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007714 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007716 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007717 }
Mike Stump11289f42009-09-09 15:08:12 +00007718
Sebastian Redladba46e2009-10-29 20:17:01 +00007719 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007720 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007721 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007722 First,
7723 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007724
Douglas Gregora16548e2009-08-11 05:31:07 +00007725 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007726 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007727 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007728 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7729 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007730 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007731
Mike Stump11289f42009-09-09 15:08:12 +00007732 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007733}
Mike Stump11289f42009-09-09 15:08:12 +00007734
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007736ExprResult
John McCallb268a282010-08-23 23:25:46 +00007737TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007738 SourceLocation OperatorLoc,
7739 bool isArrow,
7740 NestedNameSpecifier *Qualifier,
7741 SourceRange QualifierRange,
7742 TypeSourceInfo *ScopeType,
7743 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007744 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007745 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007746 CXXScopeSpec SS;
7747 if (Qualifier) {
7748 SS.setRange(QualifierRange);
7749 SS.setScopeRep(Qualifier);
7750 }
7751
John McCallb268a282010-08-23 23:25:46 +00007752 QualType BaseType = Base->getType();
7753 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007754 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007755 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007756 !BaseType->getAs<PointerType>()->getPointeeType()
7757 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007758 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007759 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007760 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007761 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007762 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007763 /*FIXME?*/true);
7764 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007765
Douglas Gregor678f90d2010-02-25 01:56:36 +00007766 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007767 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7768 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7769 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7770 NameInfo.setNamedTypeInfo(DestroyedType);
7771
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007772 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007773
John McCallb268a282010-08-23 23:25:46 +00007774 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007775 OperatorLoc, isArrow,
7776 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007777 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007778 /*TemplateArgs*/ 0);
7779}
7780
Douglas Gregord6ff3322009-08-04 16:50:30 +00007781} // end namespace clang
7782
7783#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H