blob: f5ec3a2170184f891d332b280c8280150737e7bf [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-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 Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCall781472f2010-08-25 08:40:02 +000038using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000039
Douglas Gregor577f75a2009-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 Stump1eb44332009-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 Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000071/// 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 Gregor43959a92009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-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 Gregor577f75a2009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregord3731192011-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 Gregor577f75a2009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000112
Mike Stump1eb44332009-09-09 15:08:12 +0000113public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000123 }
124
John McCall60d7b3a2010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000127
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000131
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-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 Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000160
Douglas Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 }
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump1eb44332009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-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 Gregor6eef5192009-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 }
Sean Huntc3021132010-05-05 15:23:54 +0000203
Douglas Gregor8491ffe2010-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 Gregorb99268b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-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 Gregord3731192011-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 Gregor8491ffe2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-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 Gregor8491ffe2010-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 Gregord3731192011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregord3731192011-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 Gregor12c9c002011-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 Gregor577f75a2009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCalla2becad2009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-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 McCalla93c9342009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000285
John McCalla2becad2009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
John McCalla2becad2009-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 McCall43fed0d2010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-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 McCall43fed0d2010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000301
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000303 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-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 McCall60d7b3a2010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000312
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregorb98b1992009-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 McCall60d7b3a2010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000322
Douglas Gregoraa165f82011-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 Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregordcee1a12009-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 Gregor7c1e98f2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000363 }
Mike Stump1eb44332009-09-09 15:08:12 +0000364
Douglas Gregor6cd21982009-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 ///
Sean Huntc3021132010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-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.
Sean Huntc3021132010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000376 }
Sean Huntc3021132010-05-05 15:23:54 +0000377
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000378 /// \brief Transform the given nested-name-specifier with source-location
379 /// information.
380 ///
381 /// By default, transforms all of the types and declarations within the
382 /// nested-name-specifier. Subclasses may override this function to provide
383 /// alternate behavior.
384 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
385 NestedNameSpecifierLoc NNS,
386 QualType ObjectType = QualType(),
387 NamedDecl *FirstQualifierInScope = 0);
388
Douglas Gregor81499bb2009-09-03 22:13:48 +0000389 /// \brief Transform the given declaration name.
390 ///
391 /// By default, transforms the types of conversion function, constructor,
392 /// and destructor names and then (if needed) rebuilds the declaration name.
393 /// Identifiers and selectors are returned unmodified. Sublcasses may
394 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000395 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000396 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000397
Douglas Gregor577f75a2009-08-04 16:50:30 +0000398 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000400 /// \param SS The nested-name-specifier that qualifies the template
401 /// name. This nested-name-specifier must already have been transformed.
402 ///
403 /// \param Name The template name to transform.
404 ///
405 /// \param NameLoc The source location of the template name.
406 ///
407 /// \param ObjectType If we're translating a template name within a member
408 /// access expression, this is the type of the object whose member template
409 /// is being referenced.
410 ///
411 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
412 /// also refers to a name within the current (lexical) scope, this is the
413 /// declaration it refers to.
414 ///
415 /// By default, transforms the template name by transforming the declarations
416 /// and nested-name-specifiers that occur within the template name.
417 /// Subclasses may override this function to provide alternate behavior.
418 TemplateName TransformTemplateName(CXXScopeSpec &SS,
419 TemplateName Name,
420 SourceLocation NameLoc,
421 QualType ObjectType = QualType(),
422 NamedDecl *FirstQualifierInScope = 0);
423
Douglas Gregor577f75a2009-08-04 16:50:30 +0000424 /// \brief Transform the given template argument.
425 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000426 /// By default, this operation transforms the type, expression, or
427 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000428 /// new template argument from the transformed result. Subclasses may
429 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000430 ///
431 /// Returns true if there was an error.
432 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
433 TemplateArgumentLoc &Output);
434
Douglas Gregorfcc12532010-12-20 17:31:10 +0000435 /// \brief Transform the given set of template arguments.
436 ///
437 /// By default, this operation transforms all of the template arguments
438 /// in the input set using \c TransformTemplateArgument(), and appends
439 /// the transformed arguments to the output list.
440 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000441 /// Note that this overload of \c TransformTemplateArguments() is merely
442 /// a convenience function. Subclasses that wish to override this behavior
443 /// should override the iterator-based member template version.
444 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000445 /// \param Inputs The set of template arguments to be transformed.
446 ///
447 /// \param NumInputs The number of template arguments in \p Inputs.
448 ///
449 /// \param Outputs The set of transformed template arguments output by this
450 /// routine.
451 ///
452 /// Returns true if an error occurred.
453 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
454 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000455 TemplateArgumentListInfo &Outputs) {
456 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
457 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000458
459 /// \brief Transform the given set of template arguments.
460 ///
461 /// By default, this operation transforms all of the template arguments
462 /// in the input set using \c TransformTemplateArgument(), and appends
463 /// the transformed arguments to the output list.
464 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000465 /// \param First An iterator to the first template argument.
466 ///
467 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000468 ///
469 /// \param Outputs The set of transformed template arguments output by this
470 /// routine.
471 ///
472 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000473 template<typename InputIterator>
474 bool TransformTemplateArguments(InputIterator First,
475 InputIterator Last,
476 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000477
John McCall833ca992009-10-29 08:12:44 +0000478 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
479 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
480 TemplateArgumentLoc &ArgLoc);
481
John McCalla93c9342009-12-07 02:54:59 +0000482 /// \brief Fakes up a TypeSourceInfo for a type.
483 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
484 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000485 getDerived().getBaseLocation());
486 }
Mike Stump1eb44332009-09-09 15:08:12 +0000487
John McCalla2becad2009-10-21 00:40:46 +0000488#define ABSTRACT_TYPELOC(CLASS, PARENT)
489#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000490 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000491#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000492
John McCall43fed0d2010-11-12 08:19:04 +0000493 QualType
494 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
495 TemplateSpecializationTypeLoc TL,
496 TemplateName Template);
497
498 QualType
499 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
500 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000501 TemplateName Template,
502 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000503
504 QualType
505 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000506 DependentTemplateSpecializationTypeLoc TL,
507 NestedNameSpecifierLoc QualifierLoc);
508
John McCall21ef0fa2010-03-11 09:03:00 +0000509 /// \brief Transforms the parameters of a function type into the
510 /// given vectors.
511 ///
512 /// The result vectors should be kept in sync; null entries in the
513 /// variables vector are acceptable.
514 ///
515 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000516 bool TransformFunctionTypeParams(SourceLocation Loc,
517 ParmVarDecl **Params, unsigned NumParams,
518 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000519 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000520 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000521
522 /// \brief Transforms a single function-type parameter. Return null
523 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000524 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
525 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000526
John McCall43fed0d2010-11-12 08:19:04 +0000527 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000528
John McCall60d7b3a2010-08-24 06:29:42 +0000529 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
530 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000531
Douglas Gregor43959a92009-08-20 07:17:43 +0000532#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000533 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000534#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000535 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000536#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000537#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000538
Douglas Gregor577f75a2009-08-04 16:50:30 +0000539 /// \brief Build a new pointer type given its pointee type.
540 ///
541 /// By default, performs semantic analysis when building the pointer type.
542 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000543 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544
545 /// \brief Build a new block pointer type given its pointee type.
546 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000547 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000549 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000550
John McCall85737a72009-10-30 00:06:24 +0000551 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552 ///
John McCall85737a72009-10-30 00:06:24 +0000553 /// By default, performs semantic analysis when building the
554 /// reference type. Subclasses may override this routine to provide
555 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 ///
John McCall85737a72009-10-30 00:06:24 +0000557 /// \param LValue whether the type was written with an lvalue sigil
558 /// or an rvalue sigil.
559 QualType RebuildReferenceType(QualType ReferentType,
560 bool LValue,
561 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000562
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563 /// \brief Build a new member pointer type given the pointee type and the
564 /// class type it refers into.
565 ///
566 /// By default, performs semantic analysis when building the member pointer
567 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000568 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
569 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new array type given the element type, size
572 /// modifier, size of the array (if known), size expression, and index type
573 /// qualifiers.
574 ///
575 /// By default, performs semantic analysis when building the array type.
576 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000577 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000578 QualType RebuildArrayType(QualType ElementType,
579 ArrayType::ArraySizeModifier SizeMod,
580 const llvm::APInt *Size,
581 Expr *SizeExpr,
582 unsigned IndexTypeQuals,
583 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000584
Douglas Gregor577f75a2009-08-04 16:50:30 +0000585 /// \brief Build a new constant array type given the element type, size
586 /// modifier, (known) size of the array, and index type qualifiers.
587 ///
588 /// By default, performs semantic analysis when building the array type.
589 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000590 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000591 ArrayType::ArraySizeModifier SizeMod,
592 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000593 unsigned IndexTypeQuals,
594 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000595
Douglas Gregor577f75a2009-08-04 16:50:30 +0000596 /// \brief Build a new incomplete array type given the element type, size
597 /// modifier, and index type qualifiers.
598 ///
599 /// By default, performs semantic analysis when building the array type.
600 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000601 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000602 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000603 unsigned IndexTypeQuals,
604 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605
Mike Stump1eb44332009-09-09 15:08:12 +0000606 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000607 /// size modifier, size expression, and index type qualifiers.
608 ///
609 /// By default, performs semantic analysis when building the array type.
610 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000611 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000612 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000613 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614 unsigned IndexTypeQuals,
615 SourceRange BracketsRange);
616
Mike Stump1eb44332009-09-09 15:08:12 +0000617 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000618 /// size modifier, size expression, and index type qualifiers.
619 ///
620 /// By default, performs semantic analysis when building the array type.
621 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000622 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000624 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000625 unsigned IndexTypeQuals,
626 SourceRange BracketsRange);
627
628 /// \brief Build a new vector type given the element type and
629 /// number of elements.
630 ///
631 /// By default, performs semantic analysis when building the vector type.
632 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000633 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000634 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Douglas Gregor577f75a2009-08-04 16:50:30 +0000636 /// \brief Build a new extended vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
641 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
642 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
644 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// given the element type and number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000649 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000650 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000652
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// \brief Build a new function type.
654 ///
655 /// By default, performs semantic analysis when building the function type.
656 /// Subclasses may override this routine to provide different behavior.
657 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000658 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000660 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000661 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000662 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000663
John McCalla2becad2009-10-21 00:40:46 +0000664 /// \brief Build a new unprototyped function type.
665 QualType RebuildFunctionNoProtoType(QualType ResultType);
666
John McCalled976492009-12-04 22:46:56 +0000667 /// \brief Rebuild an unresolved typename type, given the decl that
668 /// the UnresolvedUsingTypenameDecl was transformed to.
669 QualType RebuildUnresolvedUsingType(Decl *D);
670
Douglas Gregor577f75a2009-08-04 16:50:30 +0000671 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000672 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000673 return SemaRef.Context.getTypeDeclType(Typedef);
674 }
675
676 /// \brief Build a new class/struct/union type.
677 QualType RebuildRecordType(RecordDecl *Record) {
678 return SemaRef.Context.getTypeDeclType(Record);
679 }
680
681 /// \brief Build a new Enum type.
682 QualType RebuildEnumType(EnumDecl *Enum) {
683 return SemaRef.Context.getTypeDeclType(Enum);
684 }
John McCall7da24312009-09-05 00:15:47 +0000685
Mike Stump1eb44332009-09-09 15:08:12 +0000686 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 ///
688 /// By default, performs semantic analysis when building the typeof type.
689 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000690 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000691
Mike Stump1eb44332009-09-09 15:08:12 +0000692 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000693 ///
694 /// By default, builds a new TypeOfType with the given underlying type.
695 QualType RebuildTypeOfType(QualType Underlying);
696
Mike Stump1eb44332009-09-09 15:08:12 +0000697 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000698 ///
699 /// By default, performs semantic analysis when building the decltype type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000701 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000702
Richard Smith34b41d92011-02-20 03:19:35 +0000703 /// \brief Build a new C++0x auto type.
704 ///
705 /// By default, builds a new AutoType with the given deduced type.
706 QualType RebuildAutoType(QualType Deduced) {
707 return SemaRef.Context.getAutoType(Deduced);
708 }
709
Douglas Gregor577f75a2009-08-04 16:50:30 +0000710 /// \brief Build a new template specialization type.
711 ///
712 /// By default, performs semantic analysis when building the template
713 /// specialization type. Subclasses may override this routine to provide
714 /// different behavior.
715 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000716 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000717 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000718
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000719 /// \brief Build a new parenthesized type.
720 ///
721 /// By default, builds a new ParenType type from the inner type.
722 /// Subclasses may override this routine to provide different behavior.
723 QualType RebuildParenType(QualType InnerType) {
724 return SemaRef.Context.getParenType(InnerType);
725 }
726
Douglas Gregor577f75a2009-08-04 16:50:30 +0000727 /// \brief Build a new qualified name type.
728 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000729 /// By default, builds a new ElaboratedType type from the keyword,
730 /// the nested-name-specifier and the named type.
731 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000732 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
733 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000734 NestedNameSpecifierLoc QualifierLoc,
735 QualType Named) {
736 return SemaRef.Context.getElaboratedType(Keyword,
737 QualifierLoc.getNestedNameSpecifier(),
738 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000739 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740
741 /// \brief Build a new typename type that refers to a template-id.
742 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000743 /// By default, builds a new DependentNameType type from the
744 /// nested-name-specifier and the given type. Subclasses may override
745 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000746 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000747 ElaboratedTypeKeyword Keyword,
748 NestedNameSpecifierLoc QualifierLoc,
749 const IdentifierInfo *Name,
750 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000751 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000752 // Rebuild the template name.
753 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000754 CXXScopeSpec SS;
755 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000756 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000757 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000758
759 if (InstName.isNull())
760 return QualType();
761
762 // If it's still dependent, make a dependent specialization.
763 if (InstName.getAsDependentTemplateName())
764 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
765 QualifierLoc.getNestedNameSpecifier(),
766 Name,
767 Args);
768
769 // Otherwise, make an elaborated type wrapping a non-dependent
770 // specialization.
771 QualType T =
772 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
773 if (T.isNull()) return QualType();
774
775 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
776 return T;
777
778 return SemaRef.Context.getElaboratedType(Keyword,
779 QualifierLoc.getNestedNameSpecifier(),
780 T);
781 }
782
Douglas Gregor577f75a2009-08-04 16:50:30 +0000783 /// \brief Build a new typename type that refers to an identifier.
784 ///
785 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000786 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000787 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000788 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000789 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000790 NestedNameSpecifierLoc QualifierLoc,
791 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000792 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000793 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000794 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000795
Douglas Gregor2494dd02011-03-01 01:34:45 +0000796 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000797 // If the name is still dependent, just build a new dependent name type.
798 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000799 return SemaRef.Context.getDependentNameType(Keyword,
800 QualifierLoc.getNestedNameSpecifier(),
801 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000802 }
803
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000804 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000805 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000806 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000807
808 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
809
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000810 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000811 // into a non-dependent elaborated-type-specifier. Find the tag we're
812 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000813 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000814 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
815 if (!DC)
816 return QualType();
817
John McCall56138762010-05-27 06:40:31 +0000818 if (SemaRef.RequireCompleteDeclContext(SS, DC))
819 return QualType();
820
Douglas Gregor40336422010-03-31 22:19:08 +0000821 TagDecl *Tag = 0;
822 SemaRef.LookupQualifiedName(Result, DC);
823 switch (Result.getResultKind()) {
824 case LookupResult::NotFound:
825 case LookupResult::NotFoundInCurrentInstantiation:
826 break;
Sean Huntc3021132010-05-05 15:23:54 +0000827
Douglas Gregor40336422010-03-31 22:19:08 +0000828 case LookupResult::Found:
829 Tag = Result.getAsSingle<TagDecl>();
830 break;
Sean Huntc3021132010-05-05 15:23:54 +0000831
Douglas Gregor40336422010-03-31 22:19:08 +0000832 case LookupResult::FoundOverloaded:
833 case LookupResult::FoundUnresolvedValue:
834 llvm_unreachable("Tag lookup cannot find non-tags");
835 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000836
Douglas Gregor40336422010-03-31 22:19:08 +0000837 case LookupResult::Ambiguous:
838 // Let the LookupResult structure handle ambiguities.
839 return QualType();
840 }
841
842 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000843 // Check where the name exists but isn't a tag type and use that to emit
844 // better diagnostics.
845 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
846 SemaRef.LookupQualifiedName(Result, DC);
847 switch (Result.getResultKind()) {
848 case LookupResult::Found:
849 case LookupResult::FoundOverloaded:
850 case LookupResult::FoundUnresolvedValue: {
851 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
852 unsigned Kind = 0;
853 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000854 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
855 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000856 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
857 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
858 break;
859 }
860 default:
861 // FIXME: Would be nice to highlight just the source range.
862 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
863 << Kind << Id << DC;
864 break;
865 }
Douglas Gregor40336422010-03-31 22:19:08 +0000866 return QualType();
867 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000868
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000869 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
870 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000871 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
872 return QualType();
873 }
874
875 // Build the elaborated-type-specifier type.
876 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000877 return SemaRef.Context.getElaboratedType(Keyword,
878 QualifierLoc.getNestedNameSpecifier(),
879 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000880 }
Mike Stump1eb44332009-09-09 15:08:12 +0000881
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000882 /// \brief Build a new pack expansion type.
883 ///
884 /// By default, builds a new PackExpansionType type from the given pattern.
885 /// Subclasses may override this routine to provide different behavior.
886 QualType RebuildPackExpansionType(QualType Pattern,
887 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000888 SourceLocation EllipsisLoc,
889 llvm::Optional<unsigned> NumExpansions) {
890 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
891 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000892 }
893
Douglas Gregord1067e52009-08-06 06:41:21 +0000894 /// \brief Build a new template name given a nested name specifier, a flag
895 /// indicating whether the "template" keyword was provided, and the template
896 /// that the template name refers to.
897 ///
898 /// By default, builds the new template name directly. Subclasses may override
899 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000900 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000901 bool TemplateKW,
902 TemplateDecl *Template);
903
Douglas Gregord1067e52009-08-06 06:41:21 +0000904 /// \brief Build a new template name given a nested name specifier and the
905 /// name that is referred to as a template.
906 ///
907 /// By default, performs semantic analysis to determine whether the name can
908 /// be resolved to a specific template, then builds the appropriate kind of
909 /// template name. Subclasses may override this routine to provide different
910 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000911 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
912 const IdentifierInfo &Name,
913 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000914 QualType ObjectType,
915 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000916
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000917 /// \brief Build a new template name given a nested name specifier and the
918 /// overloaded operator name that is referred to as a template.
919 ///
920 /// By default, performs semantic analysis to determine whether the name can
921 /// be resolved to a specific template, then builds the appropriate kind of
922 /// template name. Subclasses may override this routine to provide different
923 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000924 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000925 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000926 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000927 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000928
929 /// \brief Build a new template name given a template template parameter pack
930 /// and the
931 ///
932 /// By default, performs semantic analysis to determine whether the name can
933 /// be resolved to a specific template, then builds the appropriate kind of
934 /// template name. Subclasses may override this routine to provide different
935 /// behavior.
936 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
937 const TemplateArgument &ArgPack) {
938 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
939 }
940
Douglas Gregor43959a92009-08-20 07:17:43 +0000941 /// \brief Build a new compound statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000945 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000946 MultiStmtArg Statements,
947 SourceLocation RBraceLoc,
948 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000949 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000950 IsStmtExpr);
951 }
952
953 /// \brief Build a new case statement.
954 ///
955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000957 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000958 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000959 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000960 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000961 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000962 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000963 ColonLoc);
964 }
Mike Stump1eb44332009-09-09 15:08:12 +0000965
Douglas Gregor43959a92009-08-20 07:17:43 +0000966 /// \brief Attach the body to a new case statement.
967 ///
968 /// By default, performs semantic analysis to build the new statement.
969 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000970 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000971 getSema().ActOnCaseStmtBody(S, Body);
972 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 }
Mike Stump1eb44332009-09-09 15:08:12 +0000974
Douglas Gregor43959a92009-08-20 07:17:43 +0000975 /// \brief Build a new default statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000979 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000981 Stmt *SubStmt) {
982 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 /*CurScope=*/0);
984 }
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 /// \brief Build a new label statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +0000990 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
991 SourceLocation ColonLoc, Stmt *SubStmt) {
992 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 }
Mike Stump1eb44332009-09-09 15:08:12 +0000994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Build a new "if" statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001000 VarDecl *CondVar, Stmt *Then,
1001 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001002 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 }
Mike Stump1eb44332009-09-09 15:08:12 +00001004
Douglas Gregor43959a92009-08-20 07:17:43 +00001005 /// \brief Start building a new switch statement.
1006 ///
1007 /// By default, performs semantic analysis to build the new statement.
1008 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001009 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001010 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001011 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001012 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 }
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 /// \brief Attach the body to the switch statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001019 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001020 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001021 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 }
1023
1024 /// \brief Build a new while statement.
1025 ///
1026 /// By default, performs semantic analysis to build the new statement.
1027 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001028 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1029 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001030 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001031 }
Mike Stump1eb44332009-09-09 15:08:12 +00001032
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 /// \brief Build a new do-while statement.
1034 ///
1035 /// By default, performs semantic analysis to build the new statement.
1036 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001037 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001038 SourceLocation WhileLoc, SourceLocation LParenLoc,
1039 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001040 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1041 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new for statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001048 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1049 Stmt *Init, Sema::FullExprArg Cond,
1050 VarDecl *CondVar, Sema::FullExprArg Inc,
1051 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001052 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001053 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 /// \brief Build a new goto statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001060 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1061 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001062 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001063 }
1064
1065 /// \brief Build a new indirect goto statement.
1066 ///
1067 /// By default, performs semantic analysis to build the new statement.
1068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001069 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001070 SourceLocation StarLoc,
1071 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001072 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001073 }
Mike Stump1eb44332009-09-09 15:08:12 +00001074
Douglas Gregor43959a92009-08-20 07:17:43 +00001075 /// \brief Build a new return statement.
1076 ///
1077 /// By default, performs semantic analysis to build the new statement.
1078 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001079 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001080 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001081 }
Mike Stump1eb44332009-09-09 15:08:12 +00001082
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 /// \brief Build a new declaration statement.
1084 ///
1085 /// By default, performs semantic analysis to build the new statement.
1086 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001087 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001088 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001090 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1091 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 }
Mike Stump1eb44332009-09-09 15:08:12 +00001093
Anders Carlsson703e3942010-01-24 05:50:09 +00001094 /// \brief Build a new inline asm statement.
1095 ///
1096 /// By default, performs semantic analysis to build the new statement.
1097 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001098 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001099 bool IsSimple,
1100 bool IsVolatile,
1101 unsigned NumOutputs,
1102 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001103 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001104 MultiExprArg Constraints,
1105 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001106 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001107 MultiExprArg Clobbers,
1108 SourceLocation RParenLoc,
1109 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001110 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001111 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001112 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001113 RParenLoc, MSAsm);
1114 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001115
1116 /// \brief Build a new Objective-C @try statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001120 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001121 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001122 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001123 Stmt *Finally) {
1124 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1125 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001126 }
1127
Douglas Gregorbe270a02010-04-26 17:57:08 +00001128 /// \brief Rebuild an Objective-C exception declaration.
1129 ///
1130 /// By default, performs semantic analysis to build the new declaration.
1131 /// Subclasses may override this routine to provide different behavior.
1132 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1133 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001134 return getSema().BuildObjCExceptionDecl(TInfo, T,
1135 ExceptionDecl->getInnerLocStart(),
1136 ExceptionDecl->getLocation(),
1137 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001138 }
Sean Huntc3021132010-05-05 15:23:54 +00001139
Douglas Gregorbe270a02010-04-26 17:57:08 +00001140 /// \brief Build a new Objective-C @catch statement.
1141 ///
1142 /// By default, performs semantic analysis to build the new statement.
1143 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001144 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001145 SourceLocation RParenLoc,
1146 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001147 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001148 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001149 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001150 }
Sean Huntc3021132010-05-05 15:23:54 +00001151
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001152 /// \brief Build a new Objective-C @finally statement.
1153 ///
1154 /// By default, performs semantic analysis to build the new statement.
1155 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001156 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001157 Stmt *Body) {
1158 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001159 }
Sean Huntc3021132010-05-05 15:23:54 +00001160
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001161 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001162 ///
1163 /// By default, performs semantic analysis to build the new statement.
1164 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001165 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001166 Expr *Operand) {
1167 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001168 }
Sean Huntc3021132010-05-05 15:23:54 +00001169
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001170 /// \brief Build a new Objective-C @synchronized statement.
1171 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001174 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001175 Expr *Object,
1176 Stmt *Body) {
1177 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1178 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001179 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001180
1181 /// \brief Build a new Objective-C fast enumeration statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001185 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001186 SourceLocation LParenLoc,
1187 Stmt *Element,
1188 Expr *Collection,
1189 SourceLocation RParenLoc,
1190 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001191 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001192 Element,
1193 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001194 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001195 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001196 }
Sean Huntc3021132010-05-05 15:23:54 +00001197
Douglas Gregor43959a92009-08-20 07:17:43 +00001198 /// \brief Build a new C++ exception declaration.
1199 ///
1200 /// By default, performs semantic analysis to build the new decaration.
1201 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001202 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001203 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001204 SourceLocation StartLoc,
1205 SourceLocation IdLoc,
1206 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001207 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1208 StartLoc, IdLoc, Id);
1209 if (Var)
1210 getSema().CurContext->addDecl(Var);
1211 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001212 }
1213
1214 /// \brief Build a new C++ catch statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001218 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001219 VarDecl *ExceptionDecl,
1220 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001221 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1222 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001223 }
Mike Stump1eb44332009-09-09 15:08:12 +00001224
Douglas Gregor43959a92009-08-20 07:17:43 +00001225 /// \brief Build a new C++ try statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001229 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001230 Stmt *TryBlock,
1231 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001232 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001233 }
Mike Stump1eb44332009-09-09 15:08:12 +00001234
Richard Smithad762fc2011-04-14 22:09:26 +00001235 /// \brief Build a new C++0x range-based for statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
1239 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1240 SourceLocation ColonLoc,
1241 Stmt *Range, Stmt *BeginEnd,
1242 Expr *Cond, Expr *Inc,
1243 Stmt *LoopVar,
1244 SourceLocation RParenLoc) {
1245 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1246 Cond, Inc, LoopVar, RParenLoc);
1247 }
1248
1249 /// \brief Attach body to a C++0x range-based for statement.
1250 ///
1251 /// By default, performs semantic analysis to finish the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
1253 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1254 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1255 }
1256
Douglas Gregorb98b1992009-08-11 05:31:07 +00001257 /// \brief Build a new expression that references a declaration.
1258 ///
1259 /// By default, performs semantic analysis to build the new expression.
1260 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001261 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001262 LookupResult &R,
1263 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001264 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1265 }
1266
1267
1268 /// \brief Build a new expression that references a declaration.
1269 ///
1270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001272 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001273 ValueDecl *VD,
1274 const DeclarationNameInfo &NameInfo,
1275 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001276 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001277 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001278
1279 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001280
1281 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001282 }
Mike Stump1eb44332009-09-09 15:08:12 +00001283
Douglas Gregorb98b1992009-08-11 05:31:07 +00001284 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001285 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 /// By default, performs semantic analysis to build the new expression.
1287 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001288 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001289 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001290 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 }
1292
Douglas Gregora71d8192009-09-04 17:36:40 +00001293 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001294 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001297 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001298 SourceLocation OperatorLoc,
1299 bool isArrow,
1300 CXXScopeSpec &SS,
1301 TypeSourceInfo *ScopeType,
1302 SourceLocation CCLoc,
1303 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001304 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001305
Douglas Gregorb98b1992009-08-11 05:31:07 +00001306 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001307 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001310 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001311 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001312 Expr *SubExpr) {
1313 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001314 }
Mike Stump1eb44332009-09-09 15:08:12 +00001315
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001316 /// \brief Build a new builtin offsetof expression.
1317 ///
1318 /// By default, performs semantic analysis to build the new expression.
1319 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001320 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001321 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001322 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001323 unsigned NumComponents,
1324 SourceLocation RParenLoc) {
1325 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1326 NumComponents, RParenLoc);
1327 }
Sean Huntc3021132010-05-05 15:23:54 +00001328
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001329 /// \brief Build a new sizeof, alignof or vec_step expression with a
1330 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001331 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001334 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1335 SourceLocation OpLoc,
1336 UnaryExprOrTypeTrait ExprKind,
1337 SourceRange R) {
1338 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 }
1340
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001341 /// \brief Build a new sizeof, alignof or vec step expression with an
1342 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001343 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001346 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1347 UnaryExprOrTypeTrait ExprKind,
1348 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001349 ExprResult Result
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001350 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001351 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001352 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 return move(Result);
1355 }
Mike Stump1eb44332009-09-09 15:08:12 +00001356
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001358 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001361 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001363 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001364 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001365 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1366 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 RBracketLoc);
1368 }
1369
1370 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001371 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001376 SourceLocation RParenLoc,
1377 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001378 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001379 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 }
1381
1382 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001383 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001386 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001387 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001388 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001389 const DeclarationNameInfo &MemberNameInfo,
1390 ValueDecl *Member,
1391 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001392 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001393 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001394 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001395 // We have a reference to an unnamed field. This is always the
1396 // base of an anonymous struct/union member access, i.e. the
1397 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001398 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001399 assert(Member->getType()->isRecordType() &&
1400 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001401
John Wiegley429bb272011-04-08 18:41:53 +00001402 ExprResult BaseResult =
1403 getSema().PerformObjectMemberConversion(Base,
1404 QualifierLoc.getNestedNameSpecifier(),
1405 FoundDecl, Member);
1406 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001407 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001408 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001409 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001410 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001411 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001412 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001413 cast<FieldDecl>(Member)->getType(),
1414 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001415 return getSema().Owned(ME);
1416 }
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001418 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001419 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001420
John Wiegley429bb272011-04-08 18:41:53 +00001421 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1422 if (BaseResult.isInvalid())
1423 return ExprError();
1424 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001425 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001426
John McCall6bb80172010-03-30 21:47:33 +00001427 // FIXME: this involves duplicating earlier analysis in a lot of
1428 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001429 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001430 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001431 R.resolveKind();
1432
John McCall9ae2f072010-08-23 23:25:46 +00001433 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001434 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001435 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 }
Mike Stump1eb44332009-09-09 15:08:12 +00001437
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001439 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001442 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001443 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001444 Expr *LHS, Expr *RHS) {
1445 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 }
1447
1448 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001449 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001452 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001453 SourceLocation QuestionLoc,
1454 Expr *LHS,
1455 SourceLocation ColonLoc,
1456 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001457 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1458 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 }
1460
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001465 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001466 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001468 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001469 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001470 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 }
Mike Stump1eb44332009-09-09 15:08:12 +00001472
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001474 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// By default, performs semantic analysis to build the new expression.
1476 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001477 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001478 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001480 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001481 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001482 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001483 }
Mike Stump1eb44332009-09-09 15:08:12 +00001484
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001486 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001489 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 SourceLocation OpLoc,
1491 SourceLocation AccessorLoc,
1492 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001493
John McCall129e2df2009-11-30 22:42:35 +00001494 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001495 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001496 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001497 OpLoc, /*IsArrow*/ false,
1498 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001499 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001500 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 }
Mike Stump1eb44332009-09-09 15:08:12 +00001502
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001504 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001507 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001509 SourceLocation RBraceLoc,
1510 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001511 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001512 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1513 if (Result.isInvalid() || ResultTy->isDependentType())
1514 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001515
Douglas Gregore48319a2009-11-09 17:16:50 +00001516 // Patch in the result type we were given, which may have been computed
1517 // when the initial InitListExpr was built.
1518 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1519 ILE->setType(ResultTy);
1520 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 }
Mike Stump1eb44332009-09-09 15:08:12 +00001522
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001524 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001527 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 MultiExprArg ArrayExprs,
1529 SourceLocation EqualOrColonLoc,
1530 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001531 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001532 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001533 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001534 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001537
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 ArrayExprs.release();
1539 return move(Result);
1540 }
Mike Stump1eb44332009-09-09 15:08:12 +00001541
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001543 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// By default, builds the implicit value initialization without performing
1545 /// any semantic analysis. Subclasses may override this routine to provide
1546 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001547 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1549 }
Mike Stump1eb44332009-09-09 15:08:12 +00001550
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001552 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 /// By default, performs semantic analysis to build the new expression.
1554 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001555 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001556 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001557 SourceLocation RParenLoc) {
1558 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001559 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001560 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 }
1562
1563 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001564 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001567 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 MultiExprArg SubExprs,
1569 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001570 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001571 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 }
Mike Stump1eb44332009-09-09 15:08:12 +00001573
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001575 ///
1576 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 /// rather than attempting to map the label statement itself.
1578 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001579 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001580 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001581 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001591 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new __builtin_choose_expr expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001598 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001599 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001600 SourceLocation RParenLoc) {
1601 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001602 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 RParenLoc);
1604 }
Mike Stump1eb44332009-09-09 15:08:12 +00001605
Peter Collingbournef111d932011-04-15 00:35:48 +00001606 /// \brief Build a new generic selection expression.
1607 ///
1608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
1610 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1611 SourceLocation DefaultLoc,
1612 SourceLocation RParenLoc,
1613 Expr *ControllingExpr,
1614 TypeSourceInfo **Types,
1615 Expr **Exprs,
1616 unsigned NumAssocs) {
1617 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1618 ControllingExpr, Types, Exprs,
1619 NumAssocs);
1620 }
1621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// \brief Build a new overloaded operator call expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// The semantic analysis provides the behavior of template instantiation,
1626 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001627 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// argument-dependent lookup, etc. Subclasses may override this routine to
1629 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001630 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001632 Expr *Callee,
1633 Expr *First,
1634 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001635
1636 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 /// reinterpret_cast.
1638 ///
1639 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001640 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001642 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 Stmt::StmtClass Class,
1644 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001645 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 SourceLocation RAngleLoc,
1647 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001648 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 SourceLocation RParenLoc) {
1650 switch (Class) {
1651 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001652 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001653 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001654 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655
1656 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001657 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001658 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001659 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001660
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001662 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001663 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001664 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001668 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001669 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001670 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001671
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 default:
1673 assert(false && "Invalid C++ named cast");
1674 break;
1675 }
Mike Stump1eb44332009-09-09 15:08:12 +00001676
John McCallf312b1e2010-08-26 23:41:50 +00001677 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 }
Mike Stump1eb44332009-09-09 15:08:12 +00001679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new C++ static_cast expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001686 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 SourceLocation RAngleLoc,
1688 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001689 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001691 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001692 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001693 SourceRange(LAngleLoc, RAngleLoc),
1694 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 }
1696
1697 /// \brief Build a new C++ dynamic_cast expression.
1698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001701 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001703 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 SourceLocation RAngleLoc,
1705 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001706 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001708 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001709 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001710 SourceRange(LAngleLoc, RAngleLoc),
1711 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 }
1713
1714 /// \brief Build a new C++ reinterpret_cast expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001718 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001720 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 SourceLocation RAngleLoc,
1722 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001725 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001726 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001727 SourceRange(LAngleLoc, RAngleLoc),
1728 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 }
1730
1731 /// \brief Build a new C++ const_cast expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001735 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001737 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 SourceLocation RAngleLoc,
1739 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001740 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001742 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001743 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001744 SourceRange(LAngleLoc, RAngleLoc),
1745 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 }
Mike Stump1eb44332009-09-09 15:08:12 +00001747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 /// \brief Build a new C++ functional-style cast expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001752 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1753 SourceLocation LParenLoc,
1754 Expr *Sub,
1755 SourceLocation RParenLoc) {
1756 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001757 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 RParenLoc);
1759 }
Mike Stump1eb44332009-09-09 15:08:12 +00001760
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 /// \brief Build a new C++ typeid(type) expression.
1762 ///
1763 /// By default, performs semantic analysis to build the new expression.
1764 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001765 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001766 SourceLocation TypeidLoc,
1767 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001768 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001769 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001770 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 }
Mike Stump1eb44332009-09-09 15:08:12 +00001772
Francois Pichet01b7c302010-09-08 12:20:18 +00001773
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 /// \brief Build a new C++ typeid(expr) expression.
1775 ///
1776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001778 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001779 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001780 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001782 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001783 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001784 }
1785
Francois Pichet01b7c302010-09-08 12:20:18 +00001786 /// \brief Build a new C++ __uuidof(type) expression.
1787 ///
1788 /// By default, performs semantic analysis to build the new expression.
1789 /// Subclasses may override this routine to provide different behavior.
1790 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1791 SourceLocation TypeidLoc,
1792 TypeSourceInfo *Operand,
1793 SourceLocation RParenLoc) {
1794 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1795 RParenLoc);
1796 }
1797
1798 /// \brief Build a new C++ __uuidof(expr) expression.
1799 ///
1800 /// By default, performs semantic analysis to build the new expression.
1801 /// Subclasses may override this routine to provide different behavior.
1802 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1803 SourceLocation TypeidLoc,
1804 Expr *Operand,
1805 SourceLocation RParenLoc) {
1806 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1807 RParenLoc);
1808 }
1809
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 /// \brief Build a new C++ "this" expression.
1811 ///
1812 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001813 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001816 QualType ThisType,
1817 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001819 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1820 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 }
1822
1823 /// \brief Build a new C++ throw expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001827 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001828 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 }
1830
1831 /// \brief Build a new C++ default-argument expression.
1832 ///
1833 /// By default, builds a new default-argument expression, which does not
1834 /// require any semantic analysis. Subclasses may override this routine to
1835 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001837 ParmVarDecl *Param) {
1838 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1839 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 }
1841
1842 /// \brief Build a new C++ zero-initialization expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001846 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1847 SourceLocation LParenLoc,
1848 SourceLocation RParenLoc) {
1849 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001850 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001851 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 }
Mike Stump1eb44332009-09-09 15:08:12 +00001853
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 /// \brief Build a new C++ "new" expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001858 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001859 bool UseGlobal,
1860 SourceLocation PlacementLParen,
1861 MultiExprArg PlacementArgs,
1862 SourceLocation PlacementRParen,
1863 SourceRange TypeIdParens,
1864 QualType AllocatedType,
1865 TypeSourceInfo *AllocatedTypeInfo,
1866 Expr *ArraySize,
1867 SourceLocation ConstructorLParen,
1868 MultiExprArg ConstructorArgs,
1869 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001870 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 PlacementLParen,
1872 move(PlacementArgs),
1873 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001874 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001875 AllocatedType,
1876 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001877 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 ConstructorLParen,
1879 move(ConstructorArgs),
1880 ConstructorRParen);
1881 }
Mike Stump1eb44332009-09-09 15:08:12 +00001882
Douglas Gregorb98b1992009-08-11 05:31:07 +00001883 /// \brief Build a new C++ "delete" expression.
1884 ///
1885 /// By default, performs semantic analysis to build the new expression.
1886 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001887 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001888 bool IsGlobalDelete,
1889 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001890 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001891 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001892 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
Mike Stump1eb44332009-09-09 15:08:12 +00001894
Douglas Gregorb98b1992009-08-11 05:31:07 +00001895 /// \brief Build a new unary type trait expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001899 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001900 SourceLocation StartLoc,
1901 TypeSourceInfo *T,
1902 SourceLocation RParenLoc) {
1903 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 }
1905
Francois Pichet6ad6f282010-12-07 00:08:36 +00001906 /// \brief Build a new binary type trait expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
1910 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1911 SourceLocation StartLoc,
1912 TypeSourceInfo *LhsT,
1913 TypeSourceInfo *RhsT,
1914 SourceLocation RParenLoc) {
1915 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1916 }
1917
John Wiegley21ff2e52011-04-28 00:16:57 +00001918 /// \brief Build a new array type trait expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
1922 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1923 SourceLocation StartLoc,
1924 TypeSourceInfo *TSInfo,
1925 Expr *DimExpr,
1926 SourceLocation RParenLoc) {
1927 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1928 }
1929
John Wiegley55262202011-04-25 06:54:41 +00001930 /// \brief Build a new expression trait expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
1934 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1935 SourceLocation StartLoc,
1936 Expr *Queried,
1937 SourceLocation RParenLoc) {
1938 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1939 }
1940
Mike Stump1eb44332009-09-09 15:08:12 +00001941 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 /// expression.
1943 ///
1944 /// By default, performs semantic analysis to build the new expression.
1945 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001946 ExprResult RebuildDependentScopeDeclRefExpr(
1947 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001948 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001949 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001950 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001951 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001952
1953 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001954 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001955 *TemplateArgs);
1956
Abramo Bagnara25777432010-08-11 22:01:17 +00001957 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001958 }
1959
1960 /// \brief Build a new template-id expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001964 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001965 LookupResult &R,
1966 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001967 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001968 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 }
1970
1971 /// \brief Build a new object-construction expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001975 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001976 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 CXXConstructorDecl *Constructor,
1978 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001979 MultiExprArg Args,
1980 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001981 CXXConstructExpr::ConstructionKind ConstructKind,
1982 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001983 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001984 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001985 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001986 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001987
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001988 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001989 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001990 RequiresZeroInit, ConstructKind,
1991 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001992 }
1993
1994 /// \brief Build a new object-construction expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001998 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1999 SourceLocation LParenLoc,
2000 MultiExprArg Args,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002003 LParenLoc,
2004 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002005 RParenLoc);
2006 }
2007
2008 /// \brief Build a new object-construction expression.
2009 ///
2010 /// By default, performs semantic analysis to build the new expression.
2011 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002012 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2013 SourceLocation LParenLoc,
2014 MultiExprArg Args,
2015 SourceLocation RParenLoc) {
2016 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002017 LParenLoc,
2018 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 RParenLoc);
2020 }
Mike Stump1eb44332009-09-09 15:08:12 +00002021
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 /// \brief Build a new member reference expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002026 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002027 QualType BaseType,
2028 bool IsArrow,
2029 SourceLocation OperatorLoc,
2030 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002031 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002032 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002033 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002034 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002035 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002036
John McCall9ae2f072010-08-23 23:25:46 +00002037 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002038 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002039 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002040 MemberNameInfo,
2041 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 }
2043
John McCall129e2df2009-11-30 22:42:35 +00002044 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002049 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002050 SourceLocation OperatorLoc,
2051 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002052 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002053 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002054 LookupResult &R,
2055 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002056 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002057 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002058
John McCall9ae2f072010-08-23 23:25:46 +00002059 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002060 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002061 SS, FirstQualifierInScope,
2062 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002063 }
Mike Stump1eb44332009-09-09 15:08:12 +00002064
Sebastian Redl2e156222010-09-10 20:55:43 +00002065 /// \brief Build a new noexcept expression.
2066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
2069 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2070 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2071 }
2072
Douglas Gregoree8aff02011-01-04 17:33:58 +00002073 /// \brief Build a new expression to compute the length of a parameter pack.
2074 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2075 SourceLocation PackLoc,
2076 SourceLocation RParenLoc,
2077 unsigned Length) {
2078 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2079 OperatorLoc, Pack, PackLoc,
2080 RParenLoc, Length);
2081 }
2082
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 /// \brief Build a new Objective-C @encode expression.
2084 ///
2085 /// By default, performs semantic analysis to build the new expression.
2086 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002087 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002088 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002089 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002090 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002092 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093
Douglas Gregor92e986e2010-04-22 16:44:27 +00002094 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002095 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002096 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002097 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002098 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002099 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002100 MultiExprArg Args,
2101 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002102 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2103 ReceiverTypeInfo->getType(),
2104 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002105 Sel, Method, LBracLoc, SelectorLoc,
2106 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002107 }
2108
2109 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002110 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002111 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002112 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002113 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002114 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002115 MultiExprArg Args,
2116 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002117 return SemaRef.BuildInstanceMessage(Receiver,
2118 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002119 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002120 Sel, Method, LBracLoc, SelectorLoc,
2121 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002122 }
2123
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002124 /// \brief Build a new Objective-C ivar reference expression.
2125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002128 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002129 SourceLocation IvarLoc,
2130 bool IsArrow, bool IsFreeIvar) {
2131 // FIXME: We lose track of the IsFreeIvar bit.
2132 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002133 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002134 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2135 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002136 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002137 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002138 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002139 false);
John Wiegley429bb272011-04-08 18:41:53 +00002140 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002141 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002142
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002143 if (Result.get())
2144 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002145
John Wiegley429bb272011-04-08 18:41:53 +00002146 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002147 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002148 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002149 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002150 /*TemplateArgs=*/0);
2151 }
Douglas Gregore3303542010-04-26 20:47:02 +00002152
2153 /// \brief Build a new Objective-C property reference expression.
2154 ///
2155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002157 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002158 ObjCPropertyDecl *Property,
2159 SourceLocation PropertyLoc) {
2160 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002161 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002162 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2163 Sema::LookupMemberName);
2164 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002165 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002166 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002167 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002168 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002169 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002170
Douglas Gregore3303542010-04-26 20:47:02 +00002171 if (Result.get())
2172 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002173
John Wiegley429bb272011-04-08 18:41:53 +00002174 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002175 /*FIXME:*/PropertyLoc, IsArrow,
2176 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002177 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002178 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002179 /*TemplateArgs=*/0);
2180 }
Sean Huntc3021132010-05-05 15:23:54 +00002181
John McCall12f78a62010-12-02 01:19:52 +00002182 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002183 ///
2184 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002185 /// Subclasses may override this routine to provide different behavior.
2186 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2187 ObjCMethodDecl *Getter,
2188 ObjCMethodDecl *Setter,
2189 SourceLocation PropertyLoc) {
2190 // Since these expressions can only be value-dependent, we do not
2191 // need to perform semantic analysis again.
2192 return Owned(
2193 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2194 VK_LValue, OK_ObjCProperty,
2195 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002196 }
2197
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002198 /// \brief Build a new Objective-C "isa" expression.
2199 ///
2200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002202 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002203 bool IsArrow) {
2204 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002205 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002206 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2207 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002208 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002209 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002210 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002211 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002212 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002213
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002214 if (Result.get())
2215 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002216
John Wiegley429bb272011-04-08 18:41:53 +00002217 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002218 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002220 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002221 /*TemplateArgs=*/0);
2222 }
Sean Huntc3021132010-05-05 15:23:54 +00002223
Douglas Gregorb98b1992009-08-11 05:31:07 +00002224 /// \brief Build a new shuffle vector expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002228 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002229 MultiExprArg SubExprs,
2230 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002231 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002232 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002233 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2234 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2235 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2236 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002237
Douglas Gregorb98b1992009-08-11 05:31:07 +00002238 // Build a reference to the __builtin_shufflevector builtin
2239 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002240 ExprResult Callee
2241 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2242 VK_LValue, BuiltinLoc));
2243 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2244 if (Callee.isInvalid())
2245 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002246
2247 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002248 unsigned NumSubExprs = SubExprs.size();
2249 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002250 ExprResult TheCall = SemaRef.Owned(
2251 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002252 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002253 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002254 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002255 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002256
Douglas Gregorb98b1992009-08-11 05:31:07 +00002257 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002258 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002259 }
John McCall43fed0d2010-11-12 08:19:04 +00002260
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002261 /// \brief Build a new template argument pack expansion.
2262 ///
2263 /// By default, performs semantic analysis to build a new pack expansion
2264 /// for a template argument. Subclasses may override this routine to provide
2265 /// different behavior.
2266 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002267 SourceLocation EllipsisLoc,
2268 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002269 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002270 case TemplateArgument::Expression: {
2271 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002272 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2273 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002274 if (Result.isInvalid())
2275 return TemplateArgumentLoc();
2276
2277 return TemplateArgumentLoc(Result.get(), Result.get());
2278 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002279
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002280 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002281 return TemplateArgumentLoc(TemplateArgument(
2282 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002283 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002284 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002285 Pattern.getTemplateNameLoc(),
2286 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002287
2288 case TemplateArgument::Null:
2289 case TemplateArgument::Integral:
2290 case TemplateArgument::Declaration:
2291 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002292 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002293 llvm_unreachable("Pack expansion pattern has no parameter packs");
2294
2295 case TemplateArgument::Type:
2296 if (TypeSourceInfo *Expansion
2297 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002298 EllipsisLoc,
2299 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002300 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2301 Expansion);
2302 break;
2303 }
2304
2305 return TemplateArgumentLoc();
2306 }
2307
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002308 /// \brief Build a new expression pack expansion.
2309 ///
2310 /// By default, performs semantic analysis to build a new pack expansion
2311 /// for an expression. Subclasses may override this routine to provide
2312 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002313 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2314 llvm::Optional<unsigned> NumExpansions) {
2315 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002316 }
2317
John McCall43fed0d2010-11-12 08:19:04 +00002318private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002319 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2320 QualType ObjectType,
2321 NamedDecl *FirstQualifierInScope,
2322 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002323
2324 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2325 QualType ObjectType,
2326 NamedDecl *FirstQualifierInScope,
2327 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002328};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002329
Douglas Gregor43959a92009-08-20 07:17:43 +00002330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002331StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002332 if (!S)
2333 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002334
Douglas Gregor43959a92009-08-20 07:17:43 +00002335 switch (S->getStmtClass()) {
2336 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002337
Douglas Gregor43959a92009-08-20 07:17:43 +00002338 // Transform individual statement nodes
2339#define STMT(Node, Parent) \
2340 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002341#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002342#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002343#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002344
Douglas Gregor43959a92009-08-20 07:17:43 +00002345 // Transform expressions by calling TransformExpr.
2346#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002347#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002348#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002349#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002350 {
John McCall60d7b3a2010-08-24 06:29:42 +00002351 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002352 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002353 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002354
John McCall9ae2f072010-08-23 23:25:46 +00002355 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002356 }
Mike Stump1eb44332009-09-09 15:08:12 +00002357 }
2358
John McCall3fa5cae2010-10-26 07:05:15 +00002359 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002360}
Mike Stump1eb44332009-09-09 15:08:12 +00002361
2362
Douglas Gregor670444e2009-08-04 22:27:00 +00002363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002364ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002365 if (!E)
2366 return SemaRef.Owned(E);
2367
2368 switch (E->getStmtClass()) {
2369 case Stmt::NoStmtClass: break;
2370#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002371#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002372#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002373 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002374#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002375 }
2376
John McCall3fa5cae2010-10-26 07:05:15 +00002377 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002378}
2379
2380template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002381bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2382 unsigned NumInputs,
2383 bool IsCall,
2384 llvm::SmallVectorImpl<Expr *> &Outputs,
2385 bool *ArgChanged) {
2386 for (unsigned I = 0; I != NumInputs; ++I) {
2387 // If requested, drop call arguments that need to be dropped.
2388 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2389 if (ArgChanged)
2390 *ArgChanged = true;
2391
2392 break;
2393 }
2394
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002395 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2396 Expr *Pattern = Expansion->getPattern();
2397
2398 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2399 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2400 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2401
2402 // Determine whether the set of unexpanded parameter packs can and should
2403 // be expanded.
2404 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002405 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002406 llvm::Optional<unsigned> OrigNumExpansions
2407 = Expansion->getNumExpansions();
2408 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002409 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2410 Pattern->getSourceRange(),
2411 Unexpanded.data(),
2412 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002413 Expand, RetainExpansion,
2414 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002415 return true;
2416
2417 if (!Expand) {
2418 // The transform has determined that we should perform a simple
2419 // transformation on the pack expansion, producing another pack
2420 // expansion.
2421 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2422 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2423 if (OutPattern.isInvalid())
2424 return true;
2425
2426 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002427 Expansion->getEllipsisLoc(),
2428 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002429 if (Out.isInvalid())
2430 return true;
2431
2432 if (ArgChanged)
2433 *ArgChanged = true;
2434 Outputs.push_back(Out.get());
2435 continue;
2436 }
2437
2438 // The transform has determined that we should perform an elementwise
2439 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002440 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002441 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2442 ExprResult Out = getDerived().TransformExpr(Pattern);
2443 if (Out.isInvalid())
2444 return true;
2445
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002446 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002447 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2448 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002449 if (Out.isInvalid())
2450 return true;
2451 }
2452
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002453 if (ArgChanged)
2454 *ArgChanged = true;
2455 Outputs.push_back(Out.get());
2456 }
2457
2458 continue;
2459 }
2460
Douglas Gregoraa165f82011-01-03 19:04:46 +00002461 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2462 if (Result.isInvalid())
2463 return true;
2464
2465 if (Result.get() != Inputs[I] && ArgChanged)
2466 *ArgChanged = true;
2467
2468 Outputs.push_back(Result.get());
2469 }
2470
2471 return false;
2472}
2473
2474template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002475NestedNameSpecifierLoc
2476TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2477 NestedNameSpecifierLoc NNS,
2478 QualType ObjectType,
2479 NamedDecl *FirstQualifierInScope) {
2480 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2481 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2482 Qualifier = Qualifier.getPrefix())
2483 Qualifiers.push_back(Qualifier);
2484
2485 CXXScopeSpec SS;
2486 while (!Qualifiers.empty()) {
2487 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2488 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2489
2490 switch (QNNS->getKind()) {
2491 case NestedNameSpecifier::Identifier:
2492 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2493 *QNNS->getAsIdentifier(),
2494 Q.getLocalBeginLoc(),
2495 Q.getLocalEndLoc(),
2496 ObjectType, false, SS,
2497 FirstQualifierInScope, false))
2498 return NestedNameSpecifierLoc();
2499
2500 break;
2501
2502 case NestedNameSpecifier::Namespace: {
2503 NamespaceDecl *NS
2504 = cast_or_null<NamespaceDecl>(
2505 getDerived().TransformDecl(
2506 Q.getLocalBeginLoc(),
2507 QNNS->getAsNamespace()));
2508 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2509 break;
2510 }
2511
2512 case NestedNameSpecifier::NamespaceAlias: {
2513 NamespaceAliasDecl *Alias
2514 = cast_or_null<NamespaceAliasDecl>(
2515 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2516 QNNS->getAsNamespaceAlias()));
2517 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2518 Q.getLocalEndLoc());
2519 break;
2520 }
2521
2522 case NestedNameSpecifier::Global:
2523 // There is no meaningful transformation that one could perform on the
2524 // global scope.
2525 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2526 break;
2527
2528 case NestedNameSpecifier::TypeSpecWithTemplate:
2529 case NestedNameSpecifier::TypeSpec: {
2530 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2531 FirstQualifierInScope, SS);
2532
2533 if (!TL)
2534 return NestedNameSpecifierLoc();
2535
2536 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2537 (SemaRef.getLangOptions().CPlusPlus0x &&
2538 TL.getType()->isEnumeralType())) {
2539 assert(!TL.getType().hasLocalQualifiers() &&
2540 "Can't get cv-qualifiers here");
2541 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2542 Q.getLocalEndLoc());
2543 break;
2544 }
2545
2546 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2547 << TL.getType() << SS.getRange();
2548 return NestedNameSpecifierLoc();
2549 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002550 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002551
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002552 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002553 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002554 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002555 }
2556
2557 // Don't rebuild the nested-name-specifier if we don't have to.
2558 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2559 !getDerived().AlwaysRebuild())
2560 return NNS;
2561
2562 // If we can re-use the source-location data from the original
2563 // nested-name-specifier, do so.
2564 if (SS.location_size() == NNS.getDataLength() &&
2565 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2566 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2567
2568 // Allocate new nested-name-specifier location information.
2569 return SS.getWithLocInContext(SemaRef.Context);
2570}
2571
2572template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002573DeclarationNameInfo
2574TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002575::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002576 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002577 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002578 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002579
2580 switch (Name.getNameKind()) {
2581 case DeclarationName::Identifier:
2582 case DeclarationName::ObjCZeroArgSelector:
2583 case DeclarationName::ObjCOneArgSelector:
2584 case DeclarationName::ObjCMultiArgSelector:
2585 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002586 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002587 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002588 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002589
Douglas Gregor81499bb2009-09-03 22:13:48 +00002590 case DeclarationName::CXXConstructorName:
2591 case DeclarationName::CXXDestructorName:
2592 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002593 TypeSourceInfo *NewTInfo;
2594 CanQualType NewCanTy;
2595 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002596 NewTInfo = getDerived().TransformType(OldTInfo);
2597 if (!NewTInfo)
2598 return DeclarationNameInfo();
2599 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002600 }
2601 else {
2602 NewTInfo = 0;
2603 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002604 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002605 if (NewT.isNull())
2606 return DeclarationNameInfo();
2607 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2608 }
Mike Stump1eb44332009-09-09 15:08:12 +00002609
Abramo Bagnara25777432010-08-11 22:01:17 +00002610 DeclarationName NewName
2611 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2612 NewCanTy);
2613 DeclarationNameInfo NewNameInfo(NameInfo);
2614 NewNameInfo.setName(NewName);
2615 NewNameInfo.setNamedTypeInfo(NewTInfo);
2616 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002617 }
Mike Stump1eb44332009-09-09 15:08:12 +00002618 }
2619
Abramo Bagnara25777432010-08-11 22:01:17 +00002620 assert(0 && "Unknown name kind.");
2621 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002622}
2623
2624template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002625TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002626TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2627 TemplateName Name,
2628 SourceLocation NameLoc,
2629 QualType ObjectType,
2630 NamedDecl *FirstQualifierInScope) {
2631 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2632 TemplateDecl *Template = QTN->getTemplateDecl();
2633 assert(Template && "qualified template name must refer to a template");
2634
2635 TemplateDecl *TransTemplate
2636 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2637 Template));
2638 if (!TransTemplate)
2639 return TemplateName();
2640
2641 if (!getDerived().AlwaysRebuild() &&
2642 SS.getScopeRep() == QTN->getQualifier() &&
2643 TransTemplate == Template)
2644 return Name;
2645
2646 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2647 TransTemplate);
2648 }
2649
2650 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2651 if (SS.getScopeRep()) {
2652 // These apply to the scope specifier, not the template.
2653 ObjectType = QualType();
2654 FirstQualifierInScope = 0;
2655 }
2656
2657 if (!getDerived().AlwaysRebuild() &&
2658 SS.getScopeRep() == DTN->getQualifier() &&
2659 ObjectType.isNull())
2660 return Name;
2661
2662 if (DTN->isIdentifier()) {
2663 return getDerived().RebuildTemplateName(SS,
2664 *DTN->getIdentifier(),
2665 NameLoc,
2666 ObjectType,
2667 FirstQualifierInScope);
2668 }
2669
2670 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2671 ObjectType);
2672 }
2673
2674 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2675 TemplateDecl *TransTemplate
2676 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2677 Template));
2678 if (!TransTemplate)
2679 return TemplateName();
2680
2681 if (!getDerived().AlwaysRebuild() &&
2682 TransTemplate == Template)
2683 return Name;
2684
2685 return TemplateName(TransTemplate);
2686 }
2687
2688 if (SubstTemplateTemplateParmPackStorage *SubstPack
2689 = Name.getAsSubstTemplateTemplateParmPack()) {
2690 TemplateTemplateParmDecl *TransParam
2691 = cast_or_null<TemplateTemplateParmDecl>(
2692 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2693 if (!TransParam)
2694 return TemplateName();
2695
2696 if (!getDerived().AlwaysRebuild() &&
2697 TransParam == SubstPack->getParameterPack())
2698 return Name;
2699
2700 return getDerived().RebuildTemplateName(TransParam,
2701 SubstPack->getArgumentPack());
2702 }
2703
2704 // These should be getting filtered out before they reach the AST.
2705 llvm_unreachable("overloaded function decl survived to here");
2706 return TemplateName();
2707}
2708
2709template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002710void TreeTransform<Derived>::InventTemplateArgumentLoc(
2711 const TemplateArgument &Arg,
2712 TemplateArgumentLoc &Output) {
2713 SourceLocation Loc = getDerived().getBaseLocation();
2714 switch (Arg.getKind()) {
2715 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002716 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002717 break;
2718
2719 case TemplateArgument::Type:
2720 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002721 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002722
John McCall833ca992009-10-29 08:12:44 +00002723 break;
2724
Douglas Gregor788cd062009-11-11 01:00:40 +00002725 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002726 case TemplateArgument::TemplateExpansion: {
2727 NestedNameSpecifierLocBuilder Builder;
2728 TemplateName Template = Arg.getAsTemplate();
2729 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2730 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2731 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2732 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2733
2734 if (Arg.getKind() == TemplateArgument::Template)
2735 Output = TemplateArgumentLoc(Arg,
2736 Builder.getWithLocInContext(SemaRef.Context),
2737 Loc);
2738 else
2739 Output = TemplateArgumentLoc(Arg,
2740 Builder.getWithLocInContext(SemaRef.Context),
2741 Loc, Loc);
2742
Douglas Gregor788cd062009-11-11 01:00:40 +00002743 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002744 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002745
John McCall833ca992009-10-29 08:12:44 +00002746 case TemplateArgument::Expression:
2747 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2748 break;
2749
2750 case TemplateArgument::Declaration:
2751 case TemplateArgument::Integral:
2752 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002753 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002754 break;
2755 }
2756}
2757
2758template<typename Derived>
2759bool TreeTransform<Derived>::TransformTemplateArgument(
2760 const TemplateArgumentLoc &Input,
2761 TemplateArgumentLoc &Output) {
2762 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002763 switch (Arg.getKind()) {
2764 case TemplateArgument::Null:
2765 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002766 Output = Input;
2767 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002768
Douglas Gregor670444e2009-08-04 22:27:00 +00002769 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002770 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002771 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002772 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002773
2774 DI = getDerived().TransformType(DI);
2775 if (!DI) return true;
2776
2777 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2778 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002779 }
Mike Stump1eb44332009-09-09 15:08:12 +00002780
Douglas Gregor670444e2009-08-04 22:27:00 +00002781 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002782 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002783 DeclarationName Name;
2784 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2785 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002786 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002787 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002788 if (!D) return true;
2789
John McCall828bff22009-10-29 18:45:58 +00002790 Expr *SourceExpr = Input.getSourceDeclExpression();
2791 if (SourceExpr) {
2792 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002793 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002794 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002795 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002796 }
2797
2798 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002799 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002800 }
Mike Stump1eb44332009-09-09 15:08:12 +00002801
Douglas Gregor788cd062009-11-11 01:00:40 +00002802 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002803 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2804 if (QualifierLoc) {
2805 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2806 if (!QualifierLoc)
2807 return true;
2808 }
2809
Douglas Gregor1d752d72011-03-02 18:46:51 +00002810 CXXScopeSpec SS;
2811 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002812 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002813 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2814 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002815 if (Template.isNull())
2816 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002817
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002818 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002819 Input.getTemplateNameLoc());
2820 return false;
2821 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002822
2823 case TemplateArgument::TemplateExpansion:
2824 llvm_unreachable("Caller should expand pack expansions");
2825
Douglas Gregor670444e2009-08-04 22:27:00 +00002826 case TemplateArgument::Expression: {
2827 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002828 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002829 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002830
John McCall833ca992009-10-29 08:12:44 +00002831 Expr *InputExpr = Input.getSourceExpression();
2832 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2833
Chris Lattner223de242011-04-25 20:37:58 +00002834 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002835 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002836 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002837 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002838 }
Mike Stump1eb44332009-09-09 15:08:12 +00002839
Douglas Gregor670444e2009-08-04 22:27:00 +00002840 case TemplateArgument::Pack: {
2841 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2842 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002843 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002844 AEnd = Arg.pack_end();
2845 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002846
John McCall833ca992009-10-29 08:12:44 +00002847 // FIXME: preserve source information here when we start
2848 // caring about parameter packs.
2849
John McCall828bff22009-10-29 18:45:58 +00002850 TemplateArgumentLoc InputArg;
2851 TemplateArgumentLoc OutputArg;
2852 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2853 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002854 return true;
2855
John McCall828bff22009-10-29 18:45:58 +00002856 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002857 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002858
2859 TemplateArgument *TransformedArgsPtr
2860 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2861 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2862 TransformedArgsPtr);
2863 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2864 TransformedArgs.size()),
2865 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002866 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002867 }
2868 }
Mike Stump1eb44332009-09-09 15:08:12 +00002869
Douglas Gregor670444e2009-08-04 22:27:00 +00002870 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002871 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002872}
2873
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002874/// \brief Iterator adaptor that invents template argument location information
2875/// for each of the template arguments in its underlying iterator.
2876template<typename Derived, typename InputIterator>
2877class TemplateArgumentLocInventIterator {
2878 TreeTransform<Derived> &Self;
2879 InputIterator Iter;
2880
2881public:
2882 typedef TemplateArgumentLoc value_type;
2883 typedef TemplateArgumentLoc reference;
2884 typedef typename std::iterator_traits<InputIterator>::difference_type
2885 difference_type;
2886 typedef std::input_iterator_tag iterator_category;
2887
2888 class pointer {
2889 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002890
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002891 public:
2892 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2893
2894 const TemplateArgumentLoc *operator->() const { return &Arg; }
2895 };
2896
2897 TemplateArgumentLocInventIterator() { }
2898
2899 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2900 InputIterator Iter)
2901 : Self(Self), Iter(Iter) { }
2902
2903 TemplateArgumentLocInventIterator &operator++() {
2904 ++Iter;
2905 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002906 }
2907
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002908 TemplateArgumentLocInventIterator operator++(int) {
2909 TemplateArgumentLocInventIterator Old(*this);
2910 ++(*this);
2911 return Old;
2912 }
2913
2914 reference operator*() const {
2915 TemplateArgumentLoc Result;
2916 Self.InventTemplateArgumentLoc(*Iter, Result);
2917 return Result;
2918 }
2919
2920 pointer operator->() const { return pointer(**this); }
2921
2922 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2923 const TemplateArgumentLocInventIterator &Y) {
2924 return X.Iter == Y.Iter;
2925 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002926
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002927 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2928 const TemplateArgumentLocInventIterator &Y) {
2929 return X.Iter != Y.Iter;
2930 }
2931};
2932
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002933template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002934template<typename InputIterator>
2935bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2936 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002937 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002938 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002939 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002940 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002941
2942 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2943 // Unpack argument packs, which we translate them into separate
2944 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002945 // FIXME: We could do much better if we could guarantee that the
2946 // TemplateArgumentLocInfo for the pack expansion would be usable for
2947 // all of the template arguments in the argument pack.
2948 typedef TemplateArgumentLocInventIterator<Derived,
2949 TemplateArgument::pack_iterator>
2950 PackLocIterator;
2951 if (TransformTemplateArguments(PackLocIterator(*this,
2952 In.getArgument().pack_begin()),
2953 PackLocIterator(*this,
2954 In.getArgument().pack_end()),
2955 Outputs))
2956 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002957
2958 continue;
2959 }
2960
2961 if (In.getArgument().isPackExpansion()) {
2962 // We have a pack expansion, for which we will be substituting into
2963 // the pattern.
2964 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002965 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002966 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00002967 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2968 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002969
2970 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2971 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2972 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2973
2974 // Determine whether the set of unexpanded parameter packs can and should
2975 // be expanded.
2976 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002977 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002978 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002979 if (getDerived().TryExpandParameterPacks(Ellipsis,
2980 Pattern.getSourceRange(),
2981 Unexpanded.data(),
2982 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002983 Expand,
2984 RetainExpansion,
2985 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002986 return true;
2987
2988 if (!Expand) {
2989 // The transform has determined that we should perform a simple
2990 // transformation on the pack expansion, producing another pack
2991 // expansion.
2992 TemplateArgumentLoc OutPattern;
2993 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2994 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2995 return true;
2996
Douglas Gregorcded4f62011-01-14 17:04:44 +00002997 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
2998 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002999 if (Out.getArgument().isNull())
3000 return true;
3001
3002 Outputs.addArgument(Out);
3003 continue;
3004 }
3005
3006 // The transform has determined that we should perform an elementwise
3007 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003008 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003009 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3010
3011 if (getDerived().TransformTemplateArgument(Pattern, Out))
3012 return true;
3013
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003014 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003015 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3016 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003017 if (Out.getArgument().isNull())
3018 return true;
3019 }
3020
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003021 Outputs.addArgument(Out);
3022 }
3023
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003024 // If we're supposed to retain a pack expansion, do so by temporarily
3025 // forgetting the partially-substituted parameter pack.
3026 if (RetainExpansion) {
3027 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3028
3029 if (getDerived().TransformTemplateArgument(Pattern, Out))
3030 return true;
3031
Douglas Gregorcded4f62011-01-14 17:04:44 +00003032 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3033 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003034 if (Out.getArgument().isNull())
3035 return true;
3036
3037 Outputs.addArgument(Out);
3038 }
Douglas Gregord3731192011-01-10 07:32:04 +00003039
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003040 continue;
3041 }
3042
3043 // The simple case:
3044 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003045 return true;
3046
3047 Outputs.addArgument(Out);
3048 }
3049
3050 return false;
3051
3052}
3053
Douglas Gregor577f75a2009-08-04 16:50:30 +00003054//===----------------------------------------------------------------------===//
3055// Type transformation
3056//===----------------------------------------------------------------------===//
3057
3058template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003059QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003060 if (getDerived().AlreadyTransformed(T))
3061 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003062
John McCalla2becad2009-10-21 00:40:46 +00003063 // Temporary workaround. All of these transformations should
3064 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003065 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3066 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003067
John McCall43fed0d2010-11-12 08:19:04 +00003068 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003069
John McCalla2becad2009-10-21 00:40:46 +00003070 if (!NewDI)
3071 return QualType();
3072
3073 return NewDI->getType();
3074}
3075
3076template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003077TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003078 if (getDerived().AlreadyTransformed(DI->getType()))
3079 return DI;
3080
3081 TypeLocBuilder TLB;
3082
3083 TypeLoc TL = DI->getTypeLoc();
3084 TLB.reserve(TL.getFullDataSize());
3085
John McCall43fed0d2010-11-12 08:19:04 +00003086 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003087 if (Result.isNull())
3088 return 0;
3089
John McCalla93c9342009-12-07 02:54:59 +00003090 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003091}
3092
3093template<typename Derived>
3094QualType
John McCall43fed0d2010-11-12 08:19:04 +00003095TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003096 switch (T.getTypeLocClass()) {
3097#define ABSTRACT_TYPELOC(CLASS, PARENT)
3098#define TYPELOC(CLASS, PARENT) \
3099 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003100 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003101#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003102 }
Mike Stump1eb44332009-09-09 15:08:12 +00003103
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003104 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003105 return QualType();
3106}
3107
3108/// FIXME: By default, this routine adds type qualifiers only to types
3109/// that can have qualifiers, and silently suppresses those qualifiers
3110/// that are not permitted (e.g., qualifiers on reference or function
3111/// types). This is the right thing for template instantiation, but
3112/// probably not for other clients.
3113template<typename Derived>
3114QualType
3115TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003116 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003117 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003118
John McCall43fed0d2010-11-12 08:19:04 +00003119 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003120 if (Result.isNull())
3121 return QualType();
3122
3123 // Silently suppress qualifiers if the result type can't be qualified.
3124 // FIXME: this is the right thing for template instantiation, but
3125 // probably not for other clients.
3126 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003127 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003128
John McCall28654742010-06-05 06:41:15 +00003129 if (!Quals.empty()) {
3130 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3131 TLB.push<QualifiedTypeLoc>(Result);
3132 // No location information to preserve.
3133 }
John McCalla2becad2009-10-21 00:40:46 +00003134
3135 return Result;
3136}
3137
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003138template<typename Derived>
3139TypeLoc
3140TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3141 QualType ObjectType,
3142 NamedDecl *UnqualLookup,
3143 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003144 QualType T = TL.getType();
3145 if (getDerived().AlreadyTransformed(T))
3146 return TL;
3147
3148 TypeLocBuilder TLB;
3149 QualType Result;
3150
3151 if (isa<TemplateSpecializationType>(T)) {
3152 TemplateSpecializationTypeLoc SpecTL
3153 = cast<TemplateSpecializationTypeLoc>(TL);
3154
3155 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003156 getDerived().TransformTemplateName(SS,
3157 SpecTL.getTypePtr()->getTemplateName(),
3158 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003159 ObjectType, UnqualLookup);
3160 if (Template.isNull())
3161 return TypeLoc();
3162
3163 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3164 Template);
3165 } else if (isa<DependentTemplateSpecializationType>(T)) {
3166 DependentTemplateSpecializationTypeLoc SpecTL
3167 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3168
Douglas Gregora88f09f2011-02-28 17:23:35 +00003169 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003170 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003171 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003172 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003173 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003174 if (Template.isNull())
3175 return TypeLoc();
3176
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003177 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003178 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003179 Template,
3180 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003181 } else {
3182 // Nothing special needs to be done for these.
3183 Result = getDerived().TransformType(TLB, TL);
3184 }
3185
3186 if (Result.isNull())
3187 return TypeLoc();
3188
3189 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3190}
3191
Douglas Gregorb71d8212011-03-02 18:32:08 +00003192template<typename Derived>
3193TypeSourceInfo *
3194TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3195 QualType ObjectType,
3196 NamedDecl *UnqualLookup,
3197 CXXScopeSpec &SS) {
3198 // FIXME: Painfully copy-paste from the above!
3199
3200 QualType T = TSInfo->getType();
3201 if (getDerived().AlreadyTransformed(T))
3202 return TSInfo;
3203
3204 TypeLocBuilder TLB;
3205 QualType Result;
3206
3207 TypeLoc TL = TSInfo->getTypeLoc();
3208 if (isa<TemplateSpecializationType>(T)) {
3209 TemplateSpecializationTypeLoc SpecTL
3210 = cast<TemplateSpecializationTypeLoc>(TL);
3211
3212 TemplateName Template
3213 = getDerived().TransformTemplateName(SS,
3214 SpecTL.getTypePtr()->getTemplateName(),
3215 SpecTL.getTemplateNameLoc(),
3216 ObjectType, UnqualLookup);
3217 if (Template.isNull())
3218 return 0;
3219
3220 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3221 Template);
3222 } else if (isa<DependentTemplateSpecializationType>(T)) {
3223 DependentTemplateSpecializationTypeLoc SpecTL
3224 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3225
3226 TemplateName Template
3227 = getDerived().RebuildTemplateName(SS,
3228 *SpecTL.getTypePtr()->getIdentifier(),
3229 SpecTL.getNameLoc(),
3230 ObjectType, UnqualLookup);
3231 if (Template.isNull())
3232 return 0;
3233
3234 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3235 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003236 Template,
3237 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003238 } else {
3239 // Nothing special needs to be done for these.
3240 Result = getDerived().TransformType(TLB, TL);
3241 }
3242
3243 if (Result.isNull())
3244 return 0;
3245
3246 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3247}
3248
John McCalla2becad2009-10-21 00:40:46 +00003249template <class TyLoc> static inline
3250QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3251 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3252 NewT.setNameLoc(T.getNameLoc());
3253 return T.getType();
3254}
3255
John McCalla2becad2009-10-21 00:40:46 +00003256template<typename Derived>
3257QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003258 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003259 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3260 NewT.setBuiltinLoc(T.getBuiltinLoc());
3261 if (T.needsExtraLocalData())
3262 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3263 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003264}
Mike Stump1eb44332009-09-09 15:08:12 +00003265
Douglas Gregor577f75a2009-08-04 16:50:30 +00003266template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003267QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003268 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003269 // FIXME: recurse?
3270 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003271}
Mike Stump1eb44332009-09-09 15:08:12 +00003272
Douglas Gregor577f75a2009-08-04 16:50:30 +00003273template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003274QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003275 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003276 QualType PointeeType
3277 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003278 if (PointeeType.isNull())
3279 return QualType();
3280
3281 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003282 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003283 // A dependent pointer type 'T *' has is being transformed such
3284 // that an Objective-C class type is being replaced for 'T'. The
3285 // resulting pointer type is an ObjCObjectPointerType, not a
3286 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003287 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003288
John McCallc12c5bb2010-05-15 11:32:37 +00003289 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3290 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003291 return Result;
3292 }
John McCall43fed0d2010-11-12 08:19:04 +00003293
Douglas Gregor92e986e2010-04-22 16:44:27 +00003294 if (getDerived().AlwaysRebuild() ||
3295 PointeeType != TL.getPointeeLoc().getType()) {
3296 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3297 if (Result.isNull())
3298 return QualType();
3299 }
Sean Huntc3021132010-05-05 15:23:54 +00003300
Douglas Gregor92e986e2010-04-22 16:44:27 +00003301 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3302 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003303 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003304}
Mike Stump1eb44332009-09-09 15:08:12 +00003305
3306template<typename Derived>
3307QualType
John McCalla2becad2009-10-21 00:40:46 +00003308TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003309 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003310 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003311 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3312 if (PointeeType.isNull())
3313 return QualType();
3314
3315 QualType Result = TL.getType();
3316 if (getDerived().AlwaysRebuild() ||
3317 PointeeType != TL.getPointeeLoc().getType()) {
3318 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003319 TL.getSigilLoc());
3320 if (Result.isNull())
3321 return QualType();
3322 }
3323
Douglas Gregor39968ad2010-04-22 16:50:51 +00003324 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003325 NewT.setSigilLoc(TL.getSigilLoc());
3326 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003327}
3328
John McCall85737a72009-10-30 00:06:24 +00003329/// Transforms a reference type. Note that somewhat paradoxically we
3330/// don't care whether the type itself is an l-value type or an r-value
3331/// type; we only care if the type was *written* as an l-value type
3332/// or an r-value type.
3333template<typename Derived>
3334QualType
3335TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003336 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003337 const ReferenceType *T = TL.getTypePtr();
3338
3339 // Note that this works with the pointee-as-written.
3340 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3341 if (PointeeType.isNull())
3342 return QualType();
3343
3344 QualType Result = TL.getType();
3345 if (getDerived().AlwaysRebuild() ||
3346 PointeeType != T->getPointeeTypeAsWritten()) {
3347 Result = getDerived().RebuildReferenceType(PointeeType,
3348 T->isSpelledAsLValue(),
3349 TL.getSigilLoc());
3350 if (Result.isNull())
3351 return QualType();
3352 }
3353
3354 // r-value references can be rebuilt as l-value references.
3355 ReferenceTypeLoc NewTL;
3356 if (isa<LValueReferenceType>(Result))
3357 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3358 else
3359 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3360 NewTL.setSigilLoc(TL.getSigilLoc());
3361
3362 return Result;
3363}
3364
Mike Stump1eb44332009-09-09 15:08:12 +00003365template<typename Derived>
3366QualType
John McCalla2becad2009-10-21 00:40:46 +00003367TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003368 LValueReferenceTypeLoc TL) {
3369 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003370}
3371
Mike Stump1eb44332009-09-09 15:08:12 +00003372template<typename Derived>
3373QualType
John McCalla2becad2009-10-21 00:40:46 +00003374TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003375 RValueReferenceTypeLoc TL) {
3376 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003377}
Mike Stump1eb44332009-09-09 15:08:12 +00003378
Douglas Gregor577f75a2009-08-04 16:50:30 +00003379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003380QualType
John McCalla2becad2009-10-21 00:40:46 +00003381TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003382 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003383 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003384 if (PointeeType.isNull())
3385 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003386
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003387 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3388 TypeSourceInfo* NewClsTInfo = 0;
3389 if (OldClsTInfo) {
3390 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3391 if (!NewClsTInfo)
3392 return QualType();
3393 }
3394
3395 const MemberPointerType *T = TL.getTypePtr();
3396 QualType OldClsType = QualType(T->getClass(), 0);
3397 QualType NewClsType;
3398 if (NewClsTInfo)
3399 NewClsType = NewClsTInfo->getType();
3400 else {
3401 NewClsType = getDerived().TransformType(OldClsType);
3402 if (NewClsType.isNull())
3403 return QualType();
3404 }
Mike Stump1eb44332009-09-09 15:08:12 +00003405
John McCalla2becad2009-10-21 00:40:46 +00003406 QualType Result = TL.getType();
3407 if (getDerived().AlwaysRebuild() ||
3408 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003409 NewClsType != OldClsType) {
3410 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003411 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003412 if (Result.isNull())
3413 return QualType();
3414 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415
John McCalla2becad2009-10-21 00:40:46 +00003416 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3417 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003418 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003419
3420 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003421}
3422
Mike Stump1eb44332009-09-09 15:08:12 +00003423template<typename Derived>
3424QualType
John McCalla2becad2009-10-21 00:40:46 +00003425TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003426 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003427 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003428 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003429 if (ElementType.isNull())
3430 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003431
John McCalla2becad2009-10-21 00:40:46 +00003432 QualType Result = TL.getType();
3433 if (getDerived().AlwaysRebuild() ||
3434 ElementType != T->getElementType()) {
3435 Result = getDerived().RebuildConstantArrayType(ElementType,
3436 T->getSizeModifier(),
3437 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003438 T->getIndexTypeCVRQualifiers(),
3439 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003440 if (Result.isNull())
3441 return QualType();
3442 }
Sean Huntc3021132010-05-05 15:23:54 +00003443
John McCalla2becad2009-10-21 00:40:46 +00003444 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3445 NewTL.setLBracketLoc(TL.getLBracketLoc());
3446 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003447
John McCalla2becad2009-10-21 00:40:46 +00003448 Expr *Size = TL.getSizeExpr();
3449 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003450 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003451 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3452 }
3453 NewTL.setSizeExpr(Size);
3454
3455 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003456}
Mike Stump1eb44332009-09-09 15:08:12 +00003457
Douglas Gregor577f75a2009-08-04 16:50:30 +00003458template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003459QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003460 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003461 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003462 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003463 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464 if (ElementType.isNull())
3465 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003466
John McCalla2becad2009-10-21 00:40:46 +00003467 QualType Result = TL.getType();
3468 if (getDerived().AlwaysRebuild() ||
3469 ElementType != T->getElementType()) {
3470 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003471 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003472 T->getIndexTypeCVRQualifiers(),
3473 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003474 if (Result.isNull())
3475 return QualType();
3476 }
Sean Huntc3021132010-05-05 15:23:54 +00003477
John McCalla2becad2009-10-21 00:40:46 +00003478 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3479 NewTL.setLBracketLoc(TL.getLBracketLoc());
3480 NewTL.setRBracketLoc(TL.getRBracketLoc());
3481 NewTL.setSizeExpr(0);
3482
3483 return Result;
3484}
3485
3486template<typename Derived>
3487QualType
3488TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003489 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003490 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003491 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3492 if (ElementType.isNull())
3493 return QualType();
3494
3495 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003496 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003497
John McCall60d7b3a2010-08-24 06:29:42 +00003498 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003499 = getDerived().TransformExpr(T->getSizeExpr());
3500 if (SizeResult.isInvalid())
3501 return QualType();
3502
John McCall9ae2f072010-08-23 23:25:46 +00003503 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003504
3505 QualType Result = TL.getType();
3506 if (getDerived().AlwaysRebuild() ||
3507 ElementType != T->getElementType() ||
3508 Size != T->getSizeExpr()) {
3509 Result = getDerived().RebuildVariableArrayType(ElementType,
3510 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003511 Size,
John McCalla2becad2009-10-21 00:40:46 +00003512 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003513 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003514 if (Result.isNull())
3515 return QualType();
3516 }
Sean Huntc3021132010-05-05 15:23:54 +00003517
John McCalla2becad2009-10-21 00:40:46 +00003518 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3519 NewTL.setLBracketLoc(TL.getLBracketLoc());
3520 NewTL.setRBracketLoc(TL.getRBracketLoc());
3521 NewTL.setSizeExpr(Size);
3522
3523 return Result;
3524}
3525
3526template<typename Derived>
3527QualType
3528TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003529 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003530 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003531 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3532 if (ElementType.isNull())
3533 return QualType();
3534
3535 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003536 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003537
John McCall3b657512011-01-19 10:06:00 +00003538 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3539 Expr *origSize = TL.getSizeExpr();
3540 if (!origSize) origSize = T->getSizeExpr();
3541
3542 ExprResult sizeResult
3543 = getDerived().TransformExpr(origSize);
3544 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003545 return QualType();
3546
John McCall3b657512011-01-19 10:06:00 +00003547 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003548
3549 QualType Result = TL.getType();
3550 if (getDerived().AlwaysRebuild() ||
3551 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003552 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003553 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3554 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003555 size,
John McCalla2becad2009-10-21 00:40:46 +00003556 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003557 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003558 if (Result.isNull())
3559 return QualType();
3560 }
John McCalla2becad2009-10-21 00:40:46 +00003561
3562 // We might have any sort of array type now, but fortunately they
3563 // all have the same location layout.
3564 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3565 NewTL.setLBracketLoc(TL.getLBracketLoc());
3566 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003567 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003568
3569 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003570}
Mike Stump1eb44332009-09-09 15:08:12 +00003571
3572template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003573QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003574 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003575 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003576 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003577
3578 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003579 QualType ElementType = getDerived().TransformType(T->getElementType());
3580 if (ElementType.isNull())
3581 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003582
Douglas Gregor670444e2009-08-04 22:27:00 +00003583 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003584 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003585
John McCall60d7b3a2010-08-24 06:29:42 +00003586 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003587 if (Size.isInvalid())
3588 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003589
John McCalla2becad2009-10-21 00:40:46 +00003590 QualType Result = TL.getType();
3591 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003592 ElementType != T->getElementType() ||
3593 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003594 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003595 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003596 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003597 if (Result.isNull())
3598 return QualType();
3599 }
John McCalla2becad2009-10-21 00:40:46 +00003600
3601 // Result might be dependent or not.
3602 if (isa<DependentSizedExtVectorType>(Result)) {
3603 DependentSizedExtVectorTypeLoc NewTL
3604 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3605 NewTL.setNameLoc(TL.getNameLoc());
3606 } else {
3607 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3608 NewTL.setNameLoc(TL.getNameLoc());
3609 }
3610
3611 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003612}
Mike Stump1eb44332009-09-09 15:08:12 +00003613
3614template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003615QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003616 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003617 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003618 QualType ElementType = getDerived().TransformType(T->getElementType());
3619 if (ElementType.isNull())
3620 return QualType();
3621
John McCalla2becad2009-10-21 00:40:46 +00003622 QualType Result = TL.getType();
3623 if (getDerived().AlwaysRebuild() ||
3624 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003625 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003626 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003627 if (Result.isNull())
3628 return QualType();
3629 }
Sean Huntc3021132010-05-05 15:23:54 +00003630
John McCalla2becad2009-10-21 00:40:46 +00003631 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3632 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003633
John McCalla2becad2009-10-21 00:40:46 +00003634 return Result;
3635}
3636
3637template<typename Derived>
3638QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003639 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003640 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003641 QualType ElementType = getDerived().TransformType(T->getElementType());
3642 if (ElementType.isNull())
3643 return QualType();
3644
3645 QualType Result = TL.getType();
3646 if (getDerived().AlwaysRebuild() ||
3647 ElementType != T->getElementType()) {
3648 Result = getDerived().RebuildExtVectorType(ElementType,
3649 T->getNumElements(),
3650 /*FIXME*/ SourceLocation());
3651 if (Result.isNull())
3652 return QualType();
3653 }
Sean Huntc3021132010-05-05 15:23:54 +00003654
John McCalla2becad2009-10-21 00:40:46 +00003655 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3656 NewTL.setNameLoc(TL.getNameLoc());
3657
3658 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003659}
Mike Stump1eb44332009-09-09 15:08:12 +00003660
3661template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003662ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003663TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3664 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003665 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003666 TypeSourceInfo *NewDI = 0;
3667
3668 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3669 // If we're substituting into a pack expansion type and we know the
3670 TypeLoc OldTL = OldDI->getTypeLoc();
3671 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3672
3673 TypeLocBuilder TLB;
3674 TypeLoc NewTL = OldDI->getTypeLoc();
3675 TLB.reserve(NewTL.getFullDataSize());
3676
3677 QualType Result = getDerived().TransformType(TLB,
3678 OldExpansionTL.getPatternLoc());
3679 if (Result.isNull())
3680 return 0;
3681
3682 Result = RebuildPackExpansionType(Result,
3683 OldExpansionTL.getPatternLoc().getSourceRange(),
3684 OldExpansionTL.getEllipsisLoc(),
3685 NumExpansions);
3686 if (Result.isNull())
3687 return 0;
3688
3689 PackExpansionTypeLoc NewExpansionTL
3690 = TLB.push<PackExpansionTypeLoc>(Result);
3691 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3692 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3693 } else
3694 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003695 if (!NewDI)
3696 return 0;
3697
3698 if (NewDI == OldDI)
3699 return OldParm;
3700 else
3701 return ParmVarDecl::Create(SemaRef.Context,
3702 OldParm->getDeclContext(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00003703 OldParm->getInnerLocStart(),
John McCall21ef0fa2010-03-11 09:03:00 +00003704 OldParm->getLocation(),
3705 OldParm->getIdentifier(),
3706 NewDI->getType(),
3707 NewDI,
3708 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003709 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003710 /* DefArg */ NULL);
3711}
3712
3713template<typename Derived>
3714bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003715 TransformFunctionTypeParams(SourceLocation Loc,
3716 ParmVarDecl **Params, unsigned NumParams,
3717 const QualType *ParamTypes,
3718 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3719 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3720 for (unsigned i = 0; i != NumParams; ++i) {
3721 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003722 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003723 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003724 if (OldParm->isParameterPack()) {
3725 // We have a function parameter pack that may need to be expanded.
3726 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003727
Douglas Gregor603cfb42011-01-05 23:12:31 +00003728 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003729 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3730 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3731 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3732 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003733 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3734
Douglas Gregor603cfb42011-01-05 23:12:31 +00003735 // Determine whether we should expand the parameter packs.
3736 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003737 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003738 llvm::Optional<unsigned> OrigNumExpansions
3739 = ExpansionTL.getTypePtr()->getNumExpansions();
3740 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003741 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3742 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003743 Unexpanded.data(),
3744 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003745 ShouldExpand,
3746 RetainExpansion,
3747 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003748 return true;
3749 }
3750
3751 if (ShouldExpand) {
3752 // Expand the function parameter pack into multiple, separate
3753 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003754 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003755 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003756 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3757 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003758 = getDerived().TransformFunctionTypeParam(OldParm,
3759 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003760 if (!NewParm)
3761 return true;
3762
Douglas Gregora009b592011-01-07 00:20:55 +00003763 OutParamTypes.push_back(NewParm->getType());
3764 if (PVars)
3765 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003766 }
Douglas Gregord3731192011-01-10 07:32:04 +00003767
3768 // If we're supposed to retain a pack expansion, do so by temporarily
3769 // forgetting the partially-substituted parameter pack.
3770 if (RetainExpansion) {
3771 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3772 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003773 = getDerived().TransformFunctionTypeParam(OldParm,
3774 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003775 if (!NewParm)
3776 return true;
3777
3778 OutParamTypes.push_back(NewParm->getType());
3779 if (PVars)
3780 PVars->push_back(NewParm);
3781 }
3782
Douglas Gregor603cfb42011-01-05 23:12:31 +00003783 // We're done with the pack expansion.
3784 continue;
3785 }
3786
3787 // We'll substitute the parameter now without expanding the pack
3788 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003789 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3790 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3791 NumExpansions);
3792 } else {
3793 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3794 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003795 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003796
John McCall21ef0fa2010-03-11 09:03:00 +00003797 if (!NewParm)
3798 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003799
Douglas Gregora009b592011-01-07 00:20:55 +00003800 OutParamTypes.push_back(NewParm->getType());
3801 if (PVars)
3802 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003803 continue;
3804 }
John McCall21ef0fa2010-03-11 09:03:00 +00003805
3806 // Deal with the possibility that we don't have a parameter
3807 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003808 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003809 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003810 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003811 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003812 if (const PackExpansionType *Expansion
3813 = dyn_cast<PackExpansionType>(OldType)) {
3814 // We have a function parameter pack that may need to be expanded.
3815 QualType Pattern = Expansion->getPattern();
3816 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3817 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3818
3819 // Determine whether we should expand the parameter packs.
3820 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003821 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003822 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003823 Unexpanded.data(),
3824 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003825 ShouldExpand,
3826 RetainExpansion,
3827 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003828 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003829 }
3830
3831 if (ShouldExpand) {
3832 // Expand the function parameter pack into multiple, separate
3833 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003834 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003835 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3836 QualType NewType = getDerived().TransformType(Pattern);
3837 if (NewType.isNull())
3838 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003839
Douglas Gregora009b592011-01-07 00:20:55 +00003840 OutParamTypes.push_back(NewType);
3841 if (PVars)
3842 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003843 }
3844
3845 // We're done with the pack expansion.
3846 continue;
3847 }
3848
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003849 // If we're supposed to retain a pack expansion, do so by temporarily
3850 // forgetting the partially-substituted parameter pack.
3851 if (RetainExpansion) {
3852 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3853 QualType NewType = getDerived().TransformType(Pattern);
3854 if (NewType.isNull())
3855 return true;
3856
3857 OutParamTypes.push_back(NewType);
3858 if (PVars)
3859 PVars->push_back(0);
3860 }
Douglas Gregord3731192011-01-10 07:32:04 +00003861
Douglas Gregor603cfb42011-01-05 23:12:31 +00003862 // We'll substitute the parameter now without expanding the pack
3863 // expansion.
3864 OldType = Expansion->getPattern();
3865 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003866 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3867 NewType = getDerived().TransformType(OldType);
3868 } else {
3869 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003870 }
3871
Douglas Gregor603cfb42011-01-05 23:12:31 +00003872 if (NewType.isNull())
3873 return true;
3874
3875 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003876 NewType = getSema().Context.getPackExpansionType(NewType,
3877 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003878
Douglas Gregora009b592011-01-07 00:20:55 +00003879 OutParamTypes.push_back(NewType);
3880 if (PVars)
3881 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003882 }
3883
3884 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003885 }
John McCall21ef0fa2010-03-11 09:03:00 +00003886
3887template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003888QualType
John McCalla2becad2009-10-21 00:40:46 +00003889TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003890 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003891 // Transform the parameters and return type.
3892 //
3893 // We instantiate in source order, with the return type first followed by
3894 // the parameters, because users tend to expect this (even if they shouldn't
3895 // rely on it!).
3896 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003897 // When the function has a trailing return type, we instantiate the
3898 // parameters before the return type, since the return type can then refer
3899 // to the parameters themselves (via decltype, sizeof, etc.).
3900 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003901 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003902 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003903 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003904
Douglas Gregordab60ad2010-10-01 18:44:50 +00003905 QualType ResultType;
3906
3907 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003908 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3909 TL.getParmArray(),
3910 TL.getNumArgs(),
3911 TL.getTypePtr()->arg_type_begin(),
3912 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003913 return QualType();
3914
3915 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3916 if (ResultType.isNull())
3917 return QualType();
3918 }
3919 else {
3920 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3921 if (ResultType.isNull())
3922 return QualType();
3923
Douglas Gregora009b592011-01-07 00:20:55 +00003924 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3925 TL.getParmArray(),
3926 TL.getNumArgs(),
3927 TL.getTypePtr()->arg_type_begin(),
3928 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003929 return QualType();
3930 }
3931
John McCalla2becad2009-10-21 00:40:46 +00003932 QualType Result = TL.getType();
3933 if (getDerived().AlwaysRebuild() ||
3934 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003935 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003936 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3937 Result = getDerived().RebuildFunctionProtoType(ResultType,
3938 ParamTypes.data(),
3939 ParamTypes.size(),
3940 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003941 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00003942 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003943 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003944 if (Result.isNull())
3945 return QualType();
3946 }
Mike Stump1eb44332009-09-09 15:08:12 +00003947
John McCalla2becad2009-10-21 00:40:46 +00003948 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00003949 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3950 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003951 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003952 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3953 NewTL.setArg(i, ParamDecls[i]);
3954
3955 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003956}
Mike Stump1eb44332009-09-09 15:08:12 +00003957
Douglas Gregor577f75a2009-08-04 16:50:30 +00003958template<typename Derived>
3959QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003960 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003961 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003962 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003963 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3964 if (ResultType.isNull())
3965 return QualType();
3966
3967 QualType Result = TL.getType();
3968 if (getDerived().AlwaysRebuild() ||
3969 ResultType != T->getResultType())
3970 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3971
3972 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00003973 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3974 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003975 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003976
3977 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003978}
Mike Stump1eb44332009-09-09 15:08:12 +00003979
John McCalled976492009-12-04 22:46:56 +00003980template<typename Derived> QualType
3981TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003982 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003983 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003984 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003985 if (!D)
3986 return QualType();
3987
3988 QualType Result = TL.getType();
3989 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3990 Result = getDerived().RebuildUnresolvedUsingType(D);
3991 if (Result.isNull())
3992 return QualType();
3993 }
3994
3995 // We might get an arbitrary type spec type back. We should at
3996 // least always get a type spec type, though.
3997 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3998 NewTL.setNameLoc(TL.getNameLoc());
3999
4000 return Result;
4001}
4002
Douglas Gregor577f75a2009-08-04 16:50:30 +00004003template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004004QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004005 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004006 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004007 TypedefNameDecl *Typedef
4008 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4009 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004010 if (!Typedef)
4011 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004012
John McCalla2becad2009-10-21 00:40:46 +00004013 QualType Result = TL.getType();
4014 if (getDerived().AlwaysRebuild() ||
4015 Typedef != T->getDecl()) {
4016 Result = getDerived().RebuildTypedefType(Typedef);
4017 if (Result.isNull())
4018 return QualType();
4019 }
Mike Stump1eb44332009-09-09 15:08:12 +00004020
John McCalla2becad2009-10-21 00:40:46 +00004021 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4022 NewTL.setNameLoc(TL.getNameLoc());
4023
4024 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004025}
Mike Stump1eb44332009-09-09 15:08:12 +00004026
Douglas Gregor577f75a2009-08-04 16:50:30 +00004027template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004028QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004029 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004030 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004031 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004032
John McCall60d7b3a2010-08-24 06:29:42 +00004033 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004034 if (E.isInvalid())
4035 return QualType();
4036
John McCalla2becad2009-10-21 00:40:46 +00004037 QualType Result = TL.getType();
4038 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004039 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004040 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004041 if (Result.isNull())
4042 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004043 }
John McCalla2becad2009-10-21 00:40:46 +00004044 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004045
John McCalla2becad2009-10-21 00:40:46 +00004046 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004047 NewTL.setTypeofLoc(TL.getTypeofLoc());
4048 NewTL.setLParenLoc(TL.getLParenLoc());
4049 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004050
4051 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004052}
Mike Stump1eb44332009-09-09 15:08:12 +00004053
4054template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004055QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004056 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004057 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4058 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4059 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004060 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004061
John McCalla2becad2009-10-21 00:40:46 +00004062 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004063 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4064 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004065 if (Result.isNull())
4066 return QualType();
4067 }
Mike Stump1eb44332009-09-09 15:08:12 +00004068
John McCalla2becad2009-10-21 00:40:46 +00004069 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004070 NewTL.setTypeofLoc(TL.getTypeofLoc());
4071 NewTL.setLParenLoc(TL.getLParenLoc());
4072 NewTL.setRParenLoc(TL.getRParenLoc());
4073 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004074
4075 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004076}
Mike Stump1eb44332009-09-09 15:08:12 +00004077
4078template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004079QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004080 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004081 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004082
Douglas Gregor670444e2009-08-04 22:27:00 +00004083 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004084 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004085
John McCall60d7b3a2010-08-24 06:29:42 +00004086 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004087 if (E.isInvalid())
4088 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004089
John McCalla2becad2009-10-21 00:40:46 +00004090 QualType Result = TL.getType();
4091 if (getDerived().AlwaysRebuild() ||
4092 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004093 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004094 if (Result.isNull())
4095 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004096 }
John McCalla2becad2009-10-21 00:40:46 +00004097 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004098
John McCalla2becad2009-10-21 00:40:46 +00004099 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4100 NewTL.setNameLoc(TL.getNameLoc());
4101
4102 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004103}
4104
4105template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004106QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4107 AutoTypeLoc TL) {
4108 const AutoType *T = TL.getTypePtr();
4109 QualType OldDeduced = T->getDeducedType();
4110 QualType NewDeduced;
4111 if (!OldDeduced.isNull()) {
4112 NewDeduced = getDerived().TransformType(OldDeduced);
4113 if (NewDeduced.isNull())
4114 return QualType();
4115 }
4116
4117 QualType Result = TL.getType();
4118 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4119 Result = getDerived().RebuildAutoType(NewDeduced);
4120 if (Result.isNull())
4121 return QualType();
4122 }
4123
4124 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4125 NewTL.setNameLoc(TL.getNameLoc());
4126
4127 return Result;
4128}
4129
4130template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004131QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004132 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004133 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004134 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004135 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4136 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004137 if (!Record)
4138 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004139
John McCalla2becad2009-10-21 00:40:46 +00004140 QualType Result = TL.getType();
4141 if (getDerived().AlwaysRebuild() ||
4142 Record != T->getDecl()) {
4143 Result = getDerived().RebuildRecordType(Record);
4144 if (Result.isNull())
4145 return QualType();
4146 }
Mike Stump1eb44332009-09-09 15:08:12 +00004147
John McCalla2becad2009-10-21 00:40:46 +00004148 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4149 NewTL.setNameLoc(TL.getNameLoc());
4150
4151 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004152}
Mike Stump1eb44332009-09-09 15:08:12 +00004153
4154template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004155QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004156 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004157 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004158 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004159 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4160 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004161 if (!Enum)
4162 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004163
John McCalla2becad2009-10-21 00:40:46 +00004164 QualType Result = TL.getType();
4165 if (getDerived().AlwaysRebuild() ||
4166 Enum != T->getDecl()) {
4167 Result = getDerived().RebuildEnumType(Enum);
4168 if (Result.isNull())
4169 return QualType();
4170 }
Mike Stump1eb44332009-09-09 15:08:12 +00004171
John McCalla2becad2009-10-21 00:40:46 +00004172 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4173 NewTL.setNameLoc(TL.getNameLoc());
4174
4175 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004176}
John McCall7da24312009-09-05 00:15:47 +00004177
John McCall3cb0ebd2010-03-10 03:28:59 +00004178template<typename Derived>
4179QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4180 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004181 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004182 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4183 TL.getTypePtr()->getDecl());
4184 if (!D) return QualType();
4185
4186 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4187 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4188 return T;
4189}
4190
Douglas Gregor577f75a2009-08-04 16:50:30 +00004191template<typename Derived>
4192QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004193 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004194 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004195 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004196}
4197
Mike Stump1eb44332009-09-09 15:08:12 +00004198template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004199QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004200 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004201 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004202 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4203
4204 // Substitute into the replacement type, which itself might involve something
4205 // that needs to be transformed. This only tends to occur with default
4206 // template arguments of template template parameters.
4207 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4208 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4209 if (Replacement.isNull())
4210 return QualType();
4211
4212 // Always canonicalize the replacement type.
4213 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4214 QualType Result
4215 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4216 Replacement);
4217
4218 // Propagate type-source information.
4219 SubstTemplateTypeParmTypeLoc NewTL
4220 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4221 NewTL.setNameLoc(TL.getNameLoc());
4222 return Result;
4223
John McCall49a832b2009-10-18 09:09:24 +00004224}
4225
4226template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004227QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4228 TypeLocBuilder &TLB,
4229 SubstTemplateTypeParmPackTypeLoc TL) {
4230 return TransformTypeSpecType(TLB, TL);
4231}
4232
4233template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004234QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004235 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004236 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004237 const TemplateSpecializationType *T = TL.getTypePtr();
4238
Douglas Gregor1d752d72011-03-02 18:46:51 +00004239 // The nested-name-specifier never matters in a TemplateSpecializationType,
4240 // because we can't have a dependent nested-name-specifier anyway.
4241 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004242 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004243 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4244 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004245 if (Template.isNull())
4246 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCall43fed0d2010-11-12 08:19:04 +00004248 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4249}
4250
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004251namespace {
4252 /// \brief Simple iterator that traverses the template arguments in a
4253 /// container that provides a \c getArgLoc() member function.
4254 ///
4255 /// This iterator is intended to be used with the iterator form of
4256 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4257 template<typename ArgLocContainer>
4258 class TemplateArgumentLocContainerIterator {
4259 ArgLocContainer *Container;
4260 unsigned Index;
4261
4262 public:
4263 typedef TemplateArgumentLoc value_type;
4264 typedef TemplateArgumentLoc reference;
4265 typedef int difference_type;
4266 typedef std::input_iterator_tag iterator_category;
4267
4268 class pointer {
4269 TemplateArgumentLoc Arg;
4270
4271 public:
4272 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4273
4274 const TemplateArgumentLoc *operator->() const {
4275 return &Arg;
4276 }
4277 };
4278
4279
4280 TemplateArgumentLocContainerIterator() {}
4281
4282 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4283 unsigned Index)
4284 : Container(&Container), Index(Index) { }
4285
4286 TemplateArgumentLocContainerIterator &operator++() {
4287 ++Index;
4288 return *this;
4289 }
4290
4291 TemplateArgumentLocContainerIterator operator++(int) {
4292 TemplateArgumentLocContainerIterator Old(*this);
4293 ++(*this);
4294 return Old;
4295 }
4296
4297 TemplateArgumentLoc operator*() const {
4298 return Container->getArgLoc(Index);
4299 }
4300
4301 pointer operator->() const {
4302 return pointer(Container->getArgLoc(Index));
4303 }
4304
4305 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004306 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004307 return X.Container == Y.Container && X.Index == Y.Index;
4308 }
4309
4310 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004311 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004312 return !(X == Y);
4313 }
4314 };
4315}
4316
4317
John McCall43fed0d2010-11-12 08:19:04 +00004318template <typename Derived>
4319QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4320 TypeLocBuilder &TLB,
4321 TemplateSpecializationTypeLoc TL,
4322 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004323 TemplateArgumentListInfo NewTemplateArgs;
4324 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4325 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004326 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4327 ArgIterator;
4328 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4329 ArgIterator(TL, TL.getNumArgs()),
4330 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004331 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004332
John McCall833ca992009-10-29 08:12:44 +00004333 // FIXME: maybe don't rebuild if all the template arguments are the same.
4334
4335 QualType Result =
4336 getDerived().RebuildTemplateSpecializationType(Template,
4337 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004338 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004339
4340 if (!Result.isNull()) {
4341 TemplateSpecializationTypeLoc NewTL
4342 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4343 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4344 NewTL.setLAngleLoc(TL.getLAngleLoc());
4345 NewTL.setRAngleLoc(TL.getRAngleLoc());
4346 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4347 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004348 }
Mike Stump1eb44332009-09-09 15:08:12 +00004349
John McCall833ca992009-10-29 08:12:44 +00004350 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004351}
Mike Stump1eb44332009-09-09 15:08:12 +00004352
Douglas Gregora88f09f2011-02-28 17:23:35 +00004353template <typename Derived>
4354QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4355 TypeLocBuilder &TLB,
4356 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004357 TemplateName Template,
4358 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004359 TemplateArgumentListInfo NewTemplateArgs;
4360 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4361 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4362 typedef TemplateArgumentLocContainerIterator<
4363 DependentTemplateSpecializationTypeLoc> ArgIterator;
4364 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4365 ArgIterator(TL, TL.getNumArgs()),
4366 NewTemplateArgs))
4367 return QualType();
4368
4369 // FIXME: maybe don't rebuild if all the template arguments are the same.
4370
4371 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4372 QualType Result
4373 = getSema().Context.getDependentTemplateSpecializationType(
4374 TL.getTypePtr()->getKeyword(),
4375 DTN->getQualifier(),
4376 DTN->getIdentifier(),
4377 NewTemplateArgs);
4378
4379 DependentTemplateSpecializationTypeLoc NewTL
4380 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4381 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004382
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004383 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004384 NewTL.setNameLoc(TL.getNameLoc());
4385 NewTL.setLAngleLoc(TL.getLAngleLoc());
4386 NewTL.setRAngleLoc(TL.getRAngleLoc());
4387 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4388 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4389 return Result;
4390 }
4391
4392 QualType Result
4393 = getDerived().RebuildTemplateSpecializationType(Template,
4394 TL.getNameLoc(),
4395 NewTemplateArgs);
4396
4397 if (!Result.isNull()) {
4398 /// FIXME: Wrap this in an elaborated-type-specifier?
4399 TemplateSpecializationTypeLoc NewTL
4400 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4401 NewTL.setTemplateNameLoc(TL.getNameLoc());
4402 NewTL.setLAngleLoc(TL.getLAngleLoc());
4403 NewTL.setRAngleLoc(TL.getRAngleLoc());
4404 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4405 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4406 }
4407
4408 return Result;
4409}
4410
Mike Stump1eb44332009-09-09 15:08:12 +00004411template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004412QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004413TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004414 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004415 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004416
Douglas Gregor9e876872011-03-01 18:12:44 +00004417 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004418 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004419 if (TL.getQualifierLoc()) {
4420 QualifierLoc
4421 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4422 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004423 return QualType();
4424 }
Mike Stump1eb44332009-09-09 15:08:12 +00004425
John McCall43fed0d2010-11-12 08:19:04 +00004426 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4427 if (NamedT.isNull())
4428 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004429
John McCalla2becad2009-10-21 00:40:46 +00004430 QualType Result = TL.getType();
4431 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004432 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004433 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004434 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004435 T->getKeyword(),
4436 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004437 if (Result.isNull())
4438 return QualType();
4439 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004440
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004441 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004442 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004443 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004444 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004445}
Mike Stump1eb44332009-09-09 15:08:12 +00004446
4447template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004448QualType TreeTransform<Derived>::TransformAttributedType(
4449 TypeLocBuilder &TLB,
4450 AttributedTypeLoc TL) {
4451 const AttributedType *oldType = TL.getTypePtr();
4452 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4453 if (modifiedType.isNull())
4454 return QualType();
4455
4456 QualType result = TL.getType();
4457
4458 // FIXME: dependent operand expressions?
4459 if (getDerived().AlwaysRebuild() ||
4460 modifiedType != oldType->getModifiedType()) {
4461 // TODO: this is really lame; we should really be rebuilding the
4462 // equivalent type from first principles.
4463 QualType equivalentType
4464 = getDerived().TransformType(oldType->getEquivalentType());
4465 if (equivalentType.isNull())
4466 return QualType();
4467 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4468 modifiedType,
4469 equivalentType);
4470 }
4471
4472 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4473 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4474 if (TL.hasAttrOperand())
4475 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4476 if (TL.hasAttrExprOperand())
4477 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4478 else if (TL.hasAttrEnumOperand())
4479 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4480
4481 return result;
4482}
4483
4484template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004485QualType
4486TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4487 ParenTypeLoc TL) {
4488 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4489 if (Inner.isNull())
4490 return QualType();
4491
4492 QualType Result = TL.getType();
4493 if (getDerived().AlwaysRebuild() ||
4494 Inner != TL.getInnerLoc().getType()) {
4495 Result = getDerived().RebuildParenType(Inner);
4496 if (Result.isNull())
4497 return QualType();
4498 }
4499
4500 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4501 NewTL.setLParenLoc(TL.getLParenLoc());
4502 NewTL.setRParenLoc(TL.getRParenLoc());
4503 return Result;
4504}
4505
4506template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004507QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004508 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004509 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004510
Douglas Gregor2494dd02011-03-01 01:34:45 +00004511 NestedNameSpecifierLoc QualifierLoc
4512 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4513 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004514 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004515
John McCall33500952010-06-11 00:33:02 +00004516 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004517 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004518 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004519 QualifierLoc,
4520 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004521 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004522 if (Result.isNull())
4523 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004524
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004525 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4526 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004527 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4528
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004529 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4530 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004531 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004532 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004533 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4534 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004535 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004536 NewTL.setNameLoc(TL.getNameLoc());
4537 }
John McCalla2becad2009-10-21 00:40:46 +00004538 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004539}
Mike Stump1eb44332009-09-09 15:08:12 +00004540
Douglas Gregor577f75a2009-08-04 16:50:30 +00004541template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004542QualType TreeTransform<Derived>::
4543 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004544 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004545 NestedNameSpecifierLoc QualifierLoc;
4546 if (TL.getQualifierLoc()) {
4547 QualifierLoc
4548 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4549 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004550 return QualType();
4551 }
4552
John McCall43fed0d2010-11-12 08:19:04 +00004553 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004554 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004555}
4556
4557template<typename Derived>
4558QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004559TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4560 DependentTemplateSpecializationTypeLoc TL,
4561 NestedNameSpecifierLoc QualifierLoc) {
4562 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4563
4564 TemplateArgumentListInfo NewTemplateArgs;
4565 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4566 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4567
4568 typedef TemplateArgumentLocContainerIterator<
4569 DependentTemplateSpecializationTypeLoc> ArgIterator;
4570 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4571 ArgIterator(TL, TL.getNumArgs()),
4572 NewTemplateArgs))
4573 return QualType();
4574
4575 QualType Result
4576 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4577 QualifierLoc,
4578 T->getIdentifier(),
4579 TL.getNameLoc(),
4580 NewTemplateArgs);
4581 if (Result.isNull())
4582 return QualType();
4583
4584 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4585 QualType NamedT = ElabT->getNamedType();
4586
4587 // Copy information relevant to the template specialization.
4588 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004589 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004590 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004591 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4592 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004593 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004594 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004595
4596 // Copy information relevant to the elaborated type.
4597 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4598 NewTL.setKeywordLoc(TL.getKeywordLoc());
4599 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004600 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4601 DependentTemplateSpecializationTypeLoc SpecTL
4602 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004603 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004604 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004605 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004606 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4607 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004608 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004609 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004610 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004611 TemplateSpecializationTypeLoc SpecTL
4612 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004613 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004614 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4615 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004616 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004617 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004618 }
4619 return Result;
4620}
4621
4622template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004623QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4624 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004625 QualType Pattern
4626 = getDerived().TransformType(TLB, TL.getPatternLoc());
4627 if (Pattern.isNull())
4628 return QualType();
4629
4630 QualType Result = TL.getType();
4631 if (getDerived().AlwaysRebuild() ||
4632 Pattern != TL.getPatternLoc().getType()) {
4633 Result = getDerived().RebuildPackExpansionType(Pattern,
4634 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004635 TL.getEllipsisLoc(),
4636 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004637 if (Result.isNull())
4638 return QualType();
4639 }
4640
4641 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4642 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4643 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004644}
4645
4646template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004647QualType
4648TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004649 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004650 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004651 TLB.pushFullCopy(TL);
4652 return TL.getType();
4653}
4654
4655template<typename Derived>
4656QualType
4657TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004658 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004659 // ObjCObjectType is never dependent.
4660 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004661 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004662}
Mike Stump1eb44332009-09-09 15:08:12 +00004663
4664template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004665QualType
4666TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004667 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004668 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004669 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004670 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004671}
4672
Douglas Gregor577f75a2009-08-04 16:50:30 +00004673//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004674// Statement transformation
4675//===----------------------------------------------------------------------===//
4676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004677StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004678TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004679 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004680}
4681
4682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004683StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004684TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4685 return getDerived().TransformCompoundStmt(S, false);
4686}
4687
4688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004689StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004690TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004691 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004692 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004693 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004694 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004695 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4696 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004697 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004698 if (Result.isInvalid()) {
4699 // Immediately fail if this was a DeclStmt, since it's very
4700 // likely that this will cause problems for future statements.
4701 if (isa<DeclStmt>(*B))
4702 return StmtError();
4703
4704 // Otherwise, just keep processing substatements and fail later.
4705 SubStmtInvalid = true;
4706 continue;
4707 }
Mike Stump1eb44332009-09-09 15:08:12 +00004708
Douglas Gregor43959a92009-08-20 07:17:43 +00004709 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4710 Statements.push_back(Result.takeAs<Stmt>());
4711 }
Mike Stump1eb44332009-09-09 15:08:12 +00004712
John McCall7114cba2010-08-27 19:56:05 +00004713 if (SubStmtInvalid)
4714 return StmtError();
4715
Douglas Gregor43959a92009-08-20 07:17:43 +00004716 if (!getDerived().AlwaysRebuild() &&
4717 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004718 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004719
4720 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4721 move_arg(Statements),
4722 S->getRBracLoc(),
4723 IsStmtExpr);
4724}
Mike Stump1eb44332009-09-09 15:08:12 +00004725
Douglas Gregor43959a92009-08-20 07:17:43 +00004726template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004727StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004728TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004729 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004730 {
4731 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004732 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004733
Eli Friedman264c1f82009-11-19 03:14:00 +00004734 // Transform the left-hand case value.
4735 LHS = getDerived().TransformExpr(S->getLHS());
4736 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004737 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004738
Eli Friedman264c1f82009-11-19 03:14:00 +00004739 // Transform the right-hand case value (for the GNU case-range extension).
4740 RHS = getDerived().TransformExpr(S->getRHS());
4741 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004742 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004743 }
Mike Stump1eb44332009-09-09 15:08:12 +00004744
Douglas Gregor43959a92009-08-20 07:17:43 +00004745 // Build the case statement.
4746 // Case statements are always rebuilt so that they will attached to their
4747 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004748 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004749 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004750 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004751 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004752 S->getColonLoc());
4753 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004754 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004755
Douglas Gregor43959a92009-08-20 07:17:43 +00004756 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004757 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004758 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004759 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004760
Douglas Gregor43959a92009-08-20 07:17:43 +00004761 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004762 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004763}
4764
4765template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004766StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004767TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004768 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004769 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004770 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004771 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004772
Douglas Gregor43959a92009-08-20 07:17:43 +00004773 // Default statements are always rebuilt
4774 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004775 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004776}
Mike Stump1eb44332009-09-09 15:08:12 +00004777
Douglas Gregor43959a92009-08-20 07:17:43 +00004778template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004779StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004780TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004781 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004782 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004783 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004784
Chris Lattner57ad3782011-02-17 20:34:02 +00004785 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4786 S->getDecl());
4787 if (!LD)
4788 return StmtError();
4789
4790
Douglas Gregor43959a92009-08-20 07:17:43 +00004791 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004792 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004793 cast<LabelDecl>(LD), SourceLocation(),
4794 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004795}
Mike Stump1eb44332009-09-09 15:08:12 +00004796
Douglas Gregor43959a92009-08-20 07:17:43 +00004797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004798StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004799TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004800 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004801 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004802 VarDecl *ConditionVar = 0;
4803 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004804 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004805 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004806 getDerived().TransformDefinition(
4807 S->getConditionVariable()->getLocation(),
4808 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004809 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004810 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004811 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004812 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004813
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004814 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004815 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004816
4817 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004818 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004819 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4820 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004821 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004822 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004823
John McCall9ae2f072010-08-23 23:25:46 +00004824 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004825 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004826 }
Sean Huntc3021132010-05-05 15:23:54 +00004827
John McCall9ae2f072010-08-23 23:25:46 +00004828 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4829 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004830 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004831
Douglas Gregor43959a92009-08-20 07:17:43 +00004832 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004833 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004834 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004835 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004836
Douglas Gregor43959a92009-08-20 07:17:43 +00004837 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004838 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004839 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004840 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004841
Douglas Gregor43959a92009-08-20 07:17:43 +00004842 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004843 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004844 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004845 Then.get() == S->getThen() &&
4846 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004847 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004848
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004849 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004850 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004851 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004852}
4853
4854template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004855StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004856TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004857 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004858 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004859 VarDecl *ConditionVar = 0;
4860 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004861 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004862 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004863 getDerived().TransformDefinition(
4864 S->getConditionVariable()->getLocation(),
4865 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004866 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004867 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004868 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004869 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004870
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004871 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004872 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004873 }
Mike Stump1eb44332009-09-09 15:08:12 +00004874
Douglas Gregor43959a92009-08-20 07:17:43 +00004875 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004876 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004877 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004878 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004879 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004880 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004881
Douglas Gregor43959a92009-08-20 07:17:43 +00004882 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004883 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004884 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004885 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004886
Douglas Gregor43959a92009-08-20 07:17:43 +00004887 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004888 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4889 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004890}
Mike Stump1eb44332009-09-09 15:08:12 +00004891
Douglas Gregor43959a92009-08-20 07:17:43 +00004892template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004893StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004894TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004895 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004896 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004897 VarDecl *ConditionVar = 0;
4898 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004899 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004900 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004901 getDerived().TransformDefinition(
4902 S->getConditionVariable()->getLocation(),
4903 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004904 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004905 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004906 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004907 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004908
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004909 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004910 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004911
4912 if (S->getCond()) {
4913 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004914 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4915 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004916 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004917 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004918 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004919 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004920 }
Mike Stump1eb44332009-09-09 15:08:12 +00004921
John McCall9ae2f072010-08-23 23:25:46 +00004922 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4923 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004924 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004925
Douglas Gregor43959a92009-08-20 07:17:43 +00004926 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004927 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004928 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004929 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004930
Douglas Gregor43959a92009-08-20 07:17:43 +00004931 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004932 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004933 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004934 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004935 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004936
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004937 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004938 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004939}
Mike Stump1eb44332009-09-09 15:08:12 +00004940
Douglas Gregor43959a92009-08-20 07:17:43 +00004941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004942StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004943TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004944 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004945 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004946 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004947 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004949 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004950 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004951 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004952 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004953
Douglas Gregor43959a92009-08-20 07:17:43 +00004954 if (!getDerived().AlwaysRebuild() &&
4955 Cond.get() == S->getCond() &&
4956 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004957 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004958
John McCall9ae2f072010-08-23 23:25:46 +00004959 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4960 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004961 S->getRParenLoc());
4962}
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregor43959a92009-08-20 07:17:43 +00004964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004965StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004966TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004967 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004968 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004969 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004970 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004971
Douglas Gregor43959a92009-08-20 07:17:43 +00004972 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004973 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004974 VarDecl *ConditionVar = 0;
4975 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004976 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004977 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004978 getDerived().TransformDefinition(
4979 S->getConditionVariable()->getLocation(),
4980 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004981 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004982 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004983 } else {
4984 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004985
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004986 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004987 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004988
4989 if (S->getCond()) {
4990 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004991 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4992 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004993 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004994 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004995
John McCall9ae2f072010-08-23 23:25:46 +00004996 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004997 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004998 }
Mike Stump1eb44332009-09-09 15:08:12 +00004999
John McCall9ae2f072010-08-23 23:25:46 +00005000 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5001 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005002 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005003
Douglas Gregor43959a92009-08-20 07:17:43 +00005004 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005005 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005006 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005007 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005008
John McCall9ae2f072010-08-23 23:25:46 +00005009 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5010 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005011 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005012
Douglas Gregor43959a92009-08-20 07:17:43 +00005013 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005014 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005015 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005016 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005017
Douglas Gregor43959a92009-08-20 07:17:43 +00005018 if (!getDerived().AlwaysRebuild() &&
5019 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005020 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005021 Inc.get() == S->getInc() &&
5022 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005023 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005024
Douglas Gregor43959a92009-08-20 07:17:43 +00005025 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005026 Init.get(), FullCond, ConditionVar,
5027 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005028}
5029
5030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005031StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005032TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005033 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5034 S->getLabel());
5035 if (!LD)
5036 return StmtError();
5037
Douglas Gregor43959a92009-08-20 07:17:43 +00005038 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005039 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005040 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005041}
5042
5043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005044StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005045TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005046 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005047 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005048 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005049
Douglas Gregor43959a92009-08-20 07:17:43 +00005050 if (!getDerived().AlwaysRebuild() &&
5051 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005052 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005053
5054 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005055 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005056}
5057
5058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005059StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005060TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005061 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005062}
Mike Stump1eb44332009-09-09 15:08:12 +00005063
Douglas Gregor43959a92009-08-20 07:17:43 +00005064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005065StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005066TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005067 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005068}
Mike Stump1eb44332009-09-09 15:08:12 +00005069
Douglas Gregor43959a92009-08-20 07:17:43 +00005070template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005071StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005072TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005073 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005074 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005075 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005076
Mike Stump1eb44332009-09-09 15:08:12 +00005077 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005078 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005079 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005080}
Mike Stump1eb44332009-09-09 15:08:12 +00005081
Douglas Gregor43959a92009-08-20 07:17:43 +00005082template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005083StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005084TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005085 bool DeclChanged = false;
5086 llvm::SmallVector<Decl *, 4> Decls;
5087 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5088 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005089 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5090 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005092 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005093
Douglas Gregor43959a92009-08-20 07:17:43 +00005094 if (Transformed != *D)
5095 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 Decls.push_back(Transformed);
5098 }
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005101 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005102
5103 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 S->getStartLoc(), S->getEndLoc());
5105}
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregor43959a92009-08-20 07:17:43 +00005107template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005108StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005109TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005110
John McCallca0408f2010-08-23 06:44:23 +00005111 ASTOwningVector<Expr*> Constraints(getSema());
5112 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005113 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005114
John McCall60d7b3a2010-08-24 06:29:42 +00005115 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005116 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005117
5118 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005119
Anders Carlsson703e3942010-01-24 05:50:09 +00005120 // Go through the outputs.
5121 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005122 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005123
Anders Carlsson703e3942010-01-24 05:50:09 +00005124 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005125 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005126
Anders Carlsson703e3942010-01-24 05:50:09 +00005127 // Transform the output expr.
5128 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005129 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005130 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005131 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005132
Anders Carlsson703e3942010-01-24 05:50:09 +00005133 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005134
John McCall9ae2f072010-08-23 23:25:46 +00005135 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005136 }
Sean Huntc3021132010-05-05 15:23:54 +00005137
Anders Carlsson703e3942010-01-24 05:50:09 +00005138 // Go through the inputs.
5139 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005140 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005141
Anders Carlsson703e3942010-01-24 05:50:09 +00005142 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005143 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005144
Anders Carlsson703e3942010-01-24 05:50:09 +00005145 // Transform the input expr.
5146 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005147 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005148 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005149 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005150
Anders Carlsson703e3942010-01-24 05:50:09 +00005151 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005152
John McCall9ae2f072010-08-23 23:25:46 +00005153 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005154 }
Sean Huntc3021132010-05-05 15:23:54 +00005155
Anders Carlsson703e3942010-01-24 05:50:09 +00005156 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005157 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005158
5159 // Go through the clobbers.
5160 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005161 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005162
5163 // No need to transform the asm string literal.
5164 AsmString = SemaRef.Owned(S->getAsmString());
5165
5166 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5167 S->isSimple(),
5168 S->isVolatile(),
5169 S->getNumOutputs(),
5170 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005171 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005172 move_arg(Constraints),
5173 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005174 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005175 move_arg(Clobbers),
5176 S->getRParenLoc(),
5177 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005178}
5179
5180
5181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005182StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005183TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005184 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005185 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005186 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005187 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005188
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005189 // Transform the @catch statements (if present).
5190 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005191 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005192 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005193 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005194 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005195 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005196 if (Catch.get() != S->getCatchStmt(I))
5197 AnyCatchChanged = true;
5198 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005199 }
Sean Huntc3021132010-05-05 15:23:54 +00005200
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005201 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005202 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005203 if (S->getFinallyStmt()) {
5204 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5205 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005206 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005207 }
5208
5209 // If nothing changed, just retain this statement.
5210 if (!getDerived().AlwaysRebuild() &&
5211 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005212 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005213 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005214 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005215
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005216 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005217 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5218 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005219}
Mike Stump1eb44332009-09-09 15:08:12 +00005220
Douglas Gregor43959a92009-08-20 07:17:43 +00005221template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005222StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005223TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005224 // Transform the @catch parameter, if there is one.
5225 VarDecl *Var = 0;
5226 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5227 TypeSourceInfo *TSInfo = 0;
5228 if (FromVar->getTypeSourceInfo()) {
5229 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5230 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005231 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005232 }
Sean Huntc3021132010-05-05 15:23:54 +00005233
Douglas Gregorbe270a02010-04-26 17:57:08 +00005234 QualType T;
5235 if (TSInfo)
5236 T = TSInfo->getType();
5237 else {
5238 T = getDerived().TransformType(FromVar->getType());
5239 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005241 }
Sean Huntc3021132010-05-05 15:23:54 +00005242
Douglas Gregorbe270a02010-04-26 17:57:08 +00005243 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5244 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005246 }
Sean Huntc3021132010-05-05 15:23:54 +00005247
John McCall60d7b3a2010-08-24 06:29:42 +00005248 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005249 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005250 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005251
5252 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005253 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005254 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005255}
Mike Stump1eb44332009-09-09 15:08:12 +00005256
Douglas Gregor43959a92009-08-20 07:17:43 +00005257template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005258StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005259TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005260 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005261 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005262 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005264
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005265 // If nothing changed, just retain this statement.
5266 if (!getDerived().AlwaysRebuild() &&
5267 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005268 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005269
5270 // Build a new statement.
5271 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005272 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005273}
Mike Stump1eb44332009-09-09 15:08:12 +00005274
Douglas Gregor43959a92009-08-20 07:17:43 +00005275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005276StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005277TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005278 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005279 if (S->getThrowExpr()) {
5280 Operand = getDerived().TransformExpr(S->getThrowExpr());
5281 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005282 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005283 }
Sean Huntc3021132010-05-05 15:23:54 +00005284
Douglas Gregord1377b22010-04-22 21:44:01 +00005285 if (!getDerived().AlwaysRebuild() &&
5286 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005287 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005288
John McCall9ae2f072010-08-23 23:25:46 +00005289 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005290}
Mike Stump1eb44332009-09-09 15:08:12 +00005291
Douglas Gregor43959a92009-08-20 07:17:43 +00005292template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005293StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005294TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005295 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005296 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005297 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005298 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005299 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005300
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005301 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005302 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005303 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005304 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005305
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005306 // If nothing change, just retain the current statement.
5307 if (!getDerived().AlwaysRebuild() &&
5308 Object.get() == S->getSynchExpr() &&
5309 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005310 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005311
5312 // Build a new statement.
5313 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005314 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315}
5316
5317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005318StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005319TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005320 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005321 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005322 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005323 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005324 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005325
Douglas Gregorc3203e72010-04-22 23:10:45 +00005326 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005327 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005328 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005329 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005330
Douglas Gregorc3203e72010-04-22 23:10:45 +00005331 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005332 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005333 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005335
Douglas Gregorc3203e72010-04-22 23:10:45 +00005336 // If nothing changed, just retain this statement.
5337 if (!getDerived().AlwaysRebuild() &&
5338 Element.get() == S->getElement() &&
5339 Collection.get() == S->getCollection() &&
5340 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005341 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005342
Douglas Gregorc3203e72010-04-22 23:10:45 +00005343 // Build a new statement.
5344 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5345 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005346 Element.get(),
5347 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005348 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005349 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005350}
5351
5352
5353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005354StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005355TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5356 // Transform the exception declaration, if any.
5357 VarDecl *Var = 0;
5358 if (S->getExceptionDecl()) {
5359 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005360 TypeSourceInfo *T = getDerived().TransformType(
5361 ExceptionDecl->getTypeSourceInfo());
5362 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005364
Douglas Gregor83cb9422010-09-09 17:09:21 +00005365 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005366 ExceptionDecl->getInnerLocStart(),
5367 ExceptionDecl->getLocation(),
5368 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005369 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005370 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005371 }
Mike Stump1eb44332009-09-09 15:08:12 +00005372
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005374 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005375 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (!getDerived().AlwaysRebuild() &&
5379 !Var &&
5380 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005381 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005382
5383 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5384 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005385 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005386}
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005389StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005390TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5391 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005392 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005393 = getDerived().TransformCompoundStmt(S->getTryBlock());
5394 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregor43959a92009-08-20 07:17:43 +00005397 // Transform the handlers.
5398 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005399 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005400 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005401 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005402 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5403 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005405
Douglas Gregor43959a92009-08-20 07:17:43 +00005406 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5407 Handlers.push_back(Handler.takeAs<Stmt>());
5408 }
Mike Stump1eb44332009-09-09 15:08:12 +00005409
Douglas Gregor43959a92009-08-20 07:17:43 +00005410 if (!getDerived().AlwaysRebuild() &&
5411 TryBlock.get() == S->getTryBlock() &&
5412 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005413 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005414
John McCall9ae2f072010-08-23 23:25:46 +00005415 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005416 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005417}
Mike Stump1eb44332009-09-09 15:08:12 +00005418
Richard Smithad762fc2011-04-14 22:09:26 +00005419template<typename Derived>
5420StmtResult
5421TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5422 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5423 if (Range.isInvalid())
5424 return StmtError();
5425
5426 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5427 if (BeginEnd.isInvalid())
5428 return StmtError();
5429
5430 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5431 if (Cond.isInvalid())
5432 return StmtError();
5433
5434 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5435 if (Inc.isInvalid())
5436 return StmtError();
5437
5438 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5439 if (LoopVar.isInvalid())
5440 return StmtError();
5441
5442 StmtResult NewStmt = S;
5443 if (getDerived().AlwaysRebuild() ||
5444 Range.get() != S->getRangeStmt() ||
5445 BeginEnd.get() != S->getBeginEndStmt() ||
5446 Cond.get() != S->getCond() ||
5447 Inc.get() != S->getInc() ||
5448 LoopVar.get() != S->getLoopVarStmt())
5449 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5450 S->getColonLoc(), Range.get(),
5451 BeginEnd.get(), Cond.get(),
5452 Inc.get(), LoopVar.get(),
5453 S->getRParenLoc());
5454
5455 StmtResult Body = getDerived().TransformStmt(S->getBody());
5456 if (Body.isInvalid())
5457 return StmtError();
5458
5459 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5460 // it now so we have a new statement to attach the body to.
5461 if (Body.get() != S->getBody() && NewStmt.get() == S)
5462 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5463 S->getColonLoc(), Range.get(),
5464 BeginEnd.get(), Cond.get(),
5465 Inc.get(), LoopVar.get(),
5466 S->getRParenLoc());
5467
5468 if (NewStmt.get() == S)
5469 return SemaRef.Owned(S);
5470
5471 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5472}
5473
Douglas Gregor43959a92009-08-20 07:17:43 +00005474//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005475// Expression transformation
5476//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005478ExprResult
John McCall454feb92009-12-08 09:21:05 +00005479TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005480 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005481}
Mike Stump1eb44332009-09-09 15:08:12 +00005482
5483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005484ExprResult
John McCall454feb92009-12-08 09:21:05 +00005485TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005486 NestedNameSpecifierLoc QualifierLoc;
5487 if (E->getQualifierLoc()) {
5488 QualifierLoc
5489 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5490 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005491 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005492 }
John McCalldbd872f2009-12-08 09:08:17 +00005493
5494 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005495 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5496 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005497 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005498 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005499
John McCallec8045d2010-08-17 21:27:17 +00005500 DeclarationNameInfo NameInfo = E->getNameInfo();
5501 if (NameInfo.getName()) {
5502 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5503 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005504 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005505 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005506
5507 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005508 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005509 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005510 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005511 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005512
5513 // Mark it referenced in the new context regardless.
5514 // FIXME: this is a bit instantiation-specific.
5515 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5516
John McCall3fa5cae2010-10-26 07:05:15 +00005517 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005518 }
John McCalldbd872f2009-12-08 09:08:17 +00005519
5520 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005521 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005522 TemplateArgs = &TransArgs;
5523 TransArgs.setLAngleLoc(E->getLAngleLoc());
5524 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005525 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5526 E->getNumTemplateArgs(),
5527 TransArgs))
5528 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005529 }
5530
Douglas Gregor40d96a62011-02-28 21:54:11 +00005531 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5532 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005533}
Mike Stump1eb44332009-09-09 15:08:12 +00005534
Douglas Gregorb98b1992009-08-11 05:31:07 +00005535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005536ExprResult
John McCall454feb92009-12-08 09:21:05 +00005537TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005538 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005539}
Mike Stump1eb44332009-09-09 15:08:12 +00005540
Douglas Gregorb98b1992009-08-11 05:31:07 +00005541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005542ExprResult
John McCall454feb92009-12-08 09:21:05 +00005543TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005544 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005545}
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregorb98b1992009-08-11 05:31:07 +00005547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005548ExprResult
John McCall454feb92009-12-08 09:21:05 +00005549TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005550 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551}
Mike Stump1eb44332009-09-09 15:08:12 +00005552
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005554ExprResult
John McCall454feb92009-12-08 09:21:05 +00005555TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005556 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005557}
Mike Stump1eb44332009-09-09 15:08:12 +00005558
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005560ExprResult
John McCall454feb92009-12-08 09:21:05 +00005561TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005562 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005563}
5564
5565template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005566ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005567TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5568 ExprResult ControllingExpr =
5569 getDerived().TransformExpr(E->getControllingExpr());
5570 if (ControllingExpr.isInvalid())
5571 return ExprError();
5572
5573 llvm::SmallVector<Expr *, 4> AssocExprs;
5574 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5575 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5576 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5577 if (TS) {
5578 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5579 if (!AssocType)
5580 return ExprError();
5581 AssocTypes.push_back(AssocType);
5582 } else {
5583 AssocTypes.push_back(0);
5584 }
5585
5586 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5587 if (AssocExpr.isInvalid())
5588 return ExprError();
5589 AssocExprs.push_back(AssocExpr.release());
5590 }
5591
5592 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5593 E->getDefaultLoc(),
5594 E->getRParenLoc(),
5595 ControllingExpr.release(),
5596 AssocTypes.data(),
5597 AssocExprs.data(),
5598 E->getNumAssocs());
5599}
5600
5601template<typename Derived>
5602ExprResult
John McCall454feb92009-12-08 09:21:05 +00005603TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005604 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005609 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005610
John McCall9ae2f072010-08-23 23:25:46 +00005611 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612 E->getRParen());
5613}
5614
Mike Stump1eb44332009-09-09 15:08:12 +00005615template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005616ExprResult
John McCall454feb92009-12-08 09:21:05 +00005617TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005618 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005620 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005621
Douglas Gregorb98b1992009-08-11 05:31:07 +00005622 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005623 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5626 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005627 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005628}
Mike Stump1eb44332009-09-09 15:08:12 +00005629
Douglas Gregorb98b1992009-08-11 05:31:07 +00005630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005631ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005632TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5633 // Transform the type.
5634 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5635 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005636 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005637
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005638 // Transform all of the components into components similar to what the
5639 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005640 // FIXME: It would be slightly more efficient in the non-dependent case to
5641 // just map FieldDecls, rather than requiring the rebuilder to look for
5642 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005643 // template code that we don't care.
5644 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005645 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005646 typedef OffsetOfExpr::OffsetOfNode Node;
5647 llvm::SmallVector<Component, 4> Components;
5648 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5649 const Node &ON = E->getComponent(I);
5650 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005651 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005652 Comp.LocStart = ON.getSourceRange().getBegin();
5653 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005654 switch (ON.getKind()) {
5655 case Node::Array: {
5656 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005657 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005658 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005659 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005660
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005661 ExprChanged = ExprChanged || Index.get() != FromIndex;
5662 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005663 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005664 break;
5665 }
Sean Huntc3021132010-05-05 15:23:54 +00005666
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005667 case Node::Field:
5668 case Node::Identifier:
5669 Comp.isBrackets = false;
5670 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005671 if (!Comp.U.IdentInfo)
5672 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005673
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005674 break;
Sean Huntc3021132010-05-05 15:23:54 +00005675
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005676 case Node::Base:
5677 // Will be recomputed during the rebuild.
5678 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005679 }
Sean Huntc3021132010-05-05 15:23:54 +00005680
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005681 Components.push_back(Comp);
5682 }
Sean Huntc3021132010-05-05 15:23:54 +00005683
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005684 // If nothing changed, retain the existing expression.
5685 if (!getDerived().AlwaysRebuild() &&
5686 Type == E->getTypeSourceInfo() &&
5687 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005688 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005689
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005690 // Build a new offsetof expression.
5691 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5692 Components.data(), Components.size(),
5693 E->getRParenLoc());
5694}
5695
5696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005697ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005698TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5699 assert(getDerived().AlreadyTransformed(E->getType()) &&
5700 "opaque value expression requires transformation");
5701 return SemaRef.Owned(E);
5702}
5703
5704template<typename Derived>
5705ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005706TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5707 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005709 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005710
John McCalla93c9342009-12-07 02:54:59 +00005711 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005712 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005714
John McCall5ab75172009-11-04 07:28:41 +00005715 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005716 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005717
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005718 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5719 E->getKind(),
5720 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721 }
Mike Stump1eb44332009-09-09 15:08:12 +00005722
John McCall60d7b3a2010-08-24 06:29:42 +00005723 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005724 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005725 // C++0x [expr.sizeof]p1:
5726 // The operand is either an expression, which is an unevaluated operand
5727 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005728 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005729
Douglas Gregorb98b1992009-08-11 05:31:07 +00005730 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5731 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Douglas Gregorb98b1992009-08-11 05:31:07 +00005734 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005735 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005736 }
Mike Stump1eb44332009-09-09 15:08:12 +00005737
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005738 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5739 E->getOperatorLoc(),
5740 E->getKind(),
5741 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742}
Mike Stump1eb44332009-09-09 15:08:12 +00005743
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005745ExprResult
John McCall454feb92009-12-08 09:21:05 +00005746TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005747 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005749 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005750
John McCall60d7b3a2010-08-24 06:29:42 +00005751 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005752 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005754
5755
Douglas Gregorb98b1992009-08-11 05:31:07 +00005756 if (!getDerived().AlwaysRebuild() &&
5757 LHS.get() == E->getLHS() &&
5758 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005759 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005760
John McCall9ae2f072010-08-23 23:25:46 +00005761 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005762 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005763 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005764 E->getRBracketLoc());
5765}
Mike Stump1eb44332009-09-09 15:08:12 +00005766
5767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005768ExprResult
John McCall454feb92009-12-08 09:21:05 +00005769TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005770 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005771 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005773 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005774
5775 // Transform arguments.
5776 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005777 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005778 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5779 &ArgChanged))
5780 return ExprError();
5781
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782 if (!getDerived().AlwaysRebuild() &&
5783 Callee.get() == E->getCallee() &&
5784 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005785 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005788 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005789 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005790 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005791 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792 E->getRParenLoc());
5793}
Mike Stump1eb44332009-09-09 15:08:12 +00005794
5795template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005796ExprResult
John McCall454feb92009-12-08 09:21:05 +00005797TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005798 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005800 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregor40d96a62011-02-28 21:54:11 +00005802 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005803 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005804 QualifierLoc
5805 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5806
5807 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005808 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005809 }
Mike Stump1eb44332009-09-09 15:08:12 +00005810
Eli Friedmanf595cc42009-12-04 06:40:45 +00005811 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005812 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5813 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005816
John McCall6bb80172010-03-30 21:47:33 +00005817 NamedDecl *FoundDecl = E->getFoundDecl();
5818 if (FoundDecl == E->getMemberDecl()) {
5819 FoundDecl = Member;
5820 } else {
5821 FoundDecl = cast_or_null<NamedDecl>(
5822 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5823 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005824 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005825 }
5826
Douglas Gregorb98b1992009-08-11 05:31:07 +00005827 if (!getDerived().AlwaysRebuild() &&
5828 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005829 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005830 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005831 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005832 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005833
Anders Carlsson1f240322009-12-22 05:24:09 +00005834 // Mark it referenced in the new context regardless.
5835 // FIXME: this is a bit instantiation-specific.
5836 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005837 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005838 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005839
John McCalld5532b62009-11-23 01:53:49 +00005840 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005841 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005842 TransArgs.setLAngleLoc(E->getLAngleLoc());
5843 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005844 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5845 E->getNumTemplateArgs(),
5846 TransArgs))
5847 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005848 }
Sean Huntc3021132010-05-05 15:23:54 +00005849
Douglas Gregorb98b1992009-08-11 05:31:07 +00005850 // FIXME: Bogus source location for the operator
5851 SourceLocation FakeOperatorLoc
5852 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5853
John McCallc2233c52010-01-15 08:34:02 +00005854 // FIXME: to do this check properly, we will need to preserve the
5855 // first-qualifier-in-scope here, just in case we had a dependent
5856 // base (and therefore couldn't do the check) and a
5857 // nested-name-qualifier (and therefore could do the lookup).
5858 NamedDecl *FirstQualifierInScope = 0;
5859
John McCall9ae2f072010-08-23 23:25:46 +00005860 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00005862 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00005863 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005864 Member,
John McCall6bb80172010-03-30 21:47:33 +00005865 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005866 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005867 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005868 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005869}
Mike Stump1eb44332009-09-09 15:08:12 +00005870
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005872ExprResult
John McCall454feb92009-12-08 09:21:05 +00005873TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005874 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005875 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005876 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005877
John McCall60d7b3a2010-08-24 06:29:42 +00005878 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005879 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005880 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005881
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882 if (!getDerived().AlwaysRebuild() &&
5883 LHS.get() == E->getLHS() &&
5884 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005885 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005886
Douglas Gregorb98b1992009-08-11 05:31:07 +00005887 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005888 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005889}
5890
Mike Stump1eb44332009-09-09 15:08:12 +00005891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005892ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005893TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005894 CompoundAssignOperator *E) {
5895 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005896}
Mike Stump1eb44332009-09-09 15:08:12 +00005897
Douglas Gregorb98b1992009-08-11 05:31:07 +00005898template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00005899ExprResult TreeTransform<Derived>::
5900TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5901 // Just rebuild the common and RHS expressions and see whether we
5902 // get any changes.
5903
5904 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5905 if (commonExpr.isInvalid())
5906 return ExprError();
5907
5908 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5909 if (rhs.isInvalid())
5910 return ExprError();
5911
5912 if (!getDerived().AlwaysRebuild() &&
5913 commonExpr.get() == e->getCommon() &&
5914 rhs.get() == e->getFalseExpr())
5915 return SemaRef.Owned(e);
5916
5917 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5918 e->getQuestionLoc(),
5919 0,
5920 e->getColonLoc(),
5921 rhs.get());
5922}
5923
5924template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005925ExprResult
John McCall454feb92009-12-08 09:21:05 +00005926TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005927 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005928 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005929 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005930
John McCall60d7b3a2010-08-24 06:29:42 +00005931 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005932 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005933 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005934
John McCall60d7b3a2010-08-24 06:29:42 +00005935 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005936 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005937 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005938
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939 if (!getDerived().AlwaysRebuild() &&
5940 Cond.get() == E->getCond() &&
5941 LHS.get() == E->getLHS() &&
5942 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005943 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005944
John McCall9ae2f072010-08-23 23:25:46 +00005945 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005946 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005947 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005948 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005949 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950}
Mike Stump1eb44332009-09-09 15:08:12 +00005951
5952template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005953ExprResult
John McCall454feb92009-12-08 09:21:05 +00005954TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005955 // Implicit casts are eliminated during transformation, since they
5956 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005957 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005958}
Mike Stump1eb44332009-09-09 15:08:12 +00005959
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005961ExprResult
John McCall454feb92009-12-08 09:21:05 +00005962TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005963 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5964 if (!Type)
5965 return ExprError();
5966
John McCall60d7b3a2010-08-24 06:29:42 +00005967 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005968 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005969 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005971
Douglas Gregorb98b1992009-08-11 05:31:07 +00005972 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005973 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005975 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005976
John McCall9d125032010-01-15 18:39:57 +00005977 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005978 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005979 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005980 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005981}
Mike Stump1eb44332009-09-09 15:08:12 +00005982
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005984ExprResult
John McCall454feb92009-12-08 09:21:05 +00005985TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005986 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5987 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5988 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005989 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005990
John McCall60d7b3a2010-08-24 06:29:42 +00005991 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005992 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005994
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005996 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005998 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005999
John McCall1d7d8d62010-01-19 22:33:45 +00006000 // Note: the expression type doesn't necessarily match the
6001 // type-as-written, but that's okay, because it should always be
6002 // derivable from the initializer.
6003
John McCall42f56b52010-01-18 19:35:47 +00006004 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006006 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006007}
Mike Stump1eb44332009-09-09 15:08:12 +00006008
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006010ExprResult
John McCall454feb92009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006012 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006013 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006015
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016 if (!getDerived().AlwaysRebuild() &&
6017 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006018 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006021 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006023 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006024 E->getAccessorLoc(),
6025 E->getAccessor());
6026}
Mike Stump1eb44332009-09-09 15:08:12 +00006027
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006029ExprResult
John McCall454feb92009-12-08 09:21:05 +00006030TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006032
John McCallca0408f2010-08-23 06:44:23 +00006033 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006034 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6035 Inits, &InitChanged))
6036 return ExprError();
6037
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006039 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006040
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006042 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006043}
Mike Stump1eb44332009-09-09 15:08:12 +00006044
Douglas Gregorb98b1992009-08-11 05:31:07 +00006045template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006046ExprResult
John McCall454feb92009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006048 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006049
Douglas Gregor43959a92009-08-20 07:17:43 +00006050 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006051 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006052 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006053 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregor43959a92009-08-20 07:17:43 +00006055 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006056 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006057 bool ExprChanged = false;
6058 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6059 DEnd = E->designators_end();
6060 D != DEnd; ++D) {
6061 if (D->isFieldDesignator()) {
6062 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6063 D->getDotLoc(),
6064 D->getFieldLoc()));
6065 continue;
6066 }
Mike Stump1eb44332009-09-09 15:08:12 +00006067
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006069 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006070 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006071 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006072
6073 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006075
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6077 ArrayExprs.push_back(Index.release());
6078 continue;
6079 }
Mike Stump1eb44332009-09-09 15:08:12 +00006080
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006082 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6084 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006085 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006086
John McCall60d7b3a2010-08-24 06:29:42 +00006087 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006088 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006089 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006090
6091 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006092 End.get(),
6093 D->getLBracketLoc(),
6094 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006095
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6097 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006098
Douglas Gregorb98b1992009-08-11 05:31:07 +00006099 ArrayExprs.push_back(Start.release());
6100 ArrayExprs.push_back(End.release());
6101 }
Mike Stump1eb44332009-09-09 15:08:12 +00006102
Douglas Gregorb98b1992009-08-11 05:31:07 +00006103 if (!getDerived().AlwaysRebuild() &&
6104 Init.get() == E->getInit() &&
6105 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006106 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006107
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6109 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006110 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111}
Mike Stump1eb44332009-09-09 15:08:12 +00006112
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006114ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006116 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006117 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006118
Douglas Gregor5557b252009-10-28 00:29:27 +00006119 // FIXME: Will we ever have proper type location here? Will we actually
6120 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121 QualType T = getDerived().TransformType(E->getType());
6122 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006123 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006124
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125 if (!getDerived().AlwaysRebuild() &&
6126 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006127 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006128
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129 return getDerived().RebuildImplicitValueInitExpr(T);
6130}
Mike Stump1eb44332009-09-09 15:08:12 +00006131
Douglas Gregorb98b1992009-08-11 05:31:07 +00006132template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006133ExprResult
John McCall454feb92009-12-08 09:21:05 +00006134TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006135 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6136 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006137 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006138
John McCall60d7b3a2010-08-24 06:29:42 +00006139 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006141 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006142
Douglas Gregorb98b1992009-08-11 05:31:07 +00006143 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006144 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006146 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006147
John McCall9ae2f072010-08-23 23:25:46 +00006148 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006149 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150}
6151
6152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006153ExprResult
John McCall454feb92009-12-08 09:21:05 +00006154TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006156 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006157 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6158 &ArgumentChanged))
6159 return ExprError();
6160
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6162 move_arg(Inits),
6163 E->getRParenLoc());
6164}
Mike Stump1eb44332009-09-09 15:08:12 +00006165
Douglas Gregorb98b1992009-08-11 05:31:07 +00006166/// \brief Transform an address-of-label expression.
6167///
6168/// By default, the transformation of an address-of-label expression always
6169/// rebuilds the expression, so that the label identifier can be resolved to
6170/// the corresponding label statement by semantic analysis.
6171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006172ExprResult
John McCall454feb92009-12-08 09:21:05 +00006173TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006174 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6175 E->getLabel());
6176 if (!LD)
6177 return ExprError();
6178
Douglas Gregorb98b1992009-08-11 05:31:07 +00006179 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006180 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181}
Mike Stump1eb44332009-09-09 15:08:12 +00006182
6183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006184ExprResult
John McCall454feb92009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006186 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006187 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6188 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006189 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006190
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191 if (!getDerived().AlwaysRebuild() &&
6192 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006193 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006194
6195 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006196 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 E->getRParenLoc());
6198}
Mike Stump1eb44332009-09-09 15:08:12 +00006199
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006201ExprResult
John McCall454feb92009-12-08 09:21:05 +00006202TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006203 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006206
John McCall60d7b3a2010-08-24 06:29:42 +00006207 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006210
John McCall60d7b3a2010-08-24 06:29:42 +00006211 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006213 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
6216 Cond.get() == E->getCond() &&
6217 LHS.get() == E->getLHS() &&
6218 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006219 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006220
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006222 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223 E->getRParenLoc());
6224}
Mike Stump1eb44332009-09-09 15:08:12 +00006225
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006227ExprResult
John McCall454feb92009-12-08 09:21:05 +00006228TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006229 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230}
6231
6232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
John McCall454feb92009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006235 switch (E->getOperator()) {
6236 case OO_New:
6237 case OO_Delete:
6238 case OO_Array_New:
6239 case OO_Array_Delete:
6240 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006241 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006242
Douglas Gregor668d6d92009-12-13 20:44:55 +00006243 case OO_Call: {
6244 // This is a call to an object's operator().
6245 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6246
6247 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006248 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006249 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006250 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006251
6252 // FIXME: Poor location information
6253 SourceLocation FakeLParenLoc
6254 = SemaRef.PP.getLocForEndOfToken(
6255 static_cast<Expr *>(Object.get())->getLocEnd());
6256
6257 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006258 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006259 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6260 Args))
6261 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006262
John McCall9ae2f072010-08-23 23:25:46 +00006263 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006264 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006265 E->getLocEnd());
6266 }
6267
6268#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6269 case OO_##Name:
6270#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6271#include "clang/Basic/OperatorKinds.def"
6272 case OO_Subscript:
6273 // Handled below.
6274 break;
6275
6276 case OO_Conditional:
6277 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006278 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006279
6280 case OO_None:
6281 case NUM_OVERLOADED_OPERATORS:
6282 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006283 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006284 }
6285
John McCall60d7b3a2010-08-24 06:29:42 +00006286 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006288 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006289
John McCall60d7b3a2010-08-24 06:29:42 +00006290 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006292 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293
John McCall60d7b3a2010-08-24 06:29:42 +00006294 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 if (E->getNumArgs() == 2) {
6296 Second = getDerived().TransformExpr(E->getArg(1));
6297 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006298 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 }
Mike Stump1eb44332009-09-09 15:08:12 +00006300
Douglas Gregorb98b1992009-08-11 05:31:07 +00006301 if (!getDerived().AlwaysRebuild() &&
6302 Callee.get() == E->getCallee() &&
6303 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006304 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006306
Douglas Gregorb98b1992009-08-11 05:31:07 +00006307 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6308 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006309 Callee.get(),
6310 First.get(),
6311 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312}
Mike Stump1eb44332009-09-09 15:08:12 +00006313
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006315ExprResult
John McCall454feb92009-12-08 09:21:05 +00006316TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6317 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006318}
Mike Stump1eb44332009-09-09 15:08:12 +00006319
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006321ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006322TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6323 // Transform the callee.
6324 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6325 if (Callee.isInvalid())
6326 return ExprError();
6327
6328 // Transform exec config.
6329 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6330 if (EC.isInvalid())
6331 return ExprError();
6332
6333 // Transform arguments.
6334 bool ArgChanged = false;
6335 ASTOwningVector<Expr*> Args(SemaRef);
6336 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6337 &ArgChanged))
6338 return ExprError();
6339
6340 if (!getDerived().AlwaysRebuild() &&
6341 Callee.get() == E->getCallee() &&
6342 !ArgChanged)
6343 return SemaRef.Owned(E);
6344
6345 // FIXME: Wrong source location information for the '('.
6346 SourceLocation FakeLParenLoc
6347 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6348 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6349 move_arg(Args),
6350 E->getRParenLoc(), EC.get());
6351}
6352
6353template<typename Derived>
6354ExprResult
John McCall454feb92009-12-08 09:21:05 +00006355TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006356 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6357 if (!Type)
6358 return ExprError();
6359
John McCall60d7b3a2010-08-24 06:29:42 +00006360 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006361 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006366 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006369
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006371 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6373 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6374 SourceLocation FakeRParenLoc
6375 = SemaRef.PP.getLocForEndOfToken(
6376 E->getSubExpr()->getSourceRange().getEnd());
6377 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006378 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006380 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 FakeRAngleLoc,
6382 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006383 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 FakeRParenLoc);
6385}
Mike Stump1eb44332009-09-09 15:08:12 +00006386
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006388ExprResult
John McCall454feb92009-12-08 09:21:05 +00006389TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6390 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391}
Mike Stump1eb44332009-09-09 15:08:12 +00006392
6393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006394ExprResult
John McCall454feb92009-12-08 09:21:05 +00006395TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6396 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006397}
6398
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006400ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006402 CXXReinterpretCastExpr *E) {
6403 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404}
Mike Stump1eb44332009-09-09 15:08:12 +00006405
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006407ExprResult
John McCall454feb92009-12-08 09:21:05 +00006408TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6409 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006410}
Mike Stump1eb44332009-09-09 15:08:12 +00006411
Douglas Gregorb98b1992009-08-11 05:31:07 +00006412template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006413ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006414TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006415 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006416 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6417 if (!Type)
6418 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006419
John McCall60d7b3a2010-08-24 06:29:42 +00006420 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006421 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006423 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006424
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006426 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006428 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006429
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006430 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006432 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 E->getRParenLoc());
6434}
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006437ExprResult
John McCall454feb92009-12-08 09:21:05 +00006438TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006440 TypeSourceInfo *TInfo
6441 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6442 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006443 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006446 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006447 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006449 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6450 E->getLocStart(),
6451 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452 E->getLocEnd());
6453 }
Mike Stump1eb44332009-09-09 15:08:12 +00006454
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 // We don't know whether the expression is potentially evaluated until
6456 // after we perform semantic analysis, so the expression is potentially
6457 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006458 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006459 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006460
John McCall60d7b3a2010-08-24 06:29:42 +00006461 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006463 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006464
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 if (!getDerived().AlwaysRebuild() &&
6466 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006467 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006468
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006469 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6470 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006471 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 E->getLocEnd());
6473}
6474
6475template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006476ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006477TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6478 if (E->isTypeOperand()) {
6479 TypeSourceInfo *TInfo
6480 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6481 if (!TInfo)
6482 return ExprError();
6483
6484 if (!getDerived().AlwaysRebuild() &&
6485 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006486 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006487
Douglas Gregor3c52a212011-03-06 17:40:41 +00006488 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006489 E->getLocStart(),
6490 TInfo,
6491 E->getLocEnd());
6492 }
6493
6494 // We don't know whether the expression is potentially evaluated until
6495 // after we perform semantic analysis, so the expression is potentially
6496 // potentially evaluated.
6497 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6498
6499 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6500 if (SubExpr.isInvalid())
6501 return ExprError();
6502
6503 if (!getDerived().AlwaysRebuild() &&
6504 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006505 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006506
6507 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6508 E->getLocStart(),
6509 SubExpr.get(),
6510 E->getLocEnd());
6511}
6512
6513template<typename Derived>
6514ExprResult
John McCall454feb92009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006516 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517}
Mike Stump1eb44332009-09-09 15:08:12 +00006518
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006520ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006522 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006523 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524}
Mike Stump1eb44332009-09-09 15:08:12 +00006525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006527ExprResult
John McCall454feb92009-12-08 09:21:05 +00006528TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006529 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6530 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6531 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006533 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006534 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregor828a1972010-01-07 23:12:05 +00006536 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537}
Mike Stump1eb44332009-09-09 15:08:12 +00006538
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006540ExprResult
John McCall454feb92009-12-08 09:21:05 +00006541TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006542 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006544 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546 if (!getDerived().AlwaysRebuild() &&
6547 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006548 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549
John McCall9ae2f072010-08-23 23:25:46 +00006550 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551}
Mike Stump1eb44332009-09-09 15:08:12 +00006552
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006554ExprResult
John McCall454feb92009-12-08 09:21:05 +00006555TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006556 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006557 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6558 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006560 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006561
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006563 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006564 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006565
Douglas Gregor036aed12009-12-23 23:03:06 +00006566 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567}
Mike Stump1eb44332009-09-09 15:08:12 +00006568
Douglas Gregorb98b1992009-08-11 05:31:07 +00006569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006570ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006571TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6572 CXXScalarValueInitExpr *E) {
6573 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6574 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006575 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006576
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006578 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006579 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006580
Douglas Gregorab6677e2010-09-08 00:15:04 +00006581 return getDerived().RebuildCXXScalarValueInitExpr(T,
6582 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006583 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584}
Mike Stump1eb44332009-09-09 15:08:12 +00006585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006587ExprResult
John McCall454feb92009-12-08 09:21:05 +00006588TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006590 TypeSourceInfo *AllocTypeInfo
6591 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6592 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006593 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006594
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006596 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006598 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006599
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600 // Transform the placement arguments (if any).
6601 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006602 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006603 if (getDerived().TransformExprs(E->getPlacementArgs(),
6604 E->getNumPlacementArgs(), true,
6605 PlacementArgs, &ArgumentChanged))
6606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregor43959a92009-08-20 07:17:43 +00006608 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006609 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006610 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6611 ConstructorArgs, &ArgumentChanged))
6612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006613
Douglas Gregor1af74512010-02-26 00:38:10 +00006614 // Transform constructor, new operator, and delete operator.
6615 CXXConstructorDecl *Constructor = 0;
6616 if (E->getConstructor()) {
6617 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006618 getDerived().TransformDecl(E->getLocStart(),
6619 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006620 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006621 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006622 }
6623
6624 FunctionDecl *OperatorNew = 0;
6625 if (E->getOperatorNew()) {
6626 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006627 getDerived().TransformDecl(E->getLocStart(),
6628 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006629 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006630 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006631 }
6632
6633 FunctionDecl *OperatorDelete = 0;
6634 if (E->getOperatorDelete()) {
6635 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006636 getDerived().TransformDecl(E->getLocStart(),
6637 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006638 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006639 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006640 }
Sean Huntc3021132010-05-05 15:23:54 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006643 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006645 Constructor == E->getConstructor() &&
6646 OperatorNew == E->getOperatorNew() &&
6647 OperatorDelete == E->getOperatorDelete() &&
6648 !ArgumentChanged) {
6649 // Mark any declarations we need as referenced.
6650 // FIXME: instantiation-specific.
6651 if (Constructor)
6652 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6653 if (OperatorNew)
6654 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6655 if (OperatorDelete)
6656 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006657 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006658 }
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006660 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006661 if (!ArraySize.get()) {
6662 // If no array size was specified, but the new expression was
6663 // instantiated with an array type (e.g., "new T" where T is
6664 // instantiated with "int[4]"), extract the outer bound from the
6665 // array type as our array size. We do this with constant and
6666 // dependently-sized array types.
6667 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6668 if (!ArrayT) {
6669 // Do nothing
6670 } else if (const ConstantArrayType *ConsArrayT
6671 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006672 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006673 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6674 ConsArrayT->getSize(),
6675 SemaRef.Context.getSizeType(),
6676 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006677 AllocType = ConsArrayT->getElementType();
6678 } else if (const DependentSizedArrayType *DepArrayT
6679 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6680 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006681 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006682 AllocType = DepArrayT->getElementType();
6683 }
6684 }
6685 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006686
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6688 E->isGlobalNew(),
6689 /*FIXME:*/E->getLocStart(),
6690 move_arg(PlacementArgs),
6691 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006692 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006693 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006694 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006695 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 /*FIXME:*/E->getLocStart(),
6697 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006698 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699}
Mike Stump1eb44332009-09-09 15:08:12 +00006700
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006702ExprResult
John McCall454feb92009-12-08 09:21:05 +00006703TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006704 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006706 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006707
Douglas Gregor1af74512010-02-26 00:38:10 +00006708 // Transform the delete operator, if known.
6709 FunctionDecl *OperatorDelete = 0;
6710 if (E->getOperatorDelete()) {
6711 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006712 getDerived().TransformDecl(E->getLocStart(),
6713 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006714 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006715 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006716 }
Sean Huntc3021132010-05-05 15:23:54 +00006717
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006719 Operand.get() == E->getArgument() &&
6720 OperatorDelete == E->getOperatorDelete()) {
6721 // Mark any declarations we need as referenced.
6722 // FIXME: instantiation-specific.
6723 if (OperatorDelete)
6724 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006725
6726 if (!E->getArgument()->isTypeDependent()) {
6727 QualType Destroyed = SemaRef.Context.getBaseElementType(
6728 E->getDestroyedType());
6729 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6730 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6731 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6732 SemaRef.LookupDestructor(Record));
6733 }
6734 }
6735
John McCall3fa5cae2010-10-26 07:05:15 +00006736 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006737 }
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6740 E->isGlobalDelete(),
6741 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006742 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743}
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006746ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006747TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006748 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006749 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006750 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006751 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006752
John McCallb3d87482010-08-24 05:47:05 +00006753 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006754 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006755 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006756 E->getOperatorLoc(),
6757 E->isArrow()? tok::arrow : tok::period,
6758 ObjectTypePtr,
6759 MayBePseudoDestructor);
6760 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006761 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006762
John McCallb3d87482010-08-24 05:47:05 +00006763 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006764 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6765 if (QualifierLoc) {
6766 QualifierLoc
6767 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6768 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006769 return ExprError();
6770 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006771 CXXScopeSpec SS;
6772 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006774 PseudoDestructorTypeStorage Destroyed;
6775 if (E->getDestroyedTypeInfo()) {
6776 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006777 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00006778 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006779 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006781 Destroyed = DestroyedTypeInfo;
6782 } else if (ObjectType->isDependentType()) {
6783 // We aren't likely to be able to resolve the identifier down to a type
6784 // now anyway, so just retain the identifier.
6785 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6786 E->getDestroyedTypeLoc());
6787 } else {
6788 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006789 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006790 *E->getDestroyedTypeIdentifier(),
6791 E->getDestroyedTypeLoc(),
6792 /*Scope=*/0,
6793 SS, ObjectTypePtr,
6794 false);
6795 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006796 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006797
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006798 Destroyed
6799 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6800 E->getDestroyedTypeLoc());
6801 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006802
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006803 TypeSourceInfo *ScopeTypeInfo = 0;
6804 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006805 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006806 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006807 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006808 }
Sean Huntc3021132010-05-05 15:23:54 +00006809
John McCall9ae2f072010-08-23 23:25:46 +00006810 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006811 E->getOperatorLoc(),
6812 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006813 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006814 ScopeTypeInfo,
6815 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006816 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006817 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006818}
Mike Stump1eb44332009-09-09 15:08:12 +00006819
Douglas Gregora71d8192009-09-04 17:36:40 +00006820template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006821ExprResult
John McCallba135432009-11-21 08:51:07 +00006822TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006823 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006824 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6825 Sema::LookupOrdinaryName);
6826
6827 // Transform all the decls.
6828 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6829 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006830 NamedDecl *InstD = static_cast<NamedDecl*>(
6831 getDerived().TransformDecl(Old->getNameLoc(),
6832 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006833 if (!InstD) {
6834 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6835 // This can happen because of dependent hiding.
6836 if (isa<UsingShadowDecl>(*I))
6837 continue;
6838 else
John McCallf312b1e2010-08-26 23:41:50 +00006839 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006840 }
John McCallf7a1a742009-11-24 19:00:30 +00006841
6842 // Expand using declarations.
6843 if (isa<UsingDecl>(InstD)) {
6844 UsingDecl *UD = cast<UsingDecl>(InstD);
6845 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6846 E = UD->shadow_end(); I != E; ++I)
6847 R.addDecl(*I);
6848 continue;
6849 }
6850
6851 R.addDecl(InstD);
6852 }
6853
6854 // Resolve a kind, but don't do any further analysis. If it's
6855 // ambiguous, the callee needs to deal with it.
6856 R.resolveKind();
6857
6858 // Rebuild the nested-name qualifier, if present.
6859 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00006860 if (Old->getQualifierLoc()) {
6861 NestedNameSpecifierLoc QualifierLoc
6862 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6863 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006864 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006865
Douglas Gregor4c9be892011-02-28 20:01:57 +00006866 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00006867 }
6868
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006869 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006870 CXXRecordDecl *NamingClass
6871 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6872 Old->getNameLoc(),
6873 Old->getNamingClass()));
6874 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006875 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006876
Douglas Gregor66c45152010-04-27 16:10:10 +00006877 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006878 }
6879
6880 // If we have no template arguments, it's a normal declaration name.
6881 if (!Old->hasExplicitTemplateArgs())
6882 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6883
6884 // If we have template arguments, rebuild them, then rebuild the
6885 // templateid expression.
6886 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006887 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6888 Old->getNumTemplateArgs(),
6889 TransArgs))
6890 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006891
6892 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6893 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894}
Mike Stump1eb44332009-09-09 15:08:12 +00006895
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006897ExprResult
John McCall454feb92009-12-08 09:21:05 +00006898TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006899 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6900 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006902
Douglas Gregorb98b1992009-08-11 05:31:07 +00006903 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006904 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006905 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006906
Mike Stump1eb44332009-09-09 15:08:12 +00006907 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006909 T,
6910 E->getLocEnd());
6911}
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006915TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6916 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6917 if (!LhsT)
6918 return ExprError();
6919
6920 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6921 if (!RhsT)
6922 return ExprError();
6923
6924 if (!getDerived().AlwaysRebuild() &&
6925 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6926 return SemaRef.Owned(E);
6927
6928 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6929 E->getLocStart(),
6930 LhsT, RhsT,
6931 E->getLocEnd());
6932}
6933
6934template<typename Derived>
6935ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00006936TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
6937 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6938 if (!T)
6939 return ExprError();
6940
6941 if (!getDerived().AlwaysRebuild() &&
6942 T == E->getQueriedTypeSourceInfo())
6943 return SemaRef.Owned(E);
6944
6945 ExprResult SubExpr;
6946 {
6947 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6948 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
6949 if (SubExpr.isInvalid())
6950 return ExprError();
6951
6952 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
6953 return SemaRef.Owned(E);
6954 }
6955
6956 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
6957 E->getLocStart(),
6958 T,
6959 SubExpr.get(),
6960 E->getLocEnd());
6961}
6962
6963template<typename Derived>
6964ExprResult
John Wiegley55262202011-04-25 06:54:41 +00006965TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
6966 ExprResult SubExpr;
6967 {
6968 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6969 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
6970 if (SubExpr.isInvalid())
6971 return ExprError();
6972
6973 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
6974 return SemaRef.Owned(E);
6975 }
6976
6977 return getDerived().RebuildExpressionTrait(
6978 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
6979}
6980
6981template<typename Derived>
6982ExprResult
John McCall865d4472009-11-19 22:55:06 +00006983TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006984 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006985 NestedNameSpecifierLoc QualifierLoc
6986 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6987 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006988 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006989
John McCall43fed0d2010-11-12 08:19:04 +00006990 // TODO: If this is a conversion-function-id, verify that the
6991 // destination type name (if present) resolves the same way after
6992 // instantiation as it did in the local scope.
6993
Abramo Bagnara25777432010-08-11 22:01:17 +00006994 DeclarationNameInfo NameInfo
6995 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6996 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006997 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006998
John McCallf7a1a742009-11-24 19:00:30 +00006999 if (!E->hasExplicitTemplateArgs()) {
7000 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007001 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007002 // Note: it is sufficient to compare the Name component of NameInfo:
7003 // if name has not changed, DNLoc has not changed either.
7004 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007005 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007007 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007008 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007009 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007010 }
John McCalld5532b62009-11-23 01:53:49 +00007011
7012 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007013 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7014 E->getNumTemplateArgs(),
7015 TransArgs))
7016 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007018 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007019 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007020 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021}
7022
7023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007024ExprResult
John McCall454feb92009-12-08 09:21:05 +00007025TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007026 // CXXConstructExprs are always implicit, so when we have a
7027 // 1-argument construction we just transform that argument.
7028 if (E->getNumArgs() == 1 ||
7029 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7030 return getDerived().TransformExpr(E->getArg(0));
7031
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7033
7034 QualType T = getDerived().TransformType(E->getType());
7035 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007036 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037
7038 CXXConstructorDecl *Constructor
7039 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007040 getDerived().TransformDecl(E->getLocStart(),
7041 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007043 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007044
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007046 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007047 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7048 &ArgumentChanged))
7049 return ExprError();
7050
Douglas Gregorb98b1992009-08-11 05:31:07 +00007051 if (!getDerived().AlwaysRebuild() &&
7052 T == E->getType() &&
7053 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007054 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007055 // Mark the constructor as referenced.
7056 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007057 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007058 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007059 }
Mike Stump1eb44332009-09-09 15:08:12 +00007060
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007061 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7062 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007063 move_arg(Args),
7064 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007065 E->getConstructionKind(),
7066 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067}
Mike Stump1eb44332009-09-09 15:08:12 +00007068
Douglas Gregorb98b1992009-08-11 05:31:07 +00007069/// \brief Transform a C++ temporary-binding expression.
7070///
Douglas Gregor51326552009-12-24 18:51:59 +00007071/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7072/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007074ExprResult
John McCall454feb92009-12-08 09:21:05 +00007075TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007076 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007077}
Mike Stump1eb44332009-09-09 15:08:12 +00007078
John McCall4765fa02010-12-06 08:20:24 +00007079/// \brief Transform a C++ expression that contains cleanups that should
7080/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007081///
John McCall4765fa02010-12-06 08:20:24 +00007082/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007083/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007085ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007086TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007087 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007088}
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregorb98b1992009-08-11 05:31:07 +00007090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007091ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007092TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007093 CXXTemporaryObjectExpr *E) {
7094 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7095 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007096 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007097
Douglas Gregorb98b1992009-08-11 05:31:07 +00007098 CXXConstructorDecl *Constructor
7099 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007100 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007101 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007102 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007103 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007104
Douglas Gregorb98b1992009-08-11 05:31:07 +00007105 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007106 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007107 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007108 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7109 &ArgumentChanged))
7110 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007111
Douglas Gregorb98b1992009-08-11 05:31:07 +00007112 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007113 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007115 !ArgumentChanged) {
7116 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007117 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007118 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007119 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007120
7121 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7122 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007124 E->getLocEnd());
7125}
Mike Stump1eb44332009-09-09 15:08:12 +00007126
Douglas Gregorb98b1992009-08-11 05:31:07 +00007127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007128ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007129TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007130 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007131 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7132 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007133 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007134
Douglas Gregorb98b1992009-08-11 05:31:07 +00007135 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007136 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007137 Args.reserve(E->arg_size());
7138 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7139 &ArgumentChanged))
7140 return ExprError();
7141
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007143 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007148 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149 E->getLParenLoc(),
7150 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007151 E->getRParenLoc());
7152}
Mike Stump1eb44332009-09-09 15:08:12 +00007153
Douglas Gregorb98b1992009-08-11 05:31:07 +00007154template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007155ExprResult
John McCall865d4472009-11-19 22:55:06 +00007156TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007157 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007158 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007159 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007160 Expr *OldBase;
7161 QualType BaseType;
7162 QualType ObjectType;
7163 if (!E->isImplicitAccess()) {
7164 OldBase = E->getBase();
7165 Base = getDerived().TransformExpr(OldBase);
7166 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007167 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007168
John McCallaa81e162009-12-01 22:10:20 +00007169 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007170 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007171 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007172 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007173 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007174 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007175 ObjectTy,
7176 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007177 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007178 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007179
John McCallb3d87482010-08-24 05:47:05 +00007180 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007181 BaseType = ((Expr*) Base.get())->getType();
7182 } else {
7183 OldBase = 0;
7184 BaseType = getDerived().TransformType(E->getBaseType());
7185 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7186 }
Mike Stump1eb44332009-09-09 15:08:12 +00007187
Douglas Gregor6cd21982009-10-20 05:58:46 +00007188 // Transform the first part of the nested-name-specifier that qualifies
7189 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007190 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007191 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007192 E->getFirstQualifierFoundInScope(),
7193 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007194
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007195 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007196 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007197 QualifierLoc
7198 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7199 ObjectType,
7200 FirstQualifierInScope);
7201 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007202 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007203 }
Mike Stump1eb44332009-09-09 15:08:12 +00007204
John McCall43fed0d2010-11-12 08:19:04 +00007205 // TODO: If this is a conversion-function-id, verify that the
7206 // destination type name (if present) resolves the same way after
7207 // instantiation as it did in the local scope.
7208
Abramo Bagnara25777432010-08-11 22:01:17 +00007209 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007210 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007211 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007213
John McCallaa81e162009-12-01 22:10:20 +00007214 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007215 // This is a reference to a member without an explicitly-specified
7216 // template argument list. Optimize for this common case.
7217 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007218 Base.get() == OldBase &&
7219 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007220 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007221 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007222 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007223 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007224
John McCall9ae2f072010-08-23 23:25:46 +00007225 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007226 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007227 E->isArrow(),
7228 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007229 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007230 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007231 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007232 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007233 }
7234
John McCalld5532b62009-11-23 01:53:49 +00007235 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007236 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7237 E->getNumTemplateArgs(),
7238 TransArgs))
7239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007240
John McCall9ae2f072010-08-23 23:25:46 +00007241 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007242 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007243 E->isArrow(),
7244 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007245 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007246 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007247 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007248 &TransArgs);
7249}
7250
7251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007252ExprResult
John McCall454feb92009-12-08 09:21:05 +00007253TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007254 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007255 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007256 QualType BaseType;
7257 if (!Old->isImplicitAccess()) {
7258 Base = getDerived().TransformExpr(Old->getBase());
7259 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007260 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007261 BaseType = ((Expr*) Base.get())->getType();
7262 } else {
7263 BaseType = getDerived().TransformType(Old->getBaseType());
7264 }
John McCall129e2df2009-11-30 22:42:35 +00007265
Douglas Gregor4c9be892011-02-28 20:01:57 +00007266 NestedNameSpecifierLoc QualifierLoc;
7267 if (Old->getQualifierLoc()) {
7268 QualifierLoc
7269 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7270 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007271 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007272 }
7273
Abramo Bagnara25777432010-08-11 22:01:17 +00007274 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007275 Sema::LookupOrdinaryName);
7276
7277 // Transform all the decls.
7278 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7279 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007280 NamedDecl *InstD = static_cast<NamedDecl*>(
7281 getDerived().TransformDecl(Old->getMemberLoc(),
7282 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007283 if (!InstD) {
7284 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7285 // This can happen because of dependent hiding.
7286 if (isa<UsingShadowDecl>(*I))
7287 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007288 else {
7289 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007290 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007291 }
John McCall9f54ad42009-12-10 09:41:52 +00007292 }
John McCall129e2df2009-11-30 22:42:35 +00007293
7294 // Expand using declarations.
7295 if (isa<UsingDecl>(InstD)) {
7296 UsingDecl *UD = cast<UsingDecl>(InstD);
7297 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7298 E = UD->shadow_end(); I != E; ++I)
7299 R.addDecl(*I);
7300 continue;
7301 }
7302
7303 R.addDecl(InstD);
7304 }
7305
7306 R.resolveKind();
7307
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007308 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007309 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007310 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007311 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007312 Old->getMemberLoc(),
7313 Old->getNamingClass()));
7314 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007315 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007316
Douglas Gregor66c45152010-04-27 16:10:10 +00007317 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007318 }
Sean Huntc3021132010-05-05 15:23:54 +00007319
John McCall129e2df2009-11-30 22:42:35 +00007320 TemplateArgumentListInfo TransArgs;
7321 if (Old->hasExplicitTemplateArgs()) {
7322 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7323 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007324 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7325 Old->getNumTemplateArgs(),
7326 TransArgs))
7327 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007328 }
John McCallc2233c52010-01-15 08:34:02 +00007329
7330 // FIXME: to do this check properly, we will need to preserve the
7331 // first-qualifier-in-scope here, just in case we had a dependent
7332 // base (and therefore couldn't do the check) and a
7333 // nested-name-qualifier (and therefore could do the lookup).
7334 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007335
John McCall9ae2f072010-08-23 23:25:46 +00007336 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007337 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007338 Old->getOperatorLoc(),
7339 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007340 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007341 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007342 R,
7343 (Old->hasExplicitTemplateArgs()
7344 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007345}
7346
7347template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007348ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007349TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7350 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7351 if (SubExpr.isInvalid())
7352 return ExprError();
7353
7354 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007355 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007356
7357 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7358}
7359
7360template<typename Derived>
7361ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007362TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007363 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7364 if (Pattern.isInvalid())
7365 return ExprError();
7366
7367 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7368 return SemaRef.Owned(E);
7369
Douglas Gregor67fd1252011-01-14 21:20:45 +00007370 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7371 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007372}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007373
7374template<typename Derived>
7375ExprResult
7376TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7377 // If E is not value-dependent, then nothing will change when we transform it.
7378 // Note: This is an instantiation-centric view.
7379 if (!E->isValueDependent())
7380 return SemaRef.Owned(E);
7381
7382 // Note: None of the implementations of TryExpandParameterPacks can ever
7383 // produce a diagnostic when given only a single unexpanded parameter pack,
7384 // so
7385 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7386 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007387 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007388 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007389 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7390 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007391 ShouldExpand, RetainExpansion,
7392 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007393 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007394
Douglas Gregord3731192011-01-10 07:32:04 +00007395 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007396 return SemaRef.Owned(E);
7397
7398 // We now know the length of the parameter pack, so build a new expression
7399 // that stores that length.
7400 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7401 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007402 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007403}
7404
Douglas Gregorbe230c32011-01-03 17:17:50 +00007405template<typename Derived>
7406ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007407TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7408 SubstNonTypeTemplateParmPackExpr *E) {
7409 // Default behavior is to do nothing with this transformation.
7410 return SemaRef.Owned(E);
7411}
7412
7413template<typename Derived>
7414ExprResult
John McCall454feb92009-12-08 09:21:05 +00007415TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007416 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417}
7418
Mike Stump1eb44332009-09-09 15:08:12 +00007419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007420ExprResult
John McCall454feb92009-12-08 09:21:05 +00007421TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007422 TypeSourceInfo *EncodedTypeInfo
7423 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7424 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007425 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007426
Douglas Gregorb98b1992009-08-11 05:31:07 +00007427 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007428 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007429 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430
7431 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007432 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433 E->getRParenLoc());
7434}
Mike Stump1eb44332009-09-09 15:08:12 +00007435
Douglas Gregorb98b1992009-08-11 05:31:07 +00007436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007437ExprResult
John McCall454feb92009-12-08 09:21:05 +00007438TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007439 // Transform arguments.
7440 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007441 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007442 Args.reserve(E->getNumArgs());
7443 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7444 &ArgChanged))
7445 return ExprError();
7446
Douglas Gregor92e986e2010-04-22 16:44:27 +00007447 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7448 // Class message: transform the receiver type.
7449 TypeSourceInfo *ReceiverTypeInfo
7450 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7451 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007452 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007453
Douglas Gregor92e986e2010-04-22 16:44:27 +00007454 // If nothing changed, just retain the existing message send.
7455 if (!getDerived().AlwaysRebuild() &&
7456 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007457 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007458
7459 // Build a new class message send.
7460 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7461 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007462 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007463 E->getMethodDecl(),
7464 E->getLeftLoc(),
7465 move_arg(Args),
7466 E->getRightLoc());
7467 }
7468
7469 // Instance message: transform the receiver
7470 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7471 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007472 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007473 = getDerived().TransformExpr(E->getInstanceReceiver());
7474 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007475 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007476
7477 // If nothing changed, just retain the existing message send.
7478 if (!getDerived().AlwaysRebuild() &&
7479 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007480 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007481
Douglas Gregor92e986e2010-04-22 16:44:27 +00007482 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007483 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007484 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007485 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007486 E->getMethodDecl(),
7487 E->getLeftLoc(),
7488 move_arg(Args),
7489 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490}
7491
Mike Stump1eb44332009-09-09 15:08:12 +00007492template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007493ExprResult
John McCall454feb92009-12-08 09:21:05 +00007494TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007495 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007496}
7497
Mike Stump1eb44332009-09-09 15:08:12 +00007498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007499ExprResult
John McCall454feb92009-12-08 09:21:05 +00007500TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007501 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502}
7503
Mike Stump1eb44332009-09-09 15:08:12 +00007504template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007505ExprResult
John McCall454feb92009-12-08 09:21:05 +00007506TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007507 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007508 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007509 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007510 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007511
7512 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007513
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007514 // If nothing changed, just retain the existing expression.
7515 if (!getDerived().AlwaysRebuild() &&
7516 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007517 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007518
John McCall9ae2f072010-08-23 23:25:46 +00007519 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007520 E->getLocation(),
7521 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007522}
7523
Mike Stump1eb44332009-09-09 15:08:12 +00007524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007525ExprResult
John McCall454feb92009-12-08 09:21:05 +00007526TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007527 // 'super' and types never change. Property never changes. Just
7528 // retain the existing expression.
7529 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007530 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007531
Douglas Gregore3303542010-04-26 20:47:02 +00007532 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007533 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007534 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007535 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007536
Douglas Gregore3303542010-04-26 20:47:02 +00007537 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007538
Douglas Gregore3303542010-04-26 20:47:02 +00007539 // If nothing changed, just retain the existing expression.
7540 if (!getDerived().AlwaysRebuild() &&
7541 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007542 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007543
John McCall12f78a62010-12-02 01:19:52 +00007544 if (E->isExplicitProperty())
7545 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7546 E->getExplicitProperty(),
7547 E->getLocation());
7548
7549 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7550 E->getType(),
7551 E->getImplicitPropertyGetter(),
7552 E->getImplicitPropertySetter(),
7553 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554}
7555
Mike Stump1eb44332009-09-09 15:08:12 +00007556template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007557ExprResult
John McCall454feb92009-12-08 09:21:05 +00007558TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007559 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007560 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007561 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007562 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007563
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007564 // If nothing changed, just retain the existing expression.
7565 if (!getDerived().AlwaysRebuild() &&
7566 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007567 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007568
John McCall9ae2f072010-08-23 23:25:46 +00007569 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007570 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007571}
7572
Mike Stump1eb44332009-09-09 15:08:12 +00007573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007574ExprResult
John McCall454feb92009-12-08 09:21:05 +00007575TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007576 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007577 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007578 SubExprs.reserve(E->getNumSubExprs());
7579 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7580 SubExprs, &ArgumentChanged))
7581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007582
Douglas Gregorb98b1992009-08-11 05:31:07 +00007583 if (!getDerived().AlwaysRebuild() &&
7584 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007586
Douglas Gregorb98b1992009-08-11 05:31:07 +00007587 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7588 move_arg(SubExprs),
7589 E->getRParenLoc());
7590}
7591
Mike Stump1eb44332009-09-09 15:08:12 +00007592template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007593ExprResult
John McCall454feb92009-12-08 09:21:05 +00007594TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007595 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007596
John McCallc6ac9c32011-02-04 18:33:18 +00007597 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7598 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7599
7600 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7601 llvm::SmallVector<ParmVarDecl*, 4> params;
7602 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007603
7604 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007605 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7606 oldBlock->param_begin(),
7607 oldBlock->param_size(),
7608 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007609 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007610
7611 const FunctionType *exprFunctionType = E->getFunctionType();
7612 QualType exprResultType = exprFunctionType->getResultType();
7613 if (!exprResultType.isNull()) {
7614 if (!exprResultType->isDependentType())
7615 blockScope->ReturnType = exprResultType;
7616 else if (exprResultType != getSema().Context.DependentTy)
7617 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007618 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007619
7620 // If the return type has not been determined yet, leave it as a dependent
7621 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007622 if (blockScope->ReturnType.isNull())
7623 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007624
7625 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007626 if (blockScope->ReturnType->isObjCObjectType()) {
7627 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007628 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007629 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007630 return ExprError();
7631 }
John McCall711c52b2011-01-05 12:14:39 +00007632
John McCallc6ac9c32011-02-04 18:33:18 +00007633 QualType functionType = getDerived().RebuildFunctionProtoType(
7634 blockScope->ReturnType,
7635 paramTypes.data(),
7636 paramTypes.size(),
7637 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007638 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007639 exprFunctionType->getExtInfo());
7640 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007641
7642 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007643 if (!params.empty())
7644 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007645
7646 // If the return type wasn't explicitly set, it will have been marked as a
7647 // dependent type (DependentTy); clear out the return type setting so
7648 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007649 if (blockScope->ReturnType == getSema().Context.DependentTy)
7650 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007651
John McCall711c52b2011-01-05 12:14:39 +00007652 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007653 StmtResult body = getDerived().TransformStmt(E->getBody());
7654 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007655 return ExprError();
7656
John McCallc6ac9c32011-02-04 18:33:18 +00007657#ifndef NDEBUG
7658 // In builds with assertions, make sure that we captured everything we
7659 // captured before.
7660
7661 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7662
7663 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7664 e = oldBlock->capture_end(); i != e; ++i) {
John McCall6b5a61b2011-02-07 10:33:21 +00007665 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007666
7667 // Ignore parameter packs.
7668 if (isa<ParmVarDecl>(oldCapture) &&
7669 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7670 continue;
7671
7672 VarDecl *newCapture =
7673 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7674 oldCapture));
John McCall6b5a61b2011-02-07 10:33:21 +00007675 assert(blockScope->CaptureMap.count(newCapture));
John McCallc6ac9c32011-02-04 18:33:18 +00007676 }
7677#endif
7678
7679 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7680 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007681}
7682
Mike Stump1eb44332009-09-09 15:08:12 +00007683template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007684ExprResult
John McCall454feb92009-12-08 09:21:05 +00007685TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007686 ValueDecl *ND
7687 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7688 E->getDecl()));
7689 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007690 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007691
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007692 if (!getDerived().AlwaysRebuild() &&
7693 ND == E->getDecl()) {
7694 // Mark it referenced in the new context regardless.
7695 // FIXME: this is a bit instantiation-specific.
7696 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7697
John McCall3fa5cae2010-10-26 07:05:15 +00007698 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007699 }
7700
Abramo Bagnara25777432010-08-11 22:01:17 +00007701 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007702 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007703 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007704}
Mike Stump1eb44332009-09-09 15:08:12 +00007705
Douglas Gregorb98b1992009-08-11 05:31:07 +00007706//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007707// Type reconstruction
7708//===----------------------------------------------------------------------===//
7709
Mike Stump1eb44332009-09-09 15:08:12 +00007710template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007711QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7712 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007713 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007714 getDerived().getBaseEntity());
7715}
7716
Mike Stump1eb44332009-09-09 15:08:12 +00007717template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007718QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7719 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007720 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007721 getDerived().getBaseEntity());
7722}
7723
Mike Stump1eb44332009-09-09 15:08:12 +00007724template<typename Derived>
7725QualType
John McCall85737a72009-10-30 00:06:24 +00007726TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7727 bool WrittenAsLValue,
7728 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007729 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007730 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007731}
7732
7733template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007734QualType
John McCall85737a72009-10-30 00:06:24 +00007735TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7736 QualType ClassType,
7737 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007738 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007739 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007740}
7741
7742template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007743QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007744TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7745 ArrayType::ArraySizeModifier SizeMod,
7746 const llvm::APInt *Size,
7747 Expr *SizeExpr,
7748 unsigned IndexTypeQuals,
7749 SourceRange BracketsRange) {
7750 if (SizeExpr || !Size)
7751 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7752 IndexTypeQuals, BracketsRange,
7753 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007754
7755 QualType Types[] = {
7756 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7757 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7758 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007759 };
7760 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7761 QualType SizeType;
7762 for (unsigned I = 0; I != NumTypes; ++I)
7763 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7764 SizeType = Types[I];
7765 break;
7766 }
Mike Stump1eb44332009-09-09 15:08:12 +00007767
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007768 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7769 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007770 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007771 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007772 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007773}
Mike Stump1eb44332009-09-09 15:08:12 +00007774
Douglas Gregor577f75a2009-08-04 16:50:30 +00007775template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007776QualType
7777TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007778 ArrayType::ArraySizeModifier SizeMod,
7779 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007780 unsigned IndexTypeQuals,
7781 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007782 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007783 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007784}
7785
7786template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007787QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007788TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007789 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007790 unsigned IndexTypeQuals,
7791 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007792 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007793 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007794}
Mike Stump1eb44332009-09-09 15:08:12 +00007795
Douglas Gregor577f75a2009-08-04 16:50:30 +00007796template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007797QualType
7798TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007799 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007800 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007801 unsigned IndexTypeQuals,
7802 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007803 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007804 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007805 IndexTypeQuals, BracketsRange);
7806}
7807
7808template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007809QualType
7810TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007811 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007812 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007813 unsigned IndexTypeQuals,
7814 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007815 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007816 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007817 IndexTypeQuals, BracketsRange);
7818}
7819
7820template<typename Derived>
7821QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007822 unsigned NumElements,
7823 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007824 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007825 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007826}
Mike Stump1eb44332009-09-09 15:08:12 +00007827
Douglas Gregor577f75a2009-08-04 16:50:30 +00007828template<typename Derived>
7829QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7830 unsigned NumElements,
7831 SourceLocation AttributeLoc) {
7832 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7833 NumElements, true);
7834 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007835 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7836 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007837 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007838}
Mike Stump1eb44332009-09-09 15:08:12 +00007839
Douglas Gregor577f75a2009-08-04 16:50:30 +00007840template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007841QualType
7842TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007843 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007844 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007845 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007846}
Mike Stump1eb44332009-09-09 15:08:12 +00007847
Douglas Gregor577f75a2009-08-04 16:50:30 +00007848template<typename Derived>
7849QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007850 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007851 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007852 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007853 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007854 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007855 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007856 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007857 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007858 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007859 getDerived().getBaseEntity(),
7860 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007861}
Mike Stump1eb44332009-09-09 15:08:12 +00007862
Douglas Gregor577f75a2009-08-04 16:50:30 +00007863template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007864QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7865 return SemaRef.Context.getFunctionNoProtoType(T);
7866}
7867
7868template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007869QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7870 assert(D && "no decl found");
7871 if (D->isInvalidDecl()) return QualType();
7872
Douglas Gregor92e986e2010-04-22 16:44:27 +00007873 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007874 TypeDecl *Ty;
7875 if (isa<UsingDecl>(D)) {
7876 UsingDecl *Using = cast<UsingDecl>(D);
7877 assert(Using->isTypeName() &&
7878 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7879
7880 // A valid resolved using typename decl points to exactly one type decl.
7881 assert(++Using->shadow_begin() == Using->shadow_end());
7882 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007883
John McCalled976492009-12-04 22:46:56 +00007884 } else {
7885 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7886 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7887 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7888 }
7889
7890 return SemaRef.Context.getTypeDeclType(Ty);
7891}
7892
7893template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007894QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7895 SourceLocation Loc) {
7896 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007897}
7898
7899template<typename Derived>
7900QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7901 return SemaRef.Context.getTypeOfType(Underlying);
7902}
7903
7904template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007905QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7906 SourceLocation Loc) {
7907 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007908}
7909
7910template<typename Derived>
7911QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007912 TemplateName Template,
7913 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00007914 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00007915 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007916}
Mike Stump1eb44332009-09-09 15:08:12 +00007917
Douglas Gregordcee1a12009-08-06 05:28:30 +00007918template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007919TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007920TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00007921 bool TemplateKW,
7922 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007923 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007924 Template);
7925}
7926
7927template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007928TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007929TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
7930 const IdentifierInfo &Name,
7931 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00007932 QualType ObjectType,
7933 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007934 UnqualifiedId TemplateName;
7935 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007936 Sema::TemplateTy Template;
7937 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007938 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007939 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007940 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00007941 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007942 /*EnteringContext=*/false,
7943 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007944 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007945}
Mike Stump1eb44332009-09-09 15:08:12 +00007946
Douglas Gregorb98b1992009-08-11 05:31:07 +00007947template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007948TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007949TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007950 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007951 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007952 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007953 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007954 // FIXME: Bogus location information.
7955 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
7956 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007957 Sema::TemplateTy Template;
7958 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007959 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007960 SS,
7961 Name,
John McCallb3d87482010-08-24 05:47:05 +00007962 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007963 /*EnteringContext=*/false,
7964 Template);
7965 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007966}
Sean Huntc3021132010-05-05 15:23:54 +00007967
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007969ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007970TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7971 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007972 Expr *OrigCallee,
7973 Expr *First,
7974 Expr *Second) {
7975 Expr *Callee = OrigCallee->IgnoreParenCasts();
7976 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007977
Douglas Gregorb98b1992009-08-11 05:31:07 +00007978 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007979 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007980 if (!First->getType()->isOverloadableType() &&
7981 !Second->getType()->isOverloadableType())
7982 return getSema().CreateBuiltinArraySubscriptExpr(First,
7983 Callee->getLocStart(),
7984 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007985 } else if (Op == OO_Arrow) {
7986 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007987 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7988 } else if (Second == 0 || isPostIncDec) {
7989 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007990 // The argument is not of overloadable type, so try to create a
7991 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007992 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007994
John McCall9ae2f072010-08-23 23:25:46 +00007995 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996 }
7997 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007998 if (!First->getType()->isOverloadableType() &&
7999 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008000 // Neither of the arguments is an overloadable type, so try to
8001 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008002 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008003 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008004 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008005 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008006 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008007
Douglas Gregorb98b1992009-08-11 05:31:07 +00008008 return move(Result);
8009 }
8010 }
Mike Stump1eb44332009-09-09 15:08:12 +00008011
8012 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008013 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008014 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008015
John McCall9ae2f072010-08-23 23:25:46 +00008016 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008017 assert(ULE->requiresADL());
8018
8019 // FIXME: Do we have to check
8020 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008021 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008022 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008023 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008024 }
Mike Stump1eb44332009-09-09 15:08:12 +00008025
Douglas Gregorb98b1992009-08-11 05:31:07 +00008026 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008027 Expr *Args[2] = { First, Second };
8028 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008029
Douglas Gregorb98b1992009-08-11 05:31:07 +00008030 // Create the overloaded operator invocation for unary operators.
8031 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008032 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008033 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008034 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008035 }
Mike Stump1eb44332009-09-09 15:08:12 +00008036
Sebastian Redlf322ed62009-10-29 20:17:01 +00008037 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00008038 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00008039 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008040 First,
8041 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00008042
Douglas Gregorb98b1992009-08-11 05:31:07 +00008043 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008044 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008045 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008046 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8047 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008048 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008049
Mike Stump1eb44332009-09-09 15:08:12 +00008050 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008051}
Mike Stump1eb44332009-09-09 15:08:12 +00008052
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008053template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008054ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008055TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008056 SourceLocation OperatorLoc,
8057 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008058 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008059 TypeSourceInfo *ScopeType,
8060 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008061 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008062 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008063 QualType BaseType = Base->getType();
8064 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008065 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008066 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008067 !BaseType->getAs<PointerType>()->getPointeeType()
8068 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008069 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008070 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008071 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008072 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008073 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008074 /*FIXME?*/true);
8075 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008076
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008077 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008078 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8079 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8080 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8081 NameInfo.setNamedTypeInfo(DestroyedType);
8082
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008083 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008084
John McCall9ae2f072010-08-23 23:25:46 +00008085 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008086 OperatorLoc, isArrow,
8087 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008088 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008089 /*TemplateArgs*/ 0);
8090}
8091
Douglas Gregor577f75a2009-08-04 16:50:30 +00008092} // end namespace clang
8093
8094#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H