blob: 8f875fbef0203cfa6e9b63709b4a1b0f5f340617 [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 Gregor577f75a2009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas 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 Gregor577f75a2009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000387
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregor81499bb2009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000407
Douglas Gregor577f75a2009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000409 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000416
Douglas Gregor577f75a2009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregorfcc12532010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000470
John McCall833ca992009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCalla93c9342009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump1eb44332009-09-09 15:08:12 +0000480
John McCalla2becad2009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000485
John McCall43fed0d2010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregora88f09f2011-02-28 17:23:35 +0000494 TemplateName Template);
495
496 QualType
497 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
498 DependentTemplateSpecializationTypeLoc TL,
John McCall43fed0d2010-11-12 08:19:04 +0000499 NestedNameSpecifier *Prefix);
500
John McCall21ef0fa2010-03-11 09:03:00 +0000501 /// \brief Transforms the parameters of a function type into the
502 /// given vectors.
503 ///
504 /// The result vectors should be kept in sync; null entries in the
505 /// variables vector are acceptable.
506 ///
507 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000508 bool TransformFunctionTypeParams(SourceLocation Loc,
509 ParmVarDecl **Params, unsigned NumParams,
510 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000511 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000512 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000513
514 /// \brief Transforms a single function-type parameter. Return null
515 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000516 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
517 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000518
John McCall43fed0d2010-11-12 08:19:04 +0000519 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000520
John McCall60d7b3a2010-08-24 06:29:42 +0000521 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
522 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000523
Douglas Gregor43959a92009-08-20 07:17:43 +0000524#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000525 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000526#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000527 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000528#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000529#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 /// \brief Build a new pointer type given its pointee type.
532 ///
533 /// By default, performs semantic analysis when building the pointer type.
534 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000535 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000536
537 /// \brief Build a new block pointer type given its pointee type.
538 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000539 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000540 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000541 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000542
John McCall85737a72009-10-30 00:06:24 +0000543 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544 ///
John McCall85737a72009-10-30 00:06:24 +0000545 /// By default, performs semantic analysis when building the
546 /// reference type. Subclasses may override this routine to provide
547 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 ///
John McCall85737a72009-10-30 00:06:24 +0000549 /// \param LValue whether the type was written with an lvalue sigil
550 /// or an rvalue sigil.
551 QualType RebuildReferenceType(QualType ReferentType,
552 bool LValue,
553 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000554
Douglas Gregor577f75a2009-08-04 16:50:30 +0000555 /// \brief Build a new member pointer type given the pointee type and the
556 /// class type it refers into.
557 ///
558 /// By default, performs semantic analysis when building the member pointer
559 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000560 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
561 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000562
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563 /// \brief Build a new array type given the element type, size
564 /// modifier, size of the array (if known), size expression, and index type
565 /// qualifiers.
566 ///
567 /// By default, performs semantic analysis when building the array type.
568 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000569 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 QualType RebuildArrayType(QualType ElementType,
571 ArrayType::ArraySizeModifier SizeMod,
572 const llvm::APInt *Size,
573 Expr *SizeExpr,
574 unsigned IndexTypeQuals,
575 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000576
Douglas Gregor577f75a2009-08-04 16:50:30 +0000577 /// \brief Build a new constant array type given the element type, size
578 /// modifier, (known) size of the array, and index type qualifiers.
579 ///
580 /// By default, performs semantic analysis when building the array type.
581 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000582 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000583 ArrayType::ArraySizeModifier SizeMod,
584 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000585 unsigned IndexTypeQuals,
586 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// \brief Build a new incomplete array type given the element type, size
589 /// modifier, and index type qualifiers.
590 ///
591 /// By default, performs semantic analysis when building the array type.
592 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000593 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000595 unsigned IndexTypeQuals,
596 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000597
Mike Stump1eb44332009-09-09 15:08:12 +0000598 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 /// size modifier, size expression, and index type qualifiers.
600 ///
601 /// By default, performs semantic analysis when building the array type.
602 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000603 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000605 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000606 unsigned IndexTypeQuals,
607 SourceRange BracketsRange);
608
Mike Stump1eb44332009-09-09 15:08:12 +0000609 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 /// size modifier, size expression, and index type qualifiers.
611 ///
612 /// By default, performs semantic analysis when building the array type.
613 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000614 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000616 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000617 unsigned IndexTypeQuals,
618 SourceRange BracketsRange);
619
620 /// \brief Build a new vector type given the element type and
621 /// number of elements.
622 ///
623 /// By default, performs semantic analysis when building the vector type.
624 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000625 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000626 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000627
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628 /// \brief Build a new extended 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.
633 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
634 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
636 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000637 /// given the element type and 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.
Mike Stump1eb44332009-09-09 15:08:12 +0000641 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000642 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000643 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new function type.
646 ///
647 /// By default, performs semantic analysis when building the function type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000650 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000651 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000652 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000653 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000654 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000655
John McCalla2becad2009-10-21 00:40:46 +0000656 /// \brief Build a new unprototyped function type.
657 QualType RebuildFunctionNoProtoType(QualType ResultType);
658
John McCalled976492009-12-04 22:46:56 +0000659 /// \brief Rebuild an unresolved typename type, given the decl that
660 /// the UnresolvedUsingTypenameDecl was transformed to.
661 QualType RebuildUnresolvedUsingType(Decl *D);
662
Douglas Gregor577f75a2009-08-04 16:50:30 +0000663 /// \brief Build a new typedef type.
664 QualType RebuildTypedefType(TypedefDecl *Typedef) {
665 return SemaRef.Context.getTypeDeclType(Typedef);
666 }
667
668 /// \brief Build a new class/struct/union type.
669 QualType RebuildRecordType(RecordDecl *Record) {
670 return SemaRef.Context.getTypeDeclType(Record);
671 }
672
673 /// \brief Build a new Enum type.
674 QualType RebuildEnumType(EnumDecl *Enum) {
675 return SemaRef.Context.getTypeDeclType(Enum);
676 }
John McCall7da24312009-09-05 00:15:47 +0000677
Mike Stump1eb44332009-09-09 15:08:12 +0000678 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 ///
680 /// By default, performs semantic analysis when building the typeof type.
681 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000682 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683
Mike Stump1eb44332009-09-09 15:08:12 +0000684 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000685 ///
686 /// By default, builds a new TypeOfType with the given underlying type.
687 QualType RebuildTypeOfType(QualType Underlying);
688
Mike Stump1eb44332009-09-09 15:08:12 +0000689 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 ///
691 /// By default, performs semantic analysis when building the decltype type.
692 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000693 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000694
Richard Smith34b41d92011-02-20 03:19:35 +0000695 /// \brief Build a new C++0x auto type.
696 ///
697 /// By default, builds a new AutoType with the given deduced type.
698 QualType RebuildAutoType(QualType Deduced) {
699 return SemaRef.Context.getAutoType(Deduced);
700 }
701
Douglas Gregor577f75a2009-08-04 16:50:30 +0000702 /// \brief Build a new template specialization type.
703 ///
704 /// By default, performs semantic analysis when building the template
705 /// specialization type. Subclasses may override this routine to provide
706 /// different behavior.
707 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000708 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000709 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000710
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000711 /// \brief Build a new parenthesized type.
712 ///
713 /// By default, builds a new ParenType type from the inner type.
714 /// Subclasses may override this routine to provide different behavior.
715 QualType RebuildParenType(QualType InnerType) {
716 return SemaRef.Context.getParenType(InnerType);
717 }
718
Douglas Gregor577f75a2009-08-04 16:50:30 +0000719 /// \brief Build a new qualified name type.
720 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000721 /// By default, builds a new ElaboratedType type from the keyword,
722 /// the nested-name-specifier and the named type.
723 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000724 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
725 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000726 NestedNameSpecifier *NNS, QualType Named) {
727 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000728 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000729
730 /// \brief Build a new typename type that refers to a template-id.
731 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000732 /// By default, builds a new DependentNameType type from the
733 /// nested-name-specifier and the given type. Subclasses may override
734 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000735 QualType RebuildDependentTemplateSpecializationType(
736 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000737 NestedNameSpecifier *Qualifier,
738 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000739 const IdentifierInfo *Name,
740 SourceLocation NameLoc,
741 const TemplateArgumentListInfo &Args) {
742 // Rebuild the template name.
743 // TODO: avoid TemplateName abstraction
744 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000745 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000746 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000747
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000748 if (InstName.isNull())
749 return QualType();
750
John McCall33500952010-06-11 00:33:02 +0000751 // If it's still dependent, make a dependent specialization.
752 if (InstName.getAsDependentTemplateName())
753 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000754 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000755
756 // Otherwise, make an elaborated type wrapping a non-dependent
757 // specialization.
758 QualType T =
759 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
760 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000761
Douglas Gregora88f09f2011-02-28 17:23:35 +0000762 if (Keyword == ETK_None && Qualifier == 0)
Douglas Gregoraa2187d2011-02-28 00:04:36 +0000763 return T;
764
Douglas Gregora88f09f2011-02-28 17:23:35 +0000765 return SemaRef.Context.getElaboratedType(Keyword, Qualifier, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000766 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000767
768 /// \brief Build a new typename type that refers to an identifier.
769 ///
770 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000771 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000772 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000773 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000774 NestedNameSpecifier *NNS,
775 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000776 SourceLocation KeywordLoc,
777 SourceRange NNSRange,
778 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000779 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +0000780 SS.MakeTrivial(SemaRef.Context, NNS, NNSRange);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000781
Douglas Gregor40336422010-03-31 22:19:08 +0000782 if (NNS->isDependent()) {
783 // If the name is still dependent, just build a new dependent name type.
784 if (!SemaRef.computeDeclContext(SS))
785 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
786 }
787
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000788 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000789 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
790 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000791
792 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
793
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000794 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000795 // into a non-dependent elaborated-type-specifier. Find the tag we're
796 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000797 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000798 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
799 if (!DC)
800 return QualType();
801
John McCall56138762010-05-27 06:40:31 +0000802 if (SemaRef.RequireCompleteDeclContext(SS, DC))
803 return QualType();
804
Douglas Gregor40336422010-03-31 22:19:08 +0000805 TagDecl *Tag = 0;
806 SemaRef.LookupQualifiedName(Result, DC);
807 switch (Result.getResultKind()) {
808 case LookupResult::NotFound:
809 case LookupResult::NotFoundInCurrentInstantiation:
810 break;
Sean Huntc3021132010-05-05 15:23:54 +0000811
Douglas Gregor40336422010-03-31 22:19:08 +0000812 case LookupResult::Found:
813 Tag = Result.getAsSingle<TagDecl>();
814 break;
Sean Huntc3021132010-05-05 15:23:54 +0000815
Douglas Gregor40336422010-03-31 22:19:08 +0000816 case LookupResult::FoundOverloaded:
817 case LookupResult::FoundUnresolvedValue:
818 llvm_unreachable("Tag lookup cannot find non-tags");
819 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000820
Douglas Gregor40336422010-03-31 22:19:08 +0000821 case LookupResult::Ambiguous:
822 // Let the LookupResult structure handle ambiguities.
823 return QualType();
824 }
825
826 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000827 // Check where the name exists but isn't a tag type and use that to emit
828 // better diagnostics.
829 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
830 SemaRef.LookupQualifiedName(Result, DC);
831 switch (Result.getResultKind()) {
832 case LookupResult::Found:
833 case LookupResult::FoundOverloaded:
834 case LookupResult::FoundUnresolvedValue: {
835 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
836 unsigned Kind = 0;
837 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
838 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
839 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
840 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
841 break;
842 }
843 default:
844 // FIXME: Would be nice to highlight just the source range.
845 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
846 << Kind << Id << DC;
847 break;
848 }
Douglas Gregor40336422010-03-31 22:19:08 +0000849 return QualType();
850 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000851
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000852 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
853 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000854 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
855 return QualType();
856 }
857
858 // Build the elaborated-type-specifier type.
859 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000860 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000861 }
Mike Stump1eb44332009-09-09 15:08:12 +0000862
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000863 /// \brief Build a new pack expansion type.
864 ///
865 /// By default, builds a new PackExpansionType type from the given pattern.
866 /// Subclasses may override this routine to provide different behavior.
867 QualType RebuildPackExpansionType(QualType Pattern,
868 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000869 SourceLocation EllipsisLoc,
870 llvm::Optional<unsigned> NumExpansions) {
871 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
872 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000873 }
874
Douglas Gregordcee1a12009-08-06 05:28:30 +0000875 /// \brief Build a new nested-name-specifier given the prefix and an
876 /// identifier that names the next step in the nested-name-specifier.
877 ///
878 /// By default, performs semantic analysis when building the new
879 /// nested-name-specifier. Subclasses may override this routine to provide
880 /// different behavior.
881 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
882 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000883 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000884 QualType ObjectType,
885 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000886
887 /// \brief Build a new nested-name-specifier given the prefix and the
888 /// namespace named in the next step in the nested-name-specifier.
889 ///
890 /// By default, performs semantic analysis when building the new
891 /// nested-name-specifier. Subclasses may override this routine to provide
892 /// different behavior.
893 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
894 SourceRange Range,
895 NamespaceDecl *NS);
896
897 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor14aba762011-02-24 02:36:08 +0000898 /// namespace alias named in the next step in the nested-name-specifier.
899 ///
900 /// By default, performs semantic analysis when building the new
901 /// nested-name-specifier. Subclasses may override this routine to provide
902 /// different behavior.
903 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
904 SourceRange Range,
905 NamespaceAliasDecl *Alias);
906
907 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000908 /// type named in the next step in the nested-name-specifier.
909 ///
910 /// By default, performs semantic analysis when building the new
911 /// nested-name-specifier. Subclasses may override this routine to provide
912 /// different behavior.
913 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
914 SourceRange Range,
915 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000916 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000917
918 /// \brief Build a new template name given a nested name specifier, a flag
919 /// indicating whether the "template" keyword was provided, and the template
920 /// that the template name refers to.
921 ///
922 /// By default, builds the new template name directly. Subclasses may override
923 /// this routine to provide different behavior.
924 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
925 bool TemplateKW,
926 TemplateDecl *Template);
927
Douglas Gregord1067e52009-08-06 06:41:21 +0000928 /// \brief Build a new template name given a nested name specifier and the
929 /// name that is referred to as a template.
930 ///
931 /// By default, performs semantic analysis to determine whether the name can
932 /// be resolved to a specific template, then builds the appropriate kind of
933 /// template name. Subclasses may override this routine to provide different
934 /// behavior.
935 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000936 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000937 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000938 QualType ObjectType,
939 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000941 /// \brief Build a new template name given a nested name specifier and the
942 /// overloaded operator name that is referred to as a template.
943 ///
944 /// By default, performs semantic analysis to determine whether the name can
945 /// be resolved to a specific template, then builds the appropriate kind of
946 /// template name. Subclasses may override this routine to provide different
947 /// behavior.
948 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
949 OverloadedOperatorKind Operator,
950 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000951
952 /// \brief Build a new template name given a template template parameter pack
953 /// and the
954 ///
955 /// By default, performs semantic analysis to determine whether the name can
956 /// be resolved to a specific template, then builds the appropriate kind of
957 /// template name. Subclasses may override this routine to provide different
958 /// behavior.
959 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
960 const TemplateArgument &ArgPack) {
961 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
962 }
963
Douglas Gregor43959a92009-08-20 07:17:43 +0000964 /// \brief Build a new compound statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000968 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000969 MultiStmtArg Statements,
970 SourceLocation RBraceLoc,
971 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000972 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 IsStmtExpr);
974 }
975
976 /// \brief Build a new case statement.
977 ///
978 /// By default, performs semantic analysis to build the new statement.
979 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000980 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000981 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000982 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000983 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000984 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000985 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 ColonLoc);
987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 /// \brief Attach the body to a new case statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000993 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000994 getSema().ActOnCaseStmtBody(S, Body);
995 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000996 }
Mike Stump1eb44332009-09-09 15:08:12 +0000997
Douglas Gregor43959a92009-08-20 07:17:43 +0000998 /// \brief Build a new default statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001002 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001004 Stmt *SubStmt) {
1005 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 /*CurScope=*/0);
1007 }
Mike Stump1eb44332009-09-09 15:08:12 +00001008
Douglas Gregor43959a92009-08-20 07:17:43 +00001009 /// \brief Build a new label statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001013 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1014 SourceLocation ColonLoc, Stmt *SubStmt) {
1015 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001016 }
Mike Stump1eb44332009-09-09 15:08:12 +00001017
Douglas Gregor43959a92009-08-20 07:17:43 +00001018 /// \brief Build a new "if" statement.
1019 ///
1020 /// By default, performs semantic analysis to build the new statement.
1021 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001022 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001023 VarDecl *CondVar, Stmt *Then,
1024 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001025 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001026 }
Mike Stump1eb44332009-09-09 15:08:12 +00001027
Douglas Gregor43959a92009-08-20 07:17:43 +00001028 /// \brief Start building a new switch statement.
1029 ///
1030 /// By default, performs semantic analysis to build the new statement.
1031 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001032 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001033 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001034 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001035 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 }
Mike Stump1eb44332009-09-09 15:08:12 +00001037
Douglas Gregor43959a92009-08-20 07:17:43 +00001038 /// \brief Attach the body to the switch statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001042 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001043 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001044 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
1046
1047 /// \brief Build a new while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001051 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1052 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001053 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, 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 do-while statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001060 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001061 SourceLocation WhileLoc, SourceLocation LParenLoc,
1062 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001063 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1064 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001065 }
1066
1067 /// \brief Build a new for statement.
1068 ///
1069 /// By default, performs semantic analysis to build the new statement.
1070 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001071 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1072 Stmt *Init, Sema::FullExprArg Cond,
1073 VarDecl *CondVar, Sema::FullExprArg Inc,
1074 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001075 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001076 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 }
Mike Stump1eb44332009-09-09 15:08:12 +00001078
Douglas Gregor43959a92009-08-20 07:17:43 +00001079 /// \brief Build a new goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001083 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1084 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001085 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001086 }
1087
1088 /// \brief Build a new indirect goto statement.
1089 ///
1090 /// By default, performs semantic analysis to build the new statement.
1091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001092 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001093 SourceLocation StarLoc,
1094 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001095 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001096 }
Mike Stump1eb44332009-09-09 15:08:12 +00001097
Douglas Gregor43959a92009-08-20 07:17:43 +00001098 /// \brief Build a new return statement.
1099 ///
1100 /// By default, performs semantic analysis to build the new statement.
1101 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001102 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001103 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001104 }
Mike Stump1eb44332009-09-09 15:08:12 +00001105
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 /// \brief Build a new declaration statement.
1107 ///
1108 /// By default, performs semantic analysis to build the new statement.
1109 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001110 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001111 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001113 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1114 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001115 }
Mike Stump1eb44332009-09-09 15:08:12 +00001116
Anders Carlsson703e3942010-01-24 05:50:09 +00001117 /// \brief Build a new inline asm statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001121 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001122 bool IsSimple,
1123 bool IsVolatile,
1124 unsigned NumOutputs,
1125 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001126 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001127 MultiExprArg Constraints,
1128 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001129 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001130 MultiExprArg Clobbers,
1131 SourceLocation RParenLoc,
1132 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001133 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001134 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001135 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001136 RParenLoc, MSAsm);
1137 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001138
1139 /// \brief Build a new Objective-C @try statement.
1140 ///
1141 /// By default, performs semantic analysis to build the new statement.
1142 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001143 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001144 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001145 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001146 Stmt *Finally) {
1147 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1148 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001149 }
1150
Douglas Gregorbe270a02010-04-26 17:57:08 +00001151 /// \brief Rebuild an Objective-C exception declaration.
1152 ///
1153 /// By default, performs semantic analysis to build the new declaration.
1154 /// Subclasses may override this routine to provide different behavior.
1155 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1156 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001157 return getSema().BuildObjCExceptionDecl(TInfo, T,
1158 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001159 ExceptionDecl->getLocation());
1160 }
Sean Huntc3021132010-05-05 15:23:54 +00001161
Douglas Gregorbe270a02010-04-26 17:57:08 +00001162 /// \brief Build a new Objective-C @catch statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001167 SourceLocation RParenLoc,
1168 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001170 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001171 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001172 }
Sean Huntc3021132010-05-05 15:23:54 +00001173
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001174 /// \brief Build a new Objective-C @finally statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001178 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001179 Stmt *Body) {
1180 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181 }
Sean Huntc3021132010-05-05 15:23:54 +00001182
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001183 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001187 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001188 Expr *Operand) {
1189 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001190 }
Sean Huntc3021132010-05-05 15:23:54 +00001191
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001192 /// \brief Build a new Objective-C @synchronized statement.
1193 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001196 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001197 Expr *Object,
1198 Stmt *Body) {
1199 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1200 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001201 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001202
1203 /// \brief Build a new Objective-C fast enumeration statement.
1204 ///
1205 /// By default, performs semantic analysis to build the new statement.
1206 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001207 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001208 SourceLocation LParenLoc,
1209 Stmt *Element,
1210 Expr *Collection,
1211 SourceLocation RParenLoc,
1212 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001213 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001214 Element,
1215 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001216 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001217 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001218 }
Sean Huntc3021132010-05-05 15:23:54 +00001219
Douglas Gregor43959a92009-08-20 07:17:43 +00001220 /// \brief Build a new C++ exception declaration.
1221 ///
1222 /// By default, performs semantic analysis to build the new decaration.
1223 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001224 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001225 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001226 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001227 SourceLocation Loc) {
1228 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001229 }
1230
1231 /// \brief Build a new C++ catch statement.
1232 ///
1233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001235 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001236 VarDecl *ExceptionDecl,
1237 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001238 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1239 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001240 }
Mike Stump1eb44332009-09-09 15:08:12 +00001241
Douglas Gregor43959a92009-08-20 07:17:43 +00001242 /// \brief Build a new C++ try statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001246 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001247 Stmt *TryBlock,
1248 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001249 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001250 }
Mike Stump1eb44332009-09-09 15:08:12 +00001251
Douglas Gregorb98b1992009-08-11 05:31:07 +00001252 /// \brief Build a new expression that references a declaration.
1253 ///
1254 /// By default, performs semantic analysis to build the new expression.
1255 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001256 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001257 LookupResult &R,
1258 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001259 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1260 }
1261
1262
1263 /// \brief Build a new expression that references a declaration.
1264 ///
1265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001267 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001268 SourceRange QualifierRange,
1269 ValueDecl *VD,
1270 const DeclarationNameInfo &NameInfo,
1271 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001272 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00001273 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001274
1275 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001276
1277 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 }
Mike Stump1eb44332009-09-09 15:08:12 +00001279
Douglas Gregorb98b1992009-08-11 05:31:07 +00001280 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001281 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001284 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001285 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001286 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 }
1288
Douglas Gregora71d8192009-09-04 17:36:40 +00001289 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001290 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001293 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001294 SourceLocation OperatorLoc,
1295 bool isArrow,
1296 CXXScopeSpec &SS,
1297 TypeSourceInfo *ScopeType,
1298 SourceLocation CCLoc,
1299 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001300 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001301
Douglas Gregorb98b1992009-08-11 05:31:07 +00001302 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001303 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001304 /// By default, performs semantic analysis to build the new expression.
1305 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001306 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001307 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001308 Expr *SubExpr) {
1309 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 }
Mike Stump1eb44332009-09-09 15:08:12 +00001311
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001312 /// \brief Build a new builtin offsetof expression.
1313 ///
1314 /// By default, performs semantic analysis to build the new expression.
1315 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001316 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001317 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001318 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001319 unsigned NumComponents,
1320 SourceLocation RParenLoc) {
1321 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1322 NumComponents, RParenLoc);
1323 }
Sean Huntc3021132010-05-05 15:23:54 +00001324
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001326 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001329 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001330 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001332 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 }
1334
Mike Stump1eb44332009-09-09 15:08:12 +00001335 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001337 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001338 /// By default, performs semantic analysis to build the new expression.
1339 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001340 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001342 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001343 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001344 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001346
Douglas Gregorb98b1992009-08-11 05:31:07 +00001347 return move(Result);
1348 }
Mike Stump1eb44332009-09-09 15:08:12 +00001349
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001351 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001352 /// By default, performs semantic analysis to build the new expression.
1353 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001354 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001356 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001358 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1359 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 RBracketLoc);
1361 }
1362
1363 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001364 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001367 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001369 SourceLocation RParenLoc,
1370 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001371 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001372 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001373 }
1374
1375 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001376 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001377 /// By default, performs semantic analysis to build the new expression.
1378 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001379 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001380 bool isArrow,
1381 NestedNameSpecifier *Qualifier,
1382 SourceRange QualifierRange,
1383 const DeclarationNameInfo &MemberNameInfo,
1384 ValueDecl *Member,
1385 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001386 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001387 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001388 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001389 // We have a reference to an unnamed field. This is always the
1390 // base of an anonymous struct/union member access, i.e. the
1391 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001392 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001393 assert(Member->getType()->isRecordType() &&
1394 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001395
John McCall9ae2f072010-08-23 23:25:46 +00001396 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001397 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001398 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001399
John McCallf89e55a2010-11-18 06:31:45 +00001400 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001401 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001402 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001403 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001404 cast<FieldDecl>(Member)->getType(),
1405 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001406 return getSema().Owned(ME);
1407 }
Mike Stump1eb44332009-09-09 15:08:12 +00001408
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001409 CXXScopeSpec SS;
1410 if (Qualifier) {
Douglas Gregorc34348a2011-02-24 17:54:50 +00001411 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001412 }
1413
John McCall9ae2f072010-08-23 23:25:46 +00001414 getSema().DefaultFunctionArrayConversion(Base);
1415 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001416
John McCall6bb80172010-03-30 21:47:33 +00001417 // FIXME: this involves duplicating earlier analysis in a lot of
1418 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001419 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001420 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001421 R.resolveKind();
1422
John McCall9ae2f072010-08-23 23:25:46 +00001423 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001424 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001425 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 }
Mike Stump1eb44332009-09-09 15:08:12 +00001427
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001429 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001432 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001433 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001434 Expr *LHS, Expr *RHS) {
1435 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 }
1437
1438 /// \brief Build a new conditional 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 RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001443 SourceLocation QuestionLoc,
1444 Expr *LHS,
1445 SourceLocation ColonLoc,
1446 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001447 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1448 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 }
1450
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001452 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001455 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001456 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001458 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001459 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001460 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 }
Mike Stump1eb44332009-09-09 15:08:12 +00001462
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001464 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001467 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001468 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001470 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001471 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001472 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001473 }
Mike Stump1eb44332009-09-09 15:08:12 +00001474
Douglas Gregorb98b1992009-08-11 05:31:07 +00001475 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001476 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001479 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 SourceLocation OpLoc,
1481 SourceLocation AccessorLoc,
1482 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001483
John McCall129e2df2009-11-30 22:42:35 +00001484 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001485 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001486 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001487 OpLoc, /*IsArrow*/ false,
1488 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001489 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001490 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001491 }
Mike Stump1eb44332009-09-09 15:08:12 +00001492
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001494 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001497 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001499 SourceLocation RBraceLoc,
1500 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001501 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001502 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1503 if (Result.isInvalid() || ResultTy->isDependentType())
1504 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001505
Douglas Gregore48319a2009-11-09 17:16:50 +00001506 // Patch in the result type we were given, which may have been computed
1507 // when the initial InitListExpr was built.
1508 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1509 ILE->setType(ResultTy);
1510 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 }
Mike Stump1eb44332009-09-09 15:08:12 +00001512
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001514 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// By default, performs semantic analysis to build the new expression.
1516 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001517 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 MultiExprArg ArrayExprs,
1519 SourceLocation EqualOrColonLoc,
1520 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001521 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001522 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001527
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 ArrayExprs.release();
1529 return move(Result);
1530 }
Mike Stump1eb44332009-09-09 15:08:12 +00001531
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001533 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 /// By default, builds the implicit value initialization without performing
1535 /// any semantic analysis. Subclasses may override this routine to provide
1536 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001537 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001538 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1539 }
Mike Stump1eb44332009-09-09 15:08:12 +00001540
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001542 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001545 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001546 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001547 SourceLocation RParenLoc) {
1548 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001549 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001550 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 }
1552
1553 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001554 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001557 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 MultiExprArg SubExprs,
1559 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001560 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001561 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001562 }
Mike Stump1eb44332009-09-09 15:08:12 +00001563
Douglas Gregorb98b1992009-08-11 05:31:07 +00001564 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001565 ///
1566 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// rather than attempting to map the label statement itself.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001570 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001571 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
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 GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001575 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001578 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001579 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001581 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
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 __builtin_choose_expr expression.
1585 ///
1586 /// 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 RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001589 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 SourceLocation RParenLoc) {
1591 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001592 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 RParenLoc);
1594 }
Mike Stump1eb44332009-09-09 15:08:12 +00001595
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 /// \brief Build a new overloaded operator call expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// The semantic analysis provides the behavior of template instantiation,
1600 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001601 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 /// argument-dependent lookup, etc. Subclasses may override this routine to
1603 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001604 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001606 Expr *Callee,
1607 Expr *First,
1608 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001609
1610 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// reinterpret_cast.
1612 ///
1613 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001614 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001616 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 Stmt::StmtClass Class,
1618 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001619 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 SourceLocation RAngleLoc,
1621 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001622 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 SourceLocation RParenLoc) {
1624 switch (Class) {
1625 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001626 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001627 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001628 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629
1630 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001631 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001632 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001633 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001634
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001636 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001637 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001638 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001640
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001642 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001643 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001644 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001645
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 default:
1647 assert(false && "Invalid C++ named cast");
1648 break;
1649 }
Mike Stump1eb44332009-09-09 15:08:12 +00001650
John McCallf312b1e2010-08-26 23:41:50 +00001651 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
Mike Stump1eb44332009-09-09 15:08:12 +00001653
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// \brief Build a new C++ static_cast expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001658 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001660 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 SourceLocation RAngleLoc,
1662 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001665 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001666 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001667 SourceRange(LAngleLoc, RAngleLoc),
1668 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 }
1670
1671 /// \brief Build a new C++ dynamic_cast expression.
1672 ///
1673 /// By default, performs semantic analysis to build the new expression.
1674 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001675 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001677 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001678 SourceLocation RAngleLoc,
1679 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001682 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001683 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001684 SourceRange(LAngleLoc, RAngleLoc),
1685 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 }
1687
1688 /// \brief Build a new C++ reinterpret_cast expression.
1689 ///
1690 /// By default, performs semantic analysis to build the new expression.
1691 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001692 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001694 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 SourceLocation RAngleLoc,
1696 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001697 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001699 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001700 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001701 SourceRange(LAngleLoc, RAngleLoc),
1702 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 }
1704
1705 /// \brief Build a new C++ const_cast expression.
1706 ///
1707 /// By default, performs semantic analysis to build the new expression.
1708 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001709 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001711 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 SourceLocation RAngleLoc,
1713 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001714 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001716 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001717 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001718 SourceRange(LAngleLoc, RAngleLoc),
1719 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// \brief Build a new C++ functional-style cast expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001726 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1727 SourceLocation LParenLoc,
1728 Expr *Sub,
1729 SourceLocation RParenLoc) {
1730 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001731 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 RParenLoc);
1733 }
Mike Stump1eb44332009-09-09 15:08:12 +00001734
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 /// \brief Build a new C++ typeid(type) expression.
1736 ///
1737 /// By default, performs semantic analysis to build the new expression.
1738 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001739 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001740 SourceLocation TypeidLoc,
1741 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001743 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001744 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 }
Mike Stump1eb44332009-09-09 15:08:12 +00001746
Francois Pichet01b7c302010-09-08 12:20:18 +00001747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 /// \brief Build a new C++ typeid(expr) expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001752 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001753 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001754 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001756 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001757 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001758 }
1759
Francois Pichet01b7c302010-09-08 12:20:18 +00001760 /// \brief Build a new C++ __uuidof(type) expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
1764 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1765 SourceLocation TypeidLoc,
1766 TypeSourceInfo *Operand,
1767 SourceLocation RParenLoc) {
1768 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1769 RParenLoc);
1770 }
1771
1772 /// \brief Build a new C++ __uuidof(expr) expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
1776 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1777 SourceLocation TypeidLoc,
1778 Expr *Operand,
1779 SourceLocation RParenLoc) {
1780 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1781 RParenLoc);
1782 }
1783
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 /// \brief Build a new C++ "this" expression.
1785 ///
1786 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001787 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001789 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001790 QualType ThisType,
1791 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001793 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1794 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 }
1796
1797 /// \brief Build a new C++ throw expression.
1798 ///
1799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001801 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001802 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 }
1804
1805 /// \brief Build a new C++ default-argument expression.
1806 ///
1807 /// By default, builds a new default-argument expression, which does not
1808 /// require any semantic analysis. Subclasses may override this routine to
1809 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001810 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001811 ParmVarDecl *Param) {
1812 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1813 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 }
1815
1816 /// \brief Build a new C++ zero-initialization expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001820 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1821 SourceLocation LParenLoc,
1822 SourceLocation RParenLoc) {
1823 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001824 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001825 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 }
Mike Stump1eb44332009-09-09 15:08:12 +00001827
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 /// \brief Build a new C++ "new" expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001832 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001833 bool UseGlobal,
1834 SourceLocation PlacementLParen,
1835 MultiExprArg PlacementArgs,
1836 SourceLocation PlacementRParen,
1837 SourceRange TypeIdParens,
1838 QualType AllocatedType,
1839 TypeSourceInfo *AllocatedTypeInfo,
1840 Expr *ArraySize,
1841 SourceLocation ConstructorLParen,
1842 MultiExprArg ConstructorArgs,
1843 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001844 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001845 PlacementLParen,
1846 move(PlacementArgs),
1847 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001848 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001849 AllocatedType,
1850 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001851 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 ConstructorLParen,
1853 move(ConstructorArgs),
1854 ConstructorRParen);
1855 }
Mike Stump1eb44332009-09-09 15:08:12 +00001856
Douglas Gregorb98b1992009-08-11 05:31:07 +00001857 /// \brief Build a new C++ "delete" expression.
1858 ///
1859 /// By default, performs semantic analysis to build the new expression.
1860 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001861 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001862 bool IsGlobalDelete,
1863 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001864 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001865 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001866 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001867 }
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregorb98b1992009-08-11 05:31:07 +00001869 /// \brief Build a new unary type trait expression.
1870 ///
1871 /// By default, performs semantic analysis to build the new expression.
1872 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001873 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001874 SourceLocation StartLoc,
1875 TypeSourceInfo *T,
1876 SourceLocation RParenLoc) {
1877 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 }
1879
Francois Pichet6ad6f282010-12-07 00:08:36 +00001880 /// \brief Build a new binary type trait expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
1884 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1885 SourceLocation StartLoc,
1886 TypeSourceInfo *LhsT,
1887 TypeSourceInfo *RhsT,
1888 SourceLocation RParenLoc) {
1889 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1890 }
1891
Mike Stump1eb44332009-09-09 15:08:12 +00001892 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 /// expression.
1894 ///
1895 /// By default, performs semantic analysis to build the new expression.
1896 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001897 ExprResult RebuildDependentScopeDeclRefExpr(
1898 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001899 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001900 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001902 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001903
1904 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001905 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001906 *TemplateArgs);
1907
Abramo Bagnara25777432010-08-11 22:01:17 +00001908 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 }
1910
1911 /// \brief Build a new template-id expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001915 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001916 LookupResult &R,
1917 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001918 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001919 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 }
1921
1922 /// \brief Build a new object-construction expression.
1923 ///
1924 /// By default, performs semantic analysis to build the new expression.
1925 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001926 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001927 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 CXXConstructorDecl *Constructor,
1929 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001930 MultiExprArg Args,
1931 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001932 CXXConstructExpr::ConstructionKind ConstructKind,
1933 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001934 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001935 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001936 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001937 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001938
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001939 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001940 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001941 RequiresZeroInit, ConstructKind,
1942 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001943 }
1944
1945 /// \brief Build a new object-construction expression.
1946 ///
1947 /// By default, performs semantic analysis to build the new expression.
1948 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001949 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1950 SourceLocation LParenLoc,
1951 MultiExprArg Args,
1952 SourceLocation RParenLoc) {
1953 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 LParenLoc,
1955 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001956 RParenLoc);
1957 }
1958
1959 /// \brief Build a new object-construction expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001963 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1964 SourceLocation LParenLoc,
1965 MultiExprArg Args,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 LParenLoc,
1969 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 RParenLoc);
1971 }
Mike Stump1eb44332009-09-09 15:08:12 +00001972
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 /// \brief Build a new member reference expression.
1974 ///
1975 /// By default, performs semantic analysis to build the new expression.
1976 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001977 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001978 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 bool IsArrow,
1980 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001981 NestedNameSpecifier *Qualifier,
1982 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001983 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001984 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001985 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00001987 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00001988
John McCall9ae2f072010-08-23 23:25:46 +00001989 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001990 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001991 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001992 MemberNameInfo,
1993 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001994 }
1995
John McCall129e2df2009-11-30 22:42:35 +00001996 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002000 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002001 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002002 SourceLocation OperatorLoc,
2003 bool IsArrow,
2004 NestedNameSpecifier *Qualifier,
2005 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00002006 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002007 LookupResult &R,
2008 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002009 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00002010 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00002011
John McCall9ae2f072010-08-23 23:25:46 +00002012 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002013 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002014 SS, FirstQualifierInScope,
2015 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002016 }
Mike Stump1eb44332009-09-09 15:08:12 +00002017
Sebastian Redl2e156222010-09-10 20:55:43 +00002018 /// \brief Build a new noexcept expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
2022 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2023 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2024 }
2025
Douglas Gregoree8aff02011-01-04 17:33:58 +00002026 /// \brief Build a new expression to compute the length of a parameter pack.
2027 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2028 SourceLocation PackLoc,
2029 SourceLocation RParenLoc,
2030 unsigned Length) {
2031 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2032 OperatorLoc, Pack, PackLoc,
2033 RParenLoc, Length);
2034 }
2035
Douglas Gregorb98b1992009-08-11 05:31:07 +00002036 /// \brief Build a new Objective-C @encode expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002040 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002041 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002042 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002043 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002044 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002045 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002046
Douglas Gregor92e986e2010-04-22 16:44:27 +00002047 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002048 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002049 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002050 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002051 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002052 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002053 MultiExprArg Args,
2054 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002055 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2056 ReceiverTypeInfo->getType(),
2057 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002058 Sel, Method, LBracLoc, SelectorLoc,
2059 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002060 }
2061
2062 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002063 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002064 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002065 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002066 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002067 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002068 MultiExprArg Args,
2069 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002070 return SemaRef.BuildInstanceMessage(Receiver,
2071 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002072 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002073 Sel, Method, LBracLoc, SelectorLoc,
2074 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002075 }
2076
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002077 /// \brief Build a new Objective-C ivar reference expression.
2078 ///
2079 /// By default, performs semantic analysis to build the new expression.
2080 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002081 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002082 SourceLocation IvarLoc,
2083 bool IsArrow, bool IsFreeIvar) {
2084 // FIXME: We lose track of the IsFreeIvar bit.
2085 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002086 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002087 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2088 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002089 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002090 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002091 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002092 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002093 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002094 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002095
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002096 if (Result.get())
2097 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002098
John McCall9ae2f072010-08-23 23:25:46 +00002099 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002100 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002101 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002102 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002103 /*TemplateArgs=*/0);
2104 }
Douglas Gregore3303542010-04-26 20:47:02 +00002105
2106 /// \brief Build a new Objective-C property reference expression.
2107 ///
2108 /// By default, performs semantic analysis to build the new expression.
2109 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002110 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002111 ObjCPropertyDecl *Property,
2112 SourceLocation PropertyLoc) {
2113 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002114 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002115 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2116 Sema::LookupMemberName);
2117 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002118 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002119 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002120 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002121 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002122 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002123
Douglas Gregore3303542010-04-26 20:47:02 +00002124 if (Result.get())
2125 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002126
John McCall9ae2f072010-08-23 23:25:46 +00002127 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002128 /*FIXME:*/PropertyLoc, IsArrow,
2129 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002130 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002131 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002132 /*TemplateArgs=*/0);
2133 }
Sean Huntc3021132010-05-05 15:23:54 +00002134
John McCall12f78a62010-12-02 01:19:52 +00002135 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002136 ///
2137 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002138 /// Subclasses may override this routine to provide different behavior.
2139 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2140 ObjCMethodDecl *Getter,
2141 ObjCMethodDecl *Setter,
2142 SourceLocation PropertyLoc) {
2143 // Since these expressions can only be value-dependent, we do not
2144 // need to perform semantic analysis again.
2145 return Owned(
2146 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2147 VK_LValue, OK_ObjCProperty,
2148 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002149 }
2150
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002151 /// \brief Build a new Objective-C "isa" expression.
2152 ///
2153 /// By default, performs semantic analysis to build the new expression.
2154 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002155 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002156 bool IsArrow) {
2157 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002158 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002159 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2160 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002161 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002162 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002163 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002164 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002165 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002166
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002167 if (Result.get())
2168 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002169
John McCall9ae2f072010-08-23 23:25:46 +00002170 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002171 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002172 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002173 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002174 /*TemplateArgs=*/0);
2175 }
Sean Huntc3021132010-05-05 15:23:54 +00002176
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 /// \brief Build a new shuffle vector expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002181 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002182 MultiExprArg SubExprs,
2183 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002185 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2187 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2188 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2189 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002190
Douglas Gregorb98b1992009-08-11 05:31:07 +00002191 // Build a reference to the __builtin_shufflevector builtin
2192 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002193 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002194 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002195 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002196 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002197
2198 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002199 unsigned NumSubExprs = SubExprs.size();
2200 Expr **Subs = (Expr **)SubExprs.release();
2201 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2202 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002203 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002204 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002205 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002206 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002207
Douglas Gregorb98b1992009-08-11 05:31:07 +00002208 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002209 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002210 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002211 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002212
Douglas Gregorb98b1992009-08-11 05:31:07 +00002213 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002214 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002215 }
John McCall43fed0d2010-11-12 08:19:04 +00002216
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002217 /// \brief Build a new template argument pack expansion.
2218 ///
2219 /// By default, performs semantic analysis to build a new pack expansion
2220 /// for a template argument. Subclasses may override this routine to provide
2221 /// different behavior.
2222 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002223 SourceLocation EllipsisLoc,
2224 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002225 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002226 case TemplateArgument::Expression: {
2227 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002228 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2229 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002230 if (Result.isInvalid())
2231 return TemplateArgumentLoc();
2232
2233 return TemplateArgumentLoc(Result.get(), Result.get());
2234 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002235
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002236 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002237 return TemplateArgumentLoc(TemplateArgument(
2238 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002239 NumExpansions),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002240 Pattern.getTemplateQualifierRange(),
2241 Pattern.getTemplateNameLoc(),
2242 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002243
2244 case TemplateArgument::Null:
2245 case TemplateArgument::Integral:
2246 case TemplateArgument::Declaration:
2247 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002248 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002249 llvm_unreachable("Pack expansion pattern has no parameter packs");
2250
2251 case TemplateArgument::Type:
2252 if (TypeSourceInfo *Expansion
2253 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002254 EllipsisLoc,
2255 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002256 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2257 Expansion);
2258 break;
2259 }
2260
2261 return TemplateArgumentLoc();
2262 }
2263
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002264 /// \brief Build a new expression pack expansion.
2265 ///
2266 /// By default, performs semantic analysis to build a new pack expansion
2267 /// for an expression. Subclasses may override this routine to provide
2268 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002269 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2270 llvm::Optional<unsigned> NumExpansions) {
2271 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002272 }
2273
John McCall43fed0d2010-11-12 08:19:04 +00002274private:
2275 QualType TransformTypeInObjectScope(QualType T,
2276 QualType ObjectType,
2277 NamedDecl *FirstQualifierInScope,
2278 NestedNameSpecifier *Prefix);
2279
2280 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2281 QualType ObjectType,
2282 NamedDecl *FirstQualifierInScope,
2283 NestedNameSpecifier *Prefix);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002284
2285 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2286 QualType ObjectType,
2287 NamedDecl *FirstQualifierInScope,
2288 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002289};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002290
Douglas Gregor43959a92009-08-20 07:17:43 +00002291template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002292StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002293 if (!S)
2294 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002295
Douglas Gregor43959a92009-08-20 07:17:43 +00002296 switch (S->getStmtClass()) {
2297 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002298
Douglas Gregor43959a92009-08-20 07:17:43 +00002299 // Transform individual statement nodes
2300#define STMT(Node, Parent) \
2301 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002302#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002303#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002304#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002305
Douglas Gregor43959a92009-08-20 07:17:43 +00002306 // Transform expressions by calling TransformExpr.
2307#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002308#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002309#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002310#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002311 {
John McCall60d7b3a2010-08-24 06:29:42 +00002312 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002313 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002314 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002315
John McCall9ae2f072010-08-23 23:25:46 +00002316 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002317 }
Mike Stump1eb44332009-09-09 15:08:12 +00002318 }
2319
John McCall3fa5cae2010-10-26 07:05:15 +00002320 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002321}
Mike Stump1eb44332009-09-09 15:08:12 +00002322
2323
Douglas Gregor670444e2009-08-04 22:27:00 +00002324template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002325ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002326 if (!E)
2327 return SemaRef.Owned(E);
2328
2329 switch (E->getStmtClass()) {
2330 case Stmt::NoStmtClass: break;
2331#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002332#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002333#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002334 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002335#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002336 }
2337
John McCall3fa5cae2010-10-26 07:05:15 +00002338 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002339}
2340
2341template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002342bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2343 unsigned NumInputs,
2344 bool IsCall,
2345 llvm::SmallVectorImpl<Expr *> &Outputs,
2346 bool *ArgChanged) {
2347 for (unsigned I = 0; I != NumInputs; ++I) {
2348 // If requested, drop call arguments that need to be dropped.
2349 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2350 if (ArgChanged)
2351 *ArgChanged = true;
2352
2353 break;
2354 }
2355
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002356 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2357 Expr *Pattern = Expansion->getPattern();
2358
2359 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2360 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2361 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2362
2363 // Determine whether the set of unexpanded parameter packs can and should
2364 // be expanded.
2365 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002366 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002367 llvm::Optional<unsigned> OrigNumExpansions
2368 = Expansion->getNumExpansions();
2369 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002370 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2371 Pattern->getSourceRange(),
2372 Unexpanded.data(),
2373 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002374 Expand, RetainExpansion,
2375 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002376 return true;
2377
2378 if (!Expand) {
2379 // The transform has determined that we should perform a simple
2380 // transformation on the pack expansion, producing another pack
2381 // expansion.
2382 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2383 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2384 if (OutPattern.isInvalid())
2385 return true;
2386
2387 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002388 Expansion->getEllipsisLoc(),
2389 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002390 if (Out.isInvalid())
2391 return true;
2392
2393 if (ArgChanged)
2394 *ArgChanged = true;
2395 Outputs.push_back(Out.get());
2396 continue;
2397 }
2398
2399 // The transform has determined that we should perform an elementwise
2400 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002401 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002402 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2403 ExprResult Out = getDerived().TransformExpr(Pattern);
2404 if (Out.isInvalid())
2405 return true;
2406
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002407 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002408 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2409 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002410 if (Out.isInvalid())
2411 return true;
2412 }
2413
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002414 if (ArgChanged)
2415 *ArgChanged = true;
2416 Outputs.push_back(Out.get());
2417 }
2418
2419 continue;
2420 }
2421
Douglas Gregoraa165f82011-01-03 19:04:46 +00002422 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2423 if (Result.isInvalid())
2424 return true;
2425
2426 if (Result.get() != Inputs[I] && ArgChanged)
2427 *ArgChanged = true;
2428
2429 Outputs.push_back(Result.get());
2430 }
2431
2432 return false;
2433}
2434
2435template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002436NestedNameSpecifier *
2437TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002438 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002439 QualType ObjectType,
2440 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002441 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002442
Douglas Gregor43959a92009-08-20 07:17:43 +00002443 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002444 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002445 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002446 ObjectType,
2447 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002448 if (!Prefix)
2449 return 0;
2450 }
Mike Stump1eb44332009-09-09 15:08:12 +00002451
Douglas Gregordcee1a12009-08-06 05:28:30 +00002452 switch (NNS->getKind()) {
2453 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002454 if (Prefix) {
2455 // The object type and qualifier-in-scope really apply to the
2456 // leftmost entity.
2457 ObjectType = QualType();
2458 FirstQualifierInScope = 0;
2459 }
2460
Mike Stump1eb44332009-09-09 15:08:12 +00002461 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002462 "Identifier nested-name-specifier with no prefix or object type");
2463 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2464 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002465 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002466
2467 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002468 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002469 ObjectType,
2470 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002471
Douglas Gregordcee1a12009-08-06 05:28:30 +00002472 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002473 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002474 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002475 getDerived().TransformDecl(Range.getBegin(),
2476 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002477 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002478 Prefix == NNS->getPrefix() &&
2479 NS == NNS->getAsNamespace())
2480 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002481
Douglas Gregordcee1a12009-08-06 05:28:30 +00002482 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2483 }
Mike Stump1eb44332009-09-09 15:08:12 +00002484
Douglas Gregor14aba762011-02-24 02:36:08 +00002485 case NestedNameSpecifier::NamespaceAlias: {
2486 NamespaceAliasDecl *Alias
2487 = cast_or_null<NamespaceAliasDecl>(
2488 getDerived().TransformDecl(Range.getBegin(),
2489 NNS->getAsNamespaceAlias()));
2490 if (!getDerived().AlwaysRebuild() &&
2491 Prefix == NNS->getPrefix() &&
2492 Alias == NNS->getAsNamespaceAlias())
2493 return NNS;
2494
2495 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2496 }
2497
Douglas Gregordcee1a12009-08-06 05:28:30 +00002498 case NestedNameSpecifier::Global:
2499 // There is no meaningful transformation that one could perform on the
2500 // global scope.
2501 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002502
Douglas Gregordcee1a12009-08-06 05:28:30 +00002503 case NestedNameSpecifier::TypeSpecWithTemplate:
2504 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002505 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002506 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2507 ObjectType,
2508 FirstQualifierInScope,
2509 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002510 if (T.isNull())
2511 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002512
Douglas Gregordcee1a12009-08-06 05:28:30 +00002513 if (!getDerived().AlwaysRebuild() &&
2514 Prefix == NNS->getPrefix() &&
2515 T == QualType(NNS->getAsType(), 0))
2516 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002517
2518 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2519 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002520 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002521 }
2522 }
Mike Stump1eb44332009-09-09 15:08:12 +00002523
Douglas Gregordcee1a12009-08-06 05:28:30 +00002524 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002525 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002526}
2527
2528template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002529NestedNameSpecifierLoc
2530TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2531 NestedNameSpecifierLoc NNS,
2532 QualType ObjectType,
2533 NamedDecl *FirstQualifierInScope) {
2534 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2535 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2536 Qualifier = Qualifier.getPrefix())
2537 Qualifiers.push_back(Qualifier);
2538
2539 CXXScopeSpec SS;
2540 while (!Qualifiers.empty()) {
2541 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2542 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2543
2544 switch (QNNS->getKind()) {
2545 case NestedNameSpecifier::Identifier:
2546 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2547 *QNNS->getAsIdentifier(),
2548 Q.getLocalBeginLoc(),
2549 Q.getLocalEndLoc(),
2550 ObjectType, false, SS,
2551 FirstQualifierInScope, false))
2552 return NestedNameSpecifierLoc();
2553
2554 break;
2555
2556 case NestedNameSpecifier::Namespace: {
2557 NamespaceDecl *NS
2558 = cast_or_null<NamespaceDecl>(
2559 getDerived().TransformDecl(
2560 Q.getLocalBeginLoc(),
2561 QNNS->getAsNamespace()));
2562 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2563 break;
2564 }
2565
2566 case NestedNameSpecifier::NamespaceAlias: {
2567 NamespaceAliasDecl *Alias
2568 = cast_or_null<NamespaceAliasDecl>(
2569 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2570 QNNS->getAsNamespaceAlias()));
2571 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2572 Q.getLocalEndLoc());
2573 break;
2574 }
2575
2576 case NestedNameSpecifier::Global:
2577 // There is no meaningful transformation that one could perform on the
2578 // global scope.
2579 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2580 break;
2581
2582 case NestedNameSpecifier::TypeSpecWithTemplate:
2583 case NestedNameSpecifier::TypeSpec: {
2584 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2585 FirstQualifierInScope, SS);
2586
2587 if (!TL)
2588 return NestedNameSpecifierLoc();
2589
2590 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2591 (SemaRef.getLangOptions().CPlusPlus0x &&
2592 TL.getType()->isEnumeralType())) {
2593 assert(!TL.getType().hasLocalQualifiers() &&
2594 "Can't get cv-qualifiers here");
2595 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2596 Q.getLocalEndLoc());
2597 break;
2598 }
2599
2600 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2601 << TL.getType() << SS.getRange();
2602 return NestedNameSpecifierLoc();
2603 }
2604 }
2605
Douglas Gregorf3db29f2011-02-25 18:19:59 +00002606 // The qualifier-in-scope only applies to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002607 FirstQualifierInScope = 0;
2608 }
2609
2610 // Don't rebuild the nested-name-specifier if we don't have to.
2611 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2612 !getDerived().AlwaysRebuild())
2613 return NNS;
2614
2615 // If we can re-use the source-location data from the original
2616 // nested-name-specifier, do so.
2617 if (SS.location_size() == NNS.getDataLength() &&
2618 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2619 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2620
2621 // Allocate new nested-name-specifier location information.
2622 return SS.getWithLocInContext(SemaRef.Context);
2623}
2624
2625template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002626DeclarationNameInfo
2627TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002628::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002629 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002630 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002631 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002632
2633 switch (Name.getNameKind()) {
2634 case DeclarationName::Identifier:
2635 case DeclarationName::ObjCZeroArgSelector:
2636 case DeclarationName::ObjCOneArgSelector:
2637 case DeclarationName::ObjCMultiArgSelector:
2638 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002639 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002640 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002641 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002642
Douglas Gregor81499bb2009-09-03 22:13:48 +00002643 case DeclarationName::CXXConstructorName:
2644 case DeclarationName::CXXDestructorName:
2645 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002646 TypeSourceInfo *NewTInfo;
2647 CanQualType NewCanTy;
2648 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002649 NewTInfo = getDerived().TransformType(OldTInfo);
2650 if (!NewTInfo)
2651 return DeclarationNameInfo();
2652 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002653 }
2654 else {
2655 NewTInfo = 0;
2656 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002657 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002658 if (NewT.isNull())
2659 return DeclarationNameInfo();
2660 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2661 }
Mike Stump1eb44332009-09-09 15:08:12 +00002662
Abramo Bagnara25777432010-08-11 22:01:17 +00002663 DeclarationName NewName
2664 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2665 NewCanTy);
2666 DeclarationNameInfo NewNameInfo(NameInfo);
2667 NewNameInfo.setName(NewName);
2668 NewNameInfo.setNamedTypeInfo(NewTInfo);
2669 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002670 }
Mike Stump1eb44332009-09-09 15:08:12 +00002671 }
2672
Abramo Bagnara25777432010-08-11 22:01:17 +00002673 assert(0 && "Unknown name kind.");
2674 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002675}
2676
2677template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002678TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002679TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002680 QualType ObjectType,
2681 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002682 SourceLocation Loc = getDerived().getBaseLocation();
2683
Douglas Gregord1067e52009-08-06 06:41:21 +00002684 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002685 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002686 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002687 /*FIXME*/ SourceRange(Loc),
2688 ObjectType,
2689 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002690 if (!NNS)
2691 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002692
Douglas Gregord1067e52009-08-06 06:41:21 +00002693 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002694 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002695 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002696 if (!TransTemplate)
2697 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002698
Douglas Gregord1067e52009-08-06 06:41:21 +00002699 if (!getDerived().AlwaysRebuild() &&
2700 NNS == QTN->getQualifier() &&
2701 TransTemplate == Template)
2702 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002703
Douglas Gregord1067e52009-08-06 06:41:21 +00002704 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2705 TransTemplate);
2706 }
Mike Stump1eb44332009-09-09 15:08:12 +00002707
John McCallf7a1a742009-11-24 19:00:30 +00002708 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002709 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002710 }
Mike Stump1eb44332009-09-09 15:08:12 +00002711
Douglas Gregord1067e52009-08-06 06:41:21 +00002712 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002713 NestedNameSpecifier *NNS = DTN->getQualifier();
2714 if (NNS) {
2715 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2716 /*FIXME:*/SourceRange(Loc),
2717 ObjectType,
2718 FirstQualifierInScope);
2719 if (!NNS) return TemplateName();
2720
2721 // These apply to the scope specifier, not the template.
2722 ObjectType = QualType();
2723 FirstQualifierInScope = 0;
2724 }
Mike Stump1eb44332009-09-09 15:08:12 +00002725
Douglas Gregord1067e52009-08-06 06:41:21 +00002726 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002727 NNS == DTN->getQualifier() &&
2728 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002729 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002730
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002731 if (DTN->isIdentifier()) {
2732 // FIXME: Bad range
2733 SourceRange QualifierRange(getDerived().getBaseLocation());
2734 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2735 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002736 ObjectType,
2737 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002738 }
Sean Huntc3021132010-05-05 15:23:54 +00002739
2740 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002741 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002742 }
Mike Stump1eb44332009-09-09 15:08:12 +00002743
Douglas Gregord1067e52009-08-06 06:41:21 +00002744 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002745 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002746 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002747 if (!TransTemplate)
2748 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002749
Douglas Gregord1067e52009-08-06 06:41:21 +00002750 if (!getDerived().AlwaysRebuild() &&
2751 TransTemplate == Template)
2752 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002753
Douglas Gregord1067e52009-08-06 06:41:21 +00002754 return TemplateName(TransTemplate);
2755 }
Mike Stump1eb44332009-09-09 15:08:12 +00002756
Douglas Gregor1aee05d2011-01-15 06:45:20 +00002757 if (SubstTemplateTemplateParmPackStorage *SubstPack
2758 = Name.getAsSubstTemplateTemplateParmPack()) {
2759 TemplateTemplateParmDecl *TransParam
2760 = cast_or_null<TemplateTemplateParmDecl>(
2761 getDerived().TransformDecl(Loc, SubstPack->getParameterPack()));
2762 if (!TransParam)
2763 return TemplateName();
2764
2765 if (!getDerived().AlwaysRebuild() &&
2766 TransParam == SubstPack->getParameterPack())
2767 return Name;
2768
2769 return getDerived().RebuildTemplateName(TransParam,
2770 SubstPack->getArgumentPack());
2771 }
2772
John McCallf7a1a742009-11-24 19:00:30 +00002773 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002774 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002775 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002776}
2777
2778template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002779void TreeTransform<Derived>::InventTemplateArgumentLoc(
2780 const TemplateArgument &Arg,
2781 TemplateArgumentLoc &Output) {
2782 SourceLocation Loc = getDerived().getBaseLocation();
2783 switch (Arg.getKind()) {
2784 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002785 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002786 break;
2787
2788 case TemplateArgument::Type:
2789 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002790 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002791
John McCall833ca992009-10-29 08:12:44 +00002792 break;
2793
Douglas Gregor788cd062009-11-11 01:00:40 +00002794 case TemplateArgument::Template:
2795 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2796 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002797
2798 case TemplateArgument::TemplateExpansion:
2799 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2800 break;
2801
John McCall833ca992009-10-29 08:12:44 +00002802 case TemplateArgument::Expression:
2803 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2804 break;
2805
2806 case TemplateArgument::Declaration:
2807 case TemplateArgument::Integral:
2808 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002809 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002810 break;
2811 }
2812}
2813
2814template<typename Derived>
2815bool TreeTransform<Derived>::TransformTemplateArgument(
2816 const TemplateArgumentLoc &Input,
2817 TemplateArgumentLoc &Output) {
2818 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002819 switch (Arg.getKind()) {
2820 case TemplateArgument::Null:
2821 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002822 Output = Input;
2823 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002824
Douglas Gregor670444e2009-08-04 22:27:00 +00002825 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002826 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002827 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002828 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002829
2830 DI = getDerived().TransformType(DI);
2831 if (!DI) return true;
2832
2833 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2834 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002835 }
Mike Stump1eb44332009-09-09 15:08:12 +00002836
Douglas Gregor670444e2009-08-04 22:27:00 +00002837 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002838 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002839 DeclarationName Name;
2840 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2841 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002842 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002843 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002844 if (!D) return true;
2845
John McCall828bff22009-10-29 18:45:58 +00002846 Expr *SourceExpr = Input.getSourceDeclExpression();
2847 if (SourceExpr) {
2848 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002849 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002850 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002851 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002852 }
2853
2854 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002855 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002856 }
Mike Stump1eb44332009-09-09 15:08:12 +00002857
Douglas Gregor788cd062009-11-11 01:00:40 +00002858 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002859 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002860 TemplateName Template
2861 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2862 if (Template.isNull())
2863 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002864
Douglas Gregor788cd062009-11-11 01:00:40 +00002865 Output = TemplateArgumentLoc(TemplateArgument(Template),
2866 Input.getTemplateQualifierRange(),
2867 Input.getTemplateNameLoc());
2868 return false;
2869 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002870
2871 case TemplateArgument::TemplateExpansion:
2872 llvm_unreachable("Caller should expand pack expansions");
2873
Douglas Gregor670444e2009-08-04 22:27:00 +00002874 case TemplateArgument::Expression: {
2875 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002876 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002877 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002878
John McCall833ca992009-10-29 08:12:44 +00002879 Expr *InputExpr = Input.getSourceExpression();
2880 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2881
John McCall60d7b3a2010-08-24 06:29:42 +00002882 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002883 = getDerived().TransformExpr(InputExpr);
2884 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002885 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002886 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002887 }
Mike Stump1eb44332009-09-09 15:08:12 +00002888
Douglas Gregor670444e2009-08-04 22:27:00 +00002889 case TemplateArgument::Pack: {
2890 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2891 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002892 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002893 AEnd = Arg.pack_end();
2894 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002895
John McCall833ca992009-10-29 08:12:44 +00002896 // FIXME: preserve source information here when we start
2897 // caring about parameter packs.
2898
John McCall828bff22009-10-29 18:45:58 +00002899 TemplateArgumentLoc InputArg;
2900 TemplateArgumentLoc OutputArg;
2901 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2902 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002903 return true;
2904
John McCall828bff22009-10-29 18:45:58 +00002905 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002906 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002907
2908 TemplateArgument *TransformedArgsPtr
2909 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2910 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2911 TransformedArgsPtr);
2912 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2913 TransformedArgs.size()),
2914 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002915 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002916 }
2917 }
Mike Stump1eb44332009-09-09 15:08:12 +00002918
Douglas Gregor670444e2009-08-04 22:27:00 +00002919 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002920 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002921}
2922
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002923/// \brief Iterator adaptor that invents template argument location information
2924/// for each of the template arguments in its underlying iterator.
2925template<typename Derived, typename InputIterator>
2926class TemplateArgumentLocInventIterator {
2927 TreeTransform<Derived> &Self;
2928 InputIterator Iter;
2929
2930public:
2931 typedef TemplateArgumentLoc value_type;
2932 typedef TemplateArgumentLoc reference;
2933 typedef typename std::iterator_traits<InputIterator>::difference_type
2934 difference_type;
2935 typedef std::input_iterator_tag iterator_category;
2936
2937 class pointer {
2938 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002939
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002940 public:
2941 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2942
2943 const TemplateArgumentLoc *operator->() const { return &Arg; }
2944 };
2945
2946 TemplateArgumentLocInventIterator() { }
2947
2948 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2949 InputIterator Iter)
2950 : Self(Self), Iter(Iter) { }
2951
2952 TemplateArgumentLocInventIterator &operator++() {
2953 ++Iter;
2954 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002955 }
2956
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002957 TemplateArgumentLocInventIterator operator++(int) {
2958 TemplateArgumentLocInventIterator Old(*this);
2959 ++(*this);
2960 return Old;
2961 }
2962
2963 reference operator*() const {
2964 TemplateArgumentLoc Result;
2965 Self.InventTemplateArgumentLoc(*Iter, Result);
2966 return Result;
2967 }
2968
2969 pointer operator->() const { return pointer(**this); }
2970
2971 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2972 const TemplateArgumentLocInventIterator &Y) {
2973 return X.Iter == Y.Iter;
2974 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002975
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002976 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2977 const TemplateArgumentLocInventIterator &Y) {
2978 return X.Iter != Y.Iter;
2979 }
2980};
2981
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002982template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002983template<typename InputIterator>
2984bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2985 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002986 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002987 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002988 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002989 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002990
2991 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2992 // Unpack argument packs, which we translate them into separate
2993 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002994 // FIXME: We could do much better if we could guarantee that the
2995 // TemplateArgumentLocInfo for the pack expansion would be usable for
2996 // all of the template arguments in the argument pack.
2997 typedef TemplateArgumentLocInventIterator<Derived,
2998 TemplateArgument::pack_iterator>
2999 PackLocIterator;
3000 if (TransformTemplateArguments(PackLocIterator(*this,
3001 In.getArgument().pack_begin()),
3002 PackLocIterator(*this,
3003 In.getArgument().pack_end()),
3004 Outputs))
3005 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003006
3007 continue;
3008 }
3009
3010 if (In.getArgument().isPackExpansion()) {
3011 // We have a pack expansion, for which we will be substituting into
3012 // the pattern.
3013 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003014 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003015 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003016 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3017 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003018
3019 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3020 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3021 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3022
3023 // Determine whether the set of unexpanded parameter packs can and should
3024 // be expanded.
3025 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003026 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003027 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003028 if (getDerived().TryExpandParameterPacks(Ellipsis,
3029 Pattern.getSourceRange(),
3030 Unexpanded.data(),
3031 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003032 Expand,
3033 RetainExpansion,
3034 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003035 return true;
3036
3037 if (!Expand) {
3038 // The transform has determined that we should perform a simple
3039 // transformation on the pack expansion, producing another pack
3040 // expansion.
3041 TemplateArgumentLoc OutPattern;
3042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3043 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3044 return true;
3045
Douglas Gregorcded4f62011-01-14 17:04:44 +00003046 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3047 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003048 if (Out.getArgument().isNull())
3049 return true;
3050
3051 Outputs.addArgument(Out);
3052 continue;
3053 }
3054
3055 // The transform has determined that we should perform an elementwise
3056 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003057 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3059
3060 if (getDerived().TransformTemplateArgument(Pattern, Out))
3061 return true;
3062
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003063 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003064 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3065 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003066 if (Out.getArgument().isNull())
3067 return true;
3068 }
3069
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003070 Outputs.addArgument(Out);
3071 }
3072
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003073 // If we're supposed to retain a pack expansion, do so by temporarily
3074 // forgetting the partially-substituted parameter pack.
3075 if (RetainExpansion) {
3076 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3077
3078 if (getDerived().TransformTemplateArgument(Pattern, Out))
3079 return true;
3080
Douglas Gregorcded4f62011-01-14 17:04:44 +00003081 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3082 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003083 if (Out.getArgument().isNull())
3084 return true;
3085
3086 Outputs.addArgument(Out);
3087 }
Douglas Gregord3731192011-01-10 07:32:04 +00003088
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003089 continue;
3090 }
3091
3092 // The simple case:
3093 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003094 return true;
3095
3096 Outputs.addArgument(Out);
3097 }
3098
3099 return false;
3100
3101}
3102
Douglas Gregor577f75a2009-08-04 16:50:30 +00003103//===----------------------------------------------------------------------===//
3104// Type transformation
3105//===----------------------------------------------------------------------===//
3106
3107template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003108QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003109 if (getDerived().AlreadyTransformed(T))
3110 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003111
John McCalla2becad2009-10-21 00:40:46 +00003112 // Temporary workaround. All of these transformations should
3113 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003114 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3115 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003116
John McCall43fed0d2010-11-12 08:19:04 +00003117 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003118
John McCalla2becad2009-10-21 00:40:46 +00003119 if (!NewDI)
3120 return QualType();
3121
3122 return NewDI->getType();
3123}
3124
3125template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003126TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003127 if (getDerived().AlreadyTransformed(DI->getType()))
3128 return DI;
3129
3130 TypeLocBuilder TLB;
3131
3132 TypeLoc TL = DI->getTypeLoc();
3133 TLB.reserve(TL.getFullDataSize());
3134
John McCall43fed0d2010-11-12 08:19:04 +00003135 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003136 if (Result.isNull())
3137 return 0;
3138
John McCalla93c9342009-12-07 02:54:59 +00003139 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003140}
3141
3142template<typename Derived>
3143QualType
John McCall43fed0d2010-11-12 08:19:04 +00003144TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003145 switch (T.getTypeLocClass()) {
3146#define ABSTRACT_TYPELOC(CLASS, PARENT)
3147#define TYPELOC(CLASS, PARENT) \
3148 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003149 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003150#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003151 }
Mike Stump1eb44332009-09-09 15:08:12 +00003152
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003153 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003154 return QualType();
3155}
3156
3157/// FIXME: By default, this routine adds type qualifiers only to types
3158/// that can have qualifiers, and silently suppresses those qualifiers
3159/// that are not permitted (e.g., qualifiers on reference or function
3160/// types). This is the right thing for template instantiation, but
3161/// probably not for other clients.
3162template<typename Derived>
3163QualType
3164TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003165 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003166 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003167
John McCall43fed0d2010-11-12 08:19:04 +00003168 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003169 if (Result.isNull())
3170 return QualType();
3171
3172 // Silently suppress qualifiers if the result type can't be qualified.
3173 // FIXME: this is the right thing for template instantiation, but
3174 // probably not for other clients.
3175 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003176 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003177
John McCall28654742010-06-05 06:41:15 +00003178 if (!Quals.empty()) {
3179 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3180 TLB.push<QualifiedTypeLoc>(Result);
3181 // No location information to preserve.
3182 }
John McCalla2becad2009-10-21 00:40:46 +00003183
3184 return Result;
3185}
3186
John McCall43fed0d2010-11-12 08:19:04 +00003187/// \brief Transforms a type that was written in a scope specifier,
3188/// given an object type, the results of unqualified lookup, and
3189/// an already-instantiated prefix.
3190///
3191/// The object type is provided iff the scope specifier qualifies the
3192/// member of a dependent member-access expression. The prefix is
3193/// provided iff the the scope specifier in which this appears has a
3194/// prefix.
3195///
3196/// This is private to TreeTransform.
3197template<typename Derived>
3198QualType
3199TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3200 QualType ObjectType,
3201 NamedDecl *UnqualLookup,
3202 NestedNameSpecifier *Prefix) {
3203 if (getDerived().AlreadyTransformed(T))
3204 return T;
3205
3206 TypeSourceInfo *TSI =
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003207 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall43fed0d2010-11-12 08:19:04 +00003208
3209 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3210 UnqualLookup, Prefix);
3211 if (!TSI) return QualType();
3212 return TSI->getType();
3213}
3214
3215template<typename Derived>
3216TypeSourceInfo *
3217TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3218 QualType ObjectType,
3219 NamedDecl *UnqualLookup,
3220 NestedNameSpecifier *Prefix) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003221 // TODO: in some cases, we might have some verification to do here.
John McCall43fed0d2010-11-12 08:19:04 +00003222 if (ObjectType.isNull())
3223 return getDerived().TransformType(TSI);
3224
3225 QualType T = TSI->getType();
3226 if (getDerived().AlreadyTransformed(T))
3227 return TSI;
3228
3229 TypeLocBuilder TLB;
3230 QualType Result;
3231
3232 if (isa<TemplateSpecializationType>(T)) {
3233 TemplateSpecializationTypeLoc TL
3234 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3235
3236 TemplateName Template =
3237 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3238 ObjectType, UnqualLookup);
3239 if (Template.isNull()) return 0;
3240
3241 Result = getDerived()
3242 .TransformTemplateSpecializationType(TLB, TL, Template);
3243 } else if (isa<DependentTemplateSpecializationType>(T)) {
3244 DependentTemplateSpecializationTypeLoc TL
3245 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3246
Douglas Gregora88f09f2011-02-28 17:23:35 +00003247 TemplateName Template
3248 = SemaRef.Context.getDependentTemplateName(
3249 TL.getTypePtr()->getQualifier(),
3250 TL.getTypePtr()->getIdentifier());
3251
3252 Template = getDerived().TransformTemplateName(Template, ObjectType,
3253 UnqualLookup);
3254 if (Template.isNull())
3255 return 0;
3256
3257 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, TL,
3258 Template);
John McCall43fed0d2010-11-12 08:19:04 +00003259 } else {
3260 // Nothing special needs to be done for these.
3261 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3262 }
3263
3264 if (Result.isNull()) return 0;
3265 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3266}
3267
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003268template<typename Derived>
3269TypeLoc
3270TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3271 QualType ObjectType,
3272 NamedDecl *UnqualLookup,
3273 CXXScopeSpec &SS) {
3274 // FIXME: Painfully copy-paste from the above!
3275
3276 // TODO: in some cases, we might have some verification to do here.
3277 if (ObjectType.isNull()) {
3278 TypeLocBuilder TLB;
3279 TLB.reserve(TL.getFullDataSize());
3280 QualType Result = getDerived().TransformType(TLB, TL);
3281 if (Result.isNull())
3282 return TypeLoc();
3283
3284 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3285 }
3286
3287 QualType T = TL.getType();
3288 if (getDerived().AlreadyTransformed(T))
3289 return TL;
3290
3291 TypeLocBuilder TLB;
3292 QualType Result;
3293
3294 if (isa<TemplateSpecializationType>(T)) {
3295 TemplateSpecializationTypeLoc SpecTL
3296 = cast<TemplateSpecializationTypeLoc>(TL);
3297
3298 TemplateName Template =
3299 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3300 ObjectType, UnqualLookup);
3301 if (Template.isNull())
3302 return TypeLoc();
3303
3304 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3305 Template);
3306 } else if (isa<DependentTemplateSpecializationType>(T)) {
3307 DependentTemplateSpecializationTypeLoc SpecTL
3308 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3309
Douglas Gregora88f09f2011-02-28 17:23:35 +00003310 TemplateName Template
3311 = SemaRef.Context.getDependentTemplateName(
3312 SpecTL.getTypePtr()->getQualifier(),
3313 SpecTL.getTypePtr()->getIdentifier());
3314
3315 Template = getDerived().TransformTemplateName(Template, ObjectType,
3316 UnqualLookup);
3317 if (Template.isNull())
3318 return TypeLoc();
3319
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003320 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003321 SpecTL,
3322 Template);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003323 } else {
3324 // Nothing special needs to be done for these.
3325 Result = getDerived().TransformType(TLB, TL);
3326 }
3327
3328 if (Result.isNull())
3329 return TypeLoc();
3330
3331 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3332}
3333
John McCalla2becad2009-10-21 00:40:46 +00003334template <class TyLoc> static inline
3335QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3336 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3337 NewT.setNameLoc(T.getNameLoc());
3338 return T.getType();
3339}
3340
John McCalla2becad2009-10-21 00:40:46 +00003341template<typename Derived>
3342QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003343 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003344 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3345 NewT.setBuiltinLoc(T.getBuiltinLoc());
3346 if (T.needsExtraLocalData())
3347 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3348 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349}
Mike Stump1eb44332009-09-09 15:08:12 +00003350
Douglas Gregor577f75a2009-08-04 16:50:30 +00003351template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003352QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003353 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003354 // FIXME: recurse?
3355 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003356}
Mike Stump1eb44332009-09-09 15:08:12 +00003357
Douglas Gregor577f75a2009-08-04 16:50:30 +00003358template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003359QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003360 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003361 QualType PointeeType
3362 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003363 if (PointeeType.isNull())
3364 return QualType();
3365
3366 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003367 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003368 // A dependent pointer type 'T *' has is being transformed such
3369 // that an Objective-C class type is being replaced for 'T'. The
3370 // resulting pointer type is an ObjCObjectPointerType, not a
3371 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003372 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003373
John McCallc12c5bb2010-05-15 11:32:37 +00003374 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3375 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003376 return Result;
3377 }
John McCall43fed0d2010-11-12 08:19:04 +00003378
Douglas Gregor92e986e2010-04-22 16:44:27 +00003379 if (getDerived().AlwaysRebuild() ||
3380 PointeeType != TL.getPointeeLoc().getType()) {
3381 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3382 if (Result.isNull())
3383 return QualType();
3384 }
Sean Huntc3021132010-05-05 15:23:54 +00003385
Douglas Gregor92e986e2010-04-22 16:44:27 +00003386 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3387 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003388 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003389}
Mike Stump1eb44332009-09-09 15:08:12 +00003390
3391template<typename Derived>
3392QualType
John McCalla2becad2009-10-21 00:40:46 +00003393TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003394 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003395 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003396 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3397 if (PointeeType.isNull())
3398 return QualType();
3399
3400 QualType Result = TL.getType();
3401 if (getDerived().AlwaysRebuild() ||
3402 PointeeType != TL.getPointeeLoc().getType()) {
3403 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003404 TL.getSigilLoc());
3405 if (Result.isNull())
3406 return QualType();
3407 }
3408
Douglas Gregor39968ad2010-04-22 16:50:51 +00003409 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003410 NewT.setSigilLoc(TL.getSigilLoc());
3411 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003412}
3413
John McCall85737a72009-10-30 00:06:24 +00003414/// Transforms a reference type. Note that somewhat paradoxically we
3415/// don't care whether the type itself is an l-value type or an r-value
3416/// type; we only care if the type was *written* as an l-value type
3417/// or an r-value type.
3418template<typename Derived>
3419QualType
3420TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003421 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003422 const ReferenceType *T = TL.getTypePtr();
3423
3424 // Note that this works with the pointee-as-written.
3425 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3426 if (PointeeType.isNull())
3427 return QualType();
3428
3429 QualType Result = TL.getType();
3430 if (getDerived().AlwaysRebuild() ||
3431 PointeeType != T->getPointeeTypeAsWritten()) {
3432 Result = getDerived().RebuildReferenceType(PointeeType,
3433 T->isSpelledAsLValue(),
3434 TL.getSigilLoc());
3435 if (Result.isNull())
3436 return QualType();
3437 }
3438
3439 // r-value references can be rebuilt as l-value references.
3440 ReferenceTypeLoc NewTL;
3441 if (isa<LValueReferenceType>(Result))
3442 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3443 else
3444 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3445 NewTL.setSigilLoc(TL.getSigilLoc());
3446
3447 return Result;
3448}
3449
Mike Stump1eb44332009-09-09 15:08:12 +00003450template<typename Derived>
3451QualType
John McCalla2becad2009-10-21 00:40:46 +00003452TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003453 LValueReferenceTypeLoc TL) {
3454 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003455}
3456
Mike Stump1eb44332009-09-09 15:08:12 +00003457template<typename Derived>
3458QualType
John McCalla2becad2009-10-21 00:40:46 +00003459TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003460 RValueReferenceTypeLoc TL) {
3461 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003462}
Mike Stump1eb44332009-09-09 15:08:12 +00003463
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003465QualType
John McCalla2becad2009-10-21 00:40:46 +00003466TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003467 MemberPointerTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003468 const MemberPointerType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003469
3470 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003471 if (PointeeType.isNull())
3472 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003473
John McCalla2becad2009-10-21 00:40:46 +00003474 // TODO: preserve source information for this.
3475 QualType ClassType
3476 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003477 if (ClassType.isNull())
3478 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003479
John McCalla2becad2009-10-21 00:40:46 +00003480 QualType Result = TL.getType();
3481 if (getDerived().AlwaysRebuild() ||
3482 PointeeType != T->getPointeeType() ||
3483 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003484 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3485 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003486 if (Result.isNull())
3487 return QualType();
3488 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003489
John McCalla2becad2009-10-21 00:40:46 +00003490 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3491 NewTL.setSigilLoc(TL.getSigilLoc());
3492
3493 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003494}
3495
Mike Stump1eb44332009-09-09 15:08:12 +00003496template<typename Derived>
3497QualType
John McCalla2becad2009-10-21 00:40:46 +00003498TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003499 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003500 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003501 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502 if (ElementType.isNull())
3503 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003504
John McCalla2becad2009-10-21 00:40:46 +00003505 QualType Result = TL.getType();
3506 if (getDerived().AlwaysRebuild() ||
3507 ElementType != T->getElementType()) {
3508 Result = getDerived().RebuildConstantArrayType(ElementType,
3509 T->getSizeModifier(),
3510 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003511 T->getIndexTypeCVRQualifiers(),
3512 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003513 if (Result.isNull())
3514 return QualType();
3515 }
Sean Huntc3021132010-05-05 15:23:54 +00003516
John McCalla2becad2009-10-21 00:40:46 +00003517 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3518 NewTL.setLBracketLoc(TL.getLBracketLoc());
3519 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003520
John McCalla2becad2009-10-21 00:40:46 +00003521 Expr *Size = TL.getSizeExpr();
3522 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003523 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003524 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3525 }
3526 NewTL.setSizeExpr(Size);
3527
3528 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003529}
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor577f75a2009-08-04 16:50:30 +00003531template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003532QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003533 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003534 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003535 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003536 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003537 if (ElementType.isNull())
3538 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003539
John McCalla2becad2009-10-21 00:40:46 +00003540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 ElementType != T->getElementType()) {
3543 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003544 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003545 T->getIndexTypeCVRQualifiers(),
3546 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003547 if (Result.isNull())
3548 return QualType();
3549 }
Sean Huntc3021132010-05-05 15:23:54 +00003550
John McCalla2becad2009-10-21 00:40:46 +00003551 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3552 NewTL.setLBracketLoc(TL.getLBracketLoc());
3553 NewTL.setRBracketLoc(TL.getRBracketLoc());
3554 NewTL.setSizeExpr(0);
3555
3556 return Result;
3557}
3558
3559template<typename Derived>
3560QualType
3561TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003562 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003563 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003564 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3565 if (ElementType.isNull())
3566 return QualType();
3567
3568 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003569 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003570
John McCall60d7b3a2010-08-24 06:29:42 +00003571 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003572 = getDerived().TransformExpr(T->getSizeExpr());
3573 if (SizeResult.isInvalid())
3574 return QualType();
3575
John McCall9ae2f072010-08-23 23:25:46 +00003576 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003577
3578 QualType Result = TL.getType();
3579 if (getDerived().AlwaysRebuild() ||
3580 ElementType != T->getElementType() ||
3581 Size != T->getSizeExpr()) {
3582 Result = getDerived().RebuildVariableArrayType(ElementType,
3583 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003584 Size,
John McCalla2becad2009-10-21 00:40:46 +00003585 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003586 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003587 if (Result.isNull())
3588 return QualType();
3589 }
Sean Huntc3021132010-05-05 15:23:54 +00003590
John McCalla2becad2009-10-21 00:40:46 +00003591 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3592 NewTL.setLBracketLoc(TL.getLBracketLoc());
3593 NewTL.setRBracketLoc(TL.getRBracketLoc());
3594 NewTL.setSizeExpr(Size);
3595
3596 return Result;
3597}
3598
3599template<typename Derived>
3600QualType
3601TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003602 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003603 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003604 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3605 if (ElementType.isNull())
3606 return QualType();
3607
3608 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003609 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003610
John McCall3b657512011-01-19 10:06:00 +00003611 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3612 Expr *origSize = TL.getSizeExpr();
3613 if (!origSize) origSize = T->getSizeExpr();
3614
3615 ExprResult sizeResult
3616 = getDerived().TransformExpr(origSize);
3617 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003618 return QualType();
3619
John McCall3b657512011-01-19 10:06:00 +00003620 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003621
3622 QualType Result = TL.getType();
3623 if (getDerived().AlwaysRebuild() ||
3624 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003625 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003626 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3627 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003628 size,
John McCalla2becad2009-10-21 00:40:46 +00003629 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003630 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003631 if (Result.isNull())
3632 return QualType();
3633 }
John McCalla2becad2009-10-21 00:40:46 +00003634
3635 // We might have any sort of array type now, but fortunately they
3636 // all have the same location layout.
3637 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3638 NewTL.setLBracketLoc(TL.getLBracketLoc());
3639 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003640 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003641
3642 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003643}
Mike Stump1eb44332009-09-09 15:08:12 +00003644
3645template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003646QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003647 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003648 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003649 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003650
3651 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003652 QualType ElementType = getDerived().TransformType(T->getElementType());
3653 if (ElementType.isNull())
3654 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003655
Douglas Gregor670444e2009-08-04 22:27:00 +00003656 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003657 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003658
John McCall60d7b3a2010-08-24 06:29:42 +00003659 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660 if (Size.isInvalid())
3661 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003662
John McCalla2becad2009-10-21 00:40:46 +00003663 QualType Result = TL.getType();
3664 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003665 ElementType != T->getElementType() ||
3666 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003667 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003668 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003669 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003670 if (Result.isNull())
3671 return QualType();
3672 }
John McCalla2becad2009-10-21 00:40:46 +00003673
3674 // Result might be dependent or not.
3675 if (isa<DependentSizedExtVectorType>(Result)) {
3676 DependentSizedExtVectorTypeLoc NewTL
3677 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3678 NewTL.setNameLoc(TL.getNameLoc());
3679 } else {
3680 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3681 NewTL.setNameLoc(TL.getNameLoc());
3682 }
3683
3684 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685}
Mike Stump1eb44332009-09-09 15:08:12 +00003686
3687template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003688QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003689 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003690 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003691 QualType ElementType = getDerived().TransformType(T->getElementType());
3692 if (ElementType.isNull())
3693 return QualType();
3694
John McCalla2becad2009-10-21 00:40:46 +00003695 QualType Result = TL.getType();
3696 if (getDerived().AlwaysRebuild() ||
3697 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003698 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003699 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003700 if (Result.isNull())
3701 return QualType();
3702 }
Sean Huntc3021132010-05-05 15:23:54 +00003703
John McCalla2becad2009-10-21 00:40:46 +00003704 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3705 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003706
John McCalla2becad2009-10-21 00:40:46 +00003707 return Result;
3708}
3709
3710template<typename Derived>
3711QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003712 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003713 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003714 QualType ElementType = getDerived().TransformType(T->getElementType());
3715 if (ElementType.isNull())
3716 return QualType();
3717
3718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 ElementType != T->getElementType()) {
3721 Result = getDerived().RebuildExtVectorType(ElementType,
3722 T->getNumElements(),
3723 /*FIXME*/ SourceLocation());
3724 if (Result.isNull())
3725 return QualType();
3726 }
Sean Huntc3021132010-05-05 15:23:54 +00003727
John McCalla2becad2009-10-21 00:40:46 +00003728 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3729 NewTL.setNameLoc(TL.getNameLoc());
3730
3731 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003732}
Mike Stump1eb44332009-09-09 15:08:12 +00003733
3734template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003735ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003736TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3737 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003738 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003739 TypeSourceInfo *NewDI = 0;
3740
3741 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3742 // If we're substituting into a pack expansion type and we know the
3743 TypeLoc OldTL = OldDI->getTypeLoc();
3744 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3745
3746 TypeLocBuilder TLB;
3747 TypeLoc NewTL = OldDI->getTypeLoc();
3748 TLB.reserve(NewTL.getFullDataSize());
3749
3750 QualType Result = getDerived().TransformType(TLB,
3751 OldExpansionTL.getPatternLoc());
3752 if (Result.isNull())
3753 return 0;
3754
3755 Result = RebuildPackExpansionType(Result,
3756 OldExpansionTL.getPatternLoc().getSourceRange(),
3757 OldExpansionTL.getEllipsisLoc(),
3758 NumExpansions);
3759 if (Result.isNull())
3760 return 0;
3761
3762 PackExpansionTypeLoc NewExpansionTL
3763 = TLB.push<PackExpansionTypeLoc>(Result);
3764 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3765 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3766 } else
3767 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003768 if (!NewDI)
3769 return 0;
3770
3771 if (NewDI == OldDI)
3772 return OldParm;
3773 else
3774 return ParmVarDecl::Create(SemaRef.Context,
3775 OldParm->getDeclContext(),
3776 OldParm->getLocation(),
3777 OldParm->getIdentifier(),
3778 NewDI->getType(),
3779 NewDI,
3780 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003781 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003782 /* DefArg */ NULL);
3783}
3784
3785template<typename Derived>
3786bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003787 TransformFunctionTypeParams(SourceLocation Loc,
3788 ParmVarDecl **Params, unsigned NumParams,
3789 const QualType *ParamTypes,
3790 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3791 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3792 for (unsigned i = 0; i != NumParams; ++i) {
3793 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003794 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003795 if (OldParm->isParameterPack()) {
3796 // We have a function parameter pack that may need to be expanded.
3797 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003798
Douglas Gregor603cfb42011-01-05 23:12:31 +00003799 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003800 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3801 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3802 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3803 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003804
3805 // Determine whether we should expand the parameter packs.
3806 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003807 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003808 llvm::Optional<unsigned> OrigNumExpansions
3809 = ExpansionTL.getTypePtr()->getNumExpansions();
3810 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003811 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3812 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003813 Unexpanded.data(),
3814 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003815 ShouldExpand,
3816 RetainExpansion,
3817 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003818 return true;
3819 }
3820
3821 if (ShouldExpand) {
3822 // Expand the function parameter pack into multiple, separate
3823 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003824 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003825 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003826 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3827 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003828 = getDerived().TransformFunctionTypeParam(OldParm,
3829 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003830 if (!NewParm)
3831 return true;
3832
Douglas Gregora009b592011-01-07 00:20:55 +00003833 OutParamTypes.push_back(NewParm->getType());
3834 if (PVars)
3835 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003836 }
Douglas Gregord3731192011-01-10 07:32:04 +00003837
3838 // If we're supposed to retain a pack expansion, do so by temporarily
3839 // forgetting the partially-substituted parameter pack.
3840 if (RetainExpansion) {
3841 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3842 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003843 = getDerived().TransformFunctionTypeParam(OldParm,
3844 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003845 if (!NewParm)
3846 return true;
3847
3848 OutParamTypes.push_back(NewParm->getType());
3849 if (PVars)
3850 PVars->push_back(NewParm);
3851 }
3852
Douglas Gregor603cfb42011-01-05 23:12:31 +00003853 // We're done with the pack expansion.
3854 continue;
3855 }
3856
3857 // We'll substitute the parameter now without expanding the pack
3858 // expansion.
3859 }
3860
3861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003862 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3863 NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +00003864 if (!NewParm)
3865 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003866
Douglas Gregora009b592011-01-07 00:20:55 +00003867 OutParamTypes.push_back(NewParm->getType());
3868 if (PVars)
3869 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003870 continue;
3871 }
John McCall21ef0fa2010-03-11 09:03:00 +00003872
3873 // Deal with the possibility that we don't have a parameter
3874 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003875 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003876 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003877 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003878 if (const PackExpansionType *Expansion
3879 = dyn_cast<PackExpansionType>(OldType)) {
3880 // We have a function parameter pack that may need to be expanded.
3881 QualType Pattern = Expansion->getPattern();
3882 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3883 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3884
3885 // Determine whether we should expand the parameter packs.
3886 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003887 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003888 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003889 Unexpanded.data(),
3890 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003891 ShouldExpand,
3892 RetainExpansion,
3893 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003894 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003895 }
3896
3897 if (ShouldExpand) {
3898 // Expand the function parameter pack into multiple, separate
3899 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003900 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003901 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3902 QualType NewType = getDerived().TransformType(Pattern);
3903 if (NewType.isNull())
3904 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003905
Douglas Gregora009b592011-01-07 00:20:55 +00003906 OutParamTypes.push_back(NewType);
3907 if (PVars)
3908 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003909 }
3910
3911 // We're done with the pack expansion.
3912 continue;
3913 }
3914
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003915 // If we're supposed to retain a pack expansion, do so by temporarily
3916 // forgetting the partially-substituted parameter pack.
3917 if (RetainExpansion) {
3918 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3919 QualType NewType = getDerived().TransformType(Pattern);
3920 if (NewType.isNull())
3921 return true;
3922
3923 OutParamTypes.push_back(NewType);
3924 if (PVars)
3925 PVars->push_back(0);
3926 }
Douglas Gregord3731192011-01-10 07:32:04 +00003927
Douglas Gregor603cfb42011-01-05 23:12:31 +00003928 // We'll substitute the parameter now without expanding the pack
3929 // expansion.
3930 OldType = Expansion->getPattern();
3931 IsPackExpansion = true;
3932 }
3933
3934 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3935 QualType NewType = getDerived().TransformType(OldType);
3936 if (NewType.isNull())
3937 return true;
3938
3939 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003940 NewType = getSema().Context.getPackExpansionType(NewType,
3941 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003942
Douglas Gregora009b592011-01-07 00:20:55 +00003943 OutParamTypes.push_back(NewType);
3944 if (PVars)
3945 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003946 }
3947
3948 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003949 }
John McCall21ef0fa2010-03-11 09:03:00 +00003950
3951template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003952QualType
John McCalla2becad2009-10-21 00:40:46 +00003953TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003954 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003955 // Transform the parameters and return type.
3956 //
3957 // We instantiate in source order, with the return type first followed by
3958 // the parameters, because users tend to expect this (even if they shouldn't
3959 // rely on it!).
3960 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003961 // When the function has a trailing return type, we instantiate the
3962 // parameters before the return type, since the return type can then refer
3963 // to the parameters themselves (via decltype, sizeof, etc.).
3964 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003965 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003966 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003967 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003968
Douglas Gregordab60ad2010-10-01 18:44:50 +00003969 QualType ResultType;
3970
3971 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003972 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3973 TL.getParmArray(),
3974 TL.getNumArgs(),
3975 TL.getTypePtr()->arg_type_begin(),
3976 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003977 return QualType();
3978
3979 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3980 if (ResultType.isNull())
3981 return QualType();
3982 }
3983 else {
3984 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3985 if (ResultType.isNull())
3986 return QualType();
3987
Douglas Gregora009b592011-01-07 00:20:55 +00003988 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3989 TL.getParmArray(),
3990 TL.getNumArgs(),
3991 TL.getTypePtr()->arg_type_begin(),
3992 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003993 return QualType();
3994 }
3995
John McCalla2becad2009-10-21 00:40:46 +00003996 QualType Result = TL.getType();
3997 if (getDerived().AlwaysRebuild() ||
3998 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003999 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004000 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4001 Result = getDerived().RebuildFunctionProtoType(ResultType,
4002 ParamTypes.data(),
4003 ParamTypes.size(),
4004 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004005 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004006 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004007 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004008 if (Result.isNull())
4009 return QualType();
4010 }
Mike Stump1eb44332009-09-09 15:08:12 +00004011
John McCalla2becad2009-10-21 00:40:46 +00004012 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
4013 NewTL.setLParenLoc(TL.getLParenLoc());
4014 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004015 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004016 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4017 NewTL.setArg(i, ParamDecls[i]);
4018
4019 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004020}
Mike Stump1eb44332009-09-09 15:08:12 +00004021
Douglas Gregor577f75a2009-08-04 16:50:30 +00004022template<typename Derived>
4023QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004024 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004025 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004026 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004027 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4028 if (ResultType.isNull())
4029 return QualType();
4030
4031 QualType Result = TL.getType();
4032 if (getDerived().AlwaysRebuild() ||
4033 ResultType != T->getResultType())
4034 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4035
4036 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4037 NewTL.setLParenLoc(TL.getLParenLoc());
4038 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004039 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004040
4041 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004042}
Mike Stump1eb44332009-09-09 15:08:12 +00004043
John McCalled976492009-12-04 22:46:56 +00004044template<typename Derived> QualType
4045TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004046 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004047 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004048 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004049 if (!D)
4050 return QualType();
4051
4052 QualType Result = TL.getType();
4053 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4054 Result = getDerived().RebuildUnresolvedUsingType(D);
4055 if (Result.isNull())
4056 return QualType();
4057 }
4058
4059 // We might get an arbitrary type spec type back. We should at
4060 // least always get a type spec type, though.
4061 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4062 NewTL.setNameLoc(TL.getNameLoc());
4063
4064 return Result;
4065}
4066
Douglas Gregor577f75a2009-08-04 16:50:30 +00004067template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004068QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004069 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004070 const TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004071 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004072 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4073 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004074 if (!Typedef)
4075 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004076
John McCalla2becad2009-10-21 00:40:46 +00004077 QualType Result = TL.getType();
4078 if (getDerived().AlwaysRebuild() ||
4079 Typedef != T->getDecl()) {
4080 Result = getDerived().RebuildTypedefType(Typedef);
4081 if (Result.isNull())
4082 return QualType();
4083 }
Mike Stump1eb44332009-09-09 15:08:12 +00004084
John McCalla2becad2009-10-21 00:40:46 +00004085 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4086 NewTL.setNameLoc(TL.getNameLoc());
4087
4088 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004089}
Mike Stump1eb44332009-09-09 15:08:12 +00004090
Douglas Gregor577f75a2009-08-04 16:50:30 +00004091template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004092QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004093 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004094 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004095 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004096
John McCall60d7b3a2010-08-24 06:29:42 +00004097 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004098 if (E.isInvalid())
4099 return QualType();
4100
John McCalla2becad2009-10-21 00:40:46 +00004101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004103 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004104 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004105 if (Result.isNull())
4106 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004107 }
John McCalla2becad2009-10-21 00:40:46 +00004108 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004109
John McCalla2becad2009-10-21 00:40:46 +00004110 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004111 NewTL.setTypeofLoc(TL.getTypeofLoc());
4112 NewTL.setLParenLoc(TL.getLParenLoc());
4113 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004114
4115 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004116}
Mike Stump1eb44332009-09-09 15:08:12 +00004117
4118template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004119QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004120 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004121 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4122 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4123 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004124 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004125
John McCalla2becad2009-10-21 00:40:46 +00004126 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004127 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4128 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004129 if (Result.isNull())
4130 return QualType();
4131 }
Mike Stump1eb44332009-09-09 15:08:12 +00004132
John McCalla2becad2009-10-21 00:40:46 +00004133 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004134 NewTL.setTypeofLoc(TL.getTypeofLoc());
4135 NewTL.setLParenLoc(TL.getLParenLoc());
4136 NewTL.setRParenLoc(TL.getRParenLoc());
4137 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004138
4139 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004140}
Mike Stump1eb44332009-09-09 15:08:12 +00004141
4142template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004143QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004144 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004145 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004146
Douglas Gregor670444e2009-08-04 22:27:00 +00004147 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004148 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004149
John McCall60d7b3a2010-08-24 06:29:42 +00004150 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004151 if (E.isInvalid())
4152 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004153
John McCalla2becad2009-10-21 00:40:46 +00004154 QualType Result = TL.getType();
4155 if (getDerived().AlwaysRebuild() ||
4156 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004157 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004158 if (Result.isNull())
4159 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004160 }
John McCalla2becad2009-10-21 00:40:46 +00004161 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004162
John McCalla2becad2009-10-21 00:40:46 +00004163 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4164 NewTL.setNameLoc(TL.getNameLoc());
4165
4166 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004167}
4168
4169template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004170QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4171 AutoTypeLoc TL) {
4172 const AutoType *T = TL.getTypePtr();
4173 QualType OldDeduced = T->getDeducedType();
4174 QualType NewDeduced;
4175 if (!OldDeduced.isNull()) {
4176 NewDeduced = getDerived().TransformType(OldDeduced);
4177 if (NewDeduced.isNull())
4178 return QualType();
4179 }
4180
4181 QualType Result = TL.getType();
4182 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4183 Result = getDerived().RebuildAutoType(NewDeduced);
4184 if (Result.isNull())
4185 return QualType();
4186 }
4187
4188 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4189 NewTL.setNameLoc(TL.getNameLoc());
4190
4191 return Result;
4192}
4193
4194template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004195QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004196 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004197 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004198 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004199 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4200 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004201 if (!Record)
4202 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
John McCalla2becad2009-10-21 00:40:46 +00004204 QualType Result = TL.getType();
4205 if (getDerived().AlwaysRebuild() ||
4206 Record != T->getDecl()) {
4207 Result = getDerived().RebuildRecordType(Record);
4208 if (Result.isNull())
4209 return QualType();
4210 }
Mike Stump1eb44332009-09-09 15:08:12 +00004211
John McCalla2becad2009-10-21 00:40:46 +00004212 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4213 NewTL.setNameLoc(TL.getNameLoc());
4214
4215 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004216}
Mike Stump1eb44332009-09-09 15:08:12 +00004217
4218template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004219QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004220 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004221 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004222 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004223 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4224 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004225 if (!Enum)
4226 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004227
John McCalla2becad2009-10-21 00:40:46 +00004228 QualType Result = TL.getType();
4229 if (getDerived().AlwaysRebuild() ||
4230 Enum != T->getDecl()) {
4231 Result = getDerived().RebuildEnumType(Enum);
4232 if (Result.isNull())
4233 return QualType();
4234 }
Mike Stump1eb44332009-09-09 15:08:12 +00004235
John McCalla2becad2009-10-21 00:40:46 +00004236 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4237 NewTL.setNameLoc(TL.getNameLoc());
4238
4239 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004240}
John McCall7da24312009-09-05 00:15:47 +00004241
John McCall3cb0ebd2010-03-10 03:28:59 +00004242template<typename Derived>
4243QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4244 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004245 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004246 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4247 TL.getTypePtr()->getDecl());
4248 if (!D) return QualType();
4249
4250 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4251 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4252 return T;
4253}
4254
Douglas Gregor577f75a2009-08-04 16:50:30 +00004255template<typename Derived>
4256QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004257 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004258 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004259 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260}
4261
Mike Stump1eb44332009-09-09 15:08:12 +00004262template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004263QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004264 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004265 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004266 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00004267}
4268
4269template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004270QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4271 TypeLocBuilder &TLB,
4272 SubstTemplateTypeParmPackTypeLoc TL) {
4273 return TransformTypeSpecType(TLB, TL);
4274}
4275
4276template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004277QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004278 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004279 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004280 const TemplateSpecializationType *T = TL.getTypePtr();
4281
Mike Stump1eb44332009-09-09 15:08:12 +00004282 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00004283 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004284 if (Template.isNull())
4285 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004286
John McCall43fed0d2010-11-12 08:19:04 +00004287 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4288}
4289
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004290namespace {
4291 /// \brief Simple iterator that traverses the template arguments in a
4292 /// container that provides a \c getArgLoc() member function.
4293 ///
4294 /// This iterator is intended to be used with the iterator form of
4295 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4296 template<typename ArgLocContainer>
4297 class TemplateArgumentLocContainerIterator {
4298 ArgLocContainer *Container;
4299 unsigned Index;
4300
4301 public:
4302 typedef TemplateArgumentLoc value_type;
4303 typedef TemplateArgumentLoc reference;
4304 typedef int difference_type;
4305 typedef std::input_iterator_tag iterator_category;
4306
4307 class pointer {
4308 TemplateArgumentLoc Arg;
4309
4310 public:
4311 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4312
4313 const TemplateArgumentLoc *operator->() const {
4314 return &Arg;
4315 }
4316 };
4317
4318
4319 TemplateArgumentLocContainerIterator() {}
4320
4321 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4322 unsigned Index)
4323 : Container(&Container), Index(Index) { }
4324
4325 TemplateArgumentLocContainerIterator &operator++() {
4326 ++Index;
4327 return *this;
4328 }
4329
4330 TemplateArgumentLocContainerIterator operator++(int) {
4331 TemplateArgumentLocContainerIterator Old(*this);
4332 ++(*this);
4333 return Old;
4334 }
4335
4336 TemplateArgumentLoc operator*() const {
4337 return Container->getArgLoc(Index);
4338 }
4339
4340 pointer operator->() const {
4341 return pointer(Container->getArgLoc(Index));
4342 }
4343
4344 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004345 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004346 return X.Container == Y.Container && X.Index == Y.Index;
4347 }
4348
4349 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004350 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004351 return !(X == Y);
4352 }
4353 };
4354}
4355
4356
John McCall43fed0d2010-11-12 08:19:04 +00004357template <typename Derived>
4358QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4359 TypeLocBuilder &TLB,
4360 TemplateSpecializationTypeLoc TL,
4361 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004362 TemplateArgumentListInfo NewTemplateArgs;
4363 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4364 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004365 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4366 ArgIterator;
4367 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4368 ArgIterator(TL, TL.getNumArgs()),
4369 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004370 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004371
John McCall833ca992009-10-29 08:12:44 +00004372 // FIXME: maybe don't rebuild if all the template arguments are the same.
4373
4374 QualType Result =
4375 getDerived().RebuildTemplateSpecializationType(Template,
4376 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004377 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004378
4379 if (!Result.isNull()) {
4380 TemplateSpecializationTypeLoc NewTL
4381 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4382 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4383 NewTL.setLAngleLoc(TL.getLAngleLoc());
4384 NewTL.setRAngleLoc(TL.getRAngleLoc());
4385 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4386 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004387 }
Mike Stump1eb44332009-09-09 15:08:12 +00004388
John McCall833ca992009-10-29 08:12:44 +00004389 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004390}
Mike Stump1eb44332009-09-09 15:08:12 +00004391
Douglas Gregora88f09f2011-02-28 17:23:35 +00004392template <typename Derived>
4393QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4394 TypeLocBuilder &TLB,
4395 DependentTemplateSpecializationTypeLoc TL,
4396 TemplateName Template) {
4397 TemplateArgumentListInfo NewTemplateArgs;
4398 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4399 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4400 typedef TemplateArgumentLocContainerIterator<
4401 DependentTemplateSpecializationTypeLoc> ArgIterator;
4402 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4403 ArgIterator(TL, TL.getNumArgs()),
4404 NewTemplateArgs))
4405 return QualType();
4406
4407 // FIXME: maybe don't rebuild if all the template arguments are the same.
4408
4409 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4410 QualType Result
4411 = getSema().Context.getDependentTemplateSpecializationType(
4412 TL.getTypePtr()->getKeyword(),
4413 DTN->getQualifier(),
4414 DTN->getIdentifier(),
4415 NewTemplateArgs);
4416
4417 DependentTemplateSpecializationTypeLoc NewTL
4418 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4419 NewTL.setKeywordLoc(TL.getKeywordLoc());
4420 NewTL.setQualifierRange(TL.getQualifierRange());
4421 NewTL.setNameLoc(TL.getNameLoc());
4422 NewTL.setLAngleLoc(TL.getLAngleLoc());
4423 NewTL.setRAngleLoc(TL.getRAngleLoc());
4424 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4425 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4426 return Result;
4427 }
4428
4429 QualType Result
4430 = getDerived().RebuildTemplateSpecializationType(Template,
4431 TL.getNameLoc(),
4432 NewTemplateArgs);
4433
4434 if (!Result.isNull()) {
4435 /// FIXME: Wrap this in an elaborated-type-specifier?
4436 TemplateSpecializationTypeLoc NewTL
4437 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4438 NewTL.setTemplateNameLoc(TL.getNameLoc());
4439 NewTL.setLAngleLoc(TL.getLAngleLoc());
4440 NewTL.setRAngleLoc(TL.getRAngleLoc());
4441 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4442 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4443 }
4444
4445 return Result;
4446}
4447
Mike Stump1eb44332009-09-09 15:08:12 +00004448template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004449QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004450TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004451 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004452 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004453
4454 NestedNameSpecifier *NNS = 0;
4455 // NOTE: the qualifier in an ElaboratedType is optional.
4456 if (T->getQualifier() != 0) {
4457 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004458 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004459 if (!NNS)
4460 return QualType();
4461 }
Mike Stump1eb44332009-09-09 15:08:12 +00004462
John McCall43fed0d2010-11-12 08:19:04 +00004463 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4464 if (NamedT.isNull())
4465 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004466
John McCalla2becad2009-10-21 00:40:46 +00004467 QualType Result = TL.getType();
4468 if (getDerived().AlwaysRebuild() ||
4469 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004470 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004471 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4472 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004473 if (Result.isNull())
4474 return QualType();
4475 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004476
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004477 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004478 NewTL.setKeywordLoc(TL.getKeywordLoc());
4479 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004480
4481 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004482}
Mike Stump1eb44332009-09-09 15:08:12 +00004483
4484template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004485QualType TreeTransform<Derived>::TransformAttributedType(
4486 TypeLocBuilder &TLB,
4487 AttributedTypeLoc TL) {
4488 const AttributedType *oldType = TL.getTypePtr();
4489 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4490 if (modifiedType.isNull())
4491 return QualType();
4492
4493 QualType result = TL.getType();
4494
4495 // FIXME: dependent operand expressions?
4496 if (getDerived().AlwaysRebuild() ||
4497 modifiedType != oldType->getModifiedType()) {
4498 // TODO: this is really lame; we should really be rebuilding the
4499 // equivalent type from first principles.
4500 QualType equivalentType
4501 = getDerived().TransformType(oldType->getEquivalentType());
4502 if (equivalentType.isNull())
4503 return QualType();
4504 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4505 modifiedType,
4506 equivalentType);
4507 }
4508
4509 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4510 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4511 if (TL.hasAttrOperand())
4512 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4513 if (TL.hasAttrExprOperand())
4514 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4515 else if (TL.hasAttrEnumOperand())
4516 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4517
4518 return result;
4519}
4520
4521template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004522QualType
4523TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4524 ParenTypeLoc TL) {
4525 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4526 if (Inner.isNull())
4527 return QualType();
4528
4529 QualType Result = TL.getType();
4530 if (getDerived().AlwaysRebuild() ||
4531 Inner != TL.getInnerLoc().getType()) {
4532 Result = getDerived().RebuildParenType(Inner);
4533 if (Result.isNull())
4534 return QualType();
4535 }
4536
4537 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4538 NewTL.setLParenLoc(TL.getLParenLoc());
4539 NewTL.setRParenLoc(TL.getRParenLoc());
4540 return Result;
4541}
4542
4543template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004544QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004545 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004546 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004547
Douglas Gregor577f75a2009-08-04 16:50:30 +00004548 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004549 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004550 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004551 if (!NNS)
4552 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004553
John McCall33500952010-06-11 00:33:02 +00004554 QualType Result
4555 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4556 T->getIdentifier(),
4557 TL.getKeywordLoc(),
4558 TL.getQualifierRange(),
4559 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004560 if (Result.isNull())
4561 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004562
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004563 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4564 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004565 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4566
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004567 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4568 NewTL.setKeywordLoc(TL.getKeywordLoc());
4569 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004570 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004571 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4572 NewTL.setKeywordLoc(TL.getKeywordLoc());
4573 NewTL.setQualifierRange(TL.getQualifierRange());
4574 NewTL.setNameLoc(TL.getNameLoc());
4575 }
John McCalla2becad2009-10-21 00:40:46 +00004576 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004577}
Mike Stump1eb44332009-09-09 15:08:12 +00004578
Douglas Gregor577f75a2009-08-04 16:50:30 +00004579template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004580QualType TreeTransform<Derived>::
4581 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004582 DependentTemplateSpecializationTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004583 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall33500952010-06-11 00:33:02 +00004584
Douglas Gregora88f09f2011-02-28 17:23:35 +00004585 NestedNameSpecifier *NNS = 0;
4586 if (T->getQualifier()) {
4587 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
4588 TL.getQualifierRange());
4589 if (!NNS)
4590 return QualType();
4591 }
4592
John McCall43fed0d2010-11-12 08:19:04 +00004593 return getDerived()
4594 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4595}
4596
4597template<typename Derived>
4598QualType TreeTransform<Derived>::
4599 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4600 DependentTemplateSpecializationTypeLoc TL,
4601 NestedNameSpecifier *NNS) {
John McCallf4c73712011-01-19 06:33:43 +00004602 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall43fed0d2010-11-12 08:19:04 +00004603
John McCall33500952010-06-11 00:33:02 +00004604 TemplateArgumentListInfo NewTemplateArgs;
4605 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4606 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00004607
4608 // FIXME: Nested-name-specifier source location info!
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004609 typedef TemplateArgumentLocContainerIterator<
4610 DependentTemplateSpecializationTypeLoc> ArgIterator;
4611 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4612 ArgIterator(TL, TL.getNumArgs()),
4613 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004614 return QualType();
John McCall33500952010-06-11 00:33:02 +00004615
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004616 QualType Result
4617 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4618 NNS,
4619 TL.getQualifierRange(),
4620 T->getIdentifier(),
4621 TL.getNameLoc(),
4622 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004623 if (Result.isNull())
4624 return QualType();
4625
4626 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4627 QualType NamedT = ElabT->getNamedType();
4628
4629 // Copy information relevant to the template specialization.
4630 TemplateSpecializationTypeLoc NamedTL
4631 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4632 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4633 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4634 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4635 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4636
4637 // Copy information relevant to the elaborated type.
4638 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4639 NewTL.setKeywordLoc(TL.getKeywordLoc());
4640 NewTL.setQualifierRange(TL.getQualifierRange());
4641 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004642 TypeLoc NewTL(Result, TL.getOpaqueData());
4643 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004644 }
4645 return Result;
4646}
4647
4648template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004649QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4650 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004651 QualType Pattern
4652 = getDerived().TransformType(TLB, TL.getPatternLoc());
4653 if (Pattern.isNull())
4654 return QualType();
4655
4656 QualType Result = TL.getType();
4657 if (getDerived().AlwaysRebuild() ||
4658 Pattern != TL.getPatternLoc().getType()) {
4659 Result = getDerived().RebuildPackExpansionType(Pattern,
4660 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004661 TL.getEllipsisLoc(),
4662 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004663 if (Result.isNull())
4664 return QualType();
4665 }
4666
4667 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4668 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4669 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004670}
4671
4672template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004673QualType
4674TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004675 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004676 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004677 TLB.pushFullCopy(TL);
4678 return TL.getType();
4679}
4680
4681template<typename Derived>
4682QualType
4683TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004684 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004685 // ObjCObjectType is never dependent.
4686 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004687 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004688}
Mike Stump1eb44332009-09-09 15:08:12 +00004689
4690template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004691QualType
4692TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004693 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004694 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004695 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004696 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004697}
4698
Douglas Gregor577f75a2009-08-04 16:50:30 +00004699//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004700// Statement transformation
4701//===----------------------------------------------------------------------===//
4702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004703StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004704TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004705 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004706}
4707
4708template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004709StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004710TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4711 return getDerived().TransformCompoundStmt(S, false);
4712}
4713
4714template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004715StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004716TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004717 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004718 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004719 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004720 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004721 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4722 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004723 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004724 if (Result.isInvalid()) {
4725 // Immediately fail if this was a DeclStmt, since it's very
4726 // likely that this will cause problems for future statements.
4727 if (isa<DeclStmt>(*B))
4728 return StmtError();
4729
4730 // Otherwise, just keep processing substatements and fail later.
4731 SubStmtInvalid = true;
4732 continue;
4733 }
Mike Stump1eb44332009-09-09 15:08:12 +00004734
Douglas Gregor43959a92009-08-20 07:17:43 +00004735 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4736 Statements.push_back(Result.takeAs<Stmt>());
4737 }
Mike Stump1eb44332009-09-09 15:08:12 +00004738
John McCall7114cba2010-08-27 19:56:05 +00004739 if (SubStmtInvalid)
4740 return StmtError();
4741
Douglas Gregor43959a92009-08-20 07:17:43 +00004742 if (!getDerived().AlwaysRebuild() &&
4743 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004744 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004745
4746 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4747 move_arg(Statements),
4748 S->getRBracLoc(),
4749 IsStmtExpr);
4750}
Mike Stump1eb44332009-09-09 15:08:12 +00004751
Douglas Gregor43959a92009-08-20 07:17:43 +00004752template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004753StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004754TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004755 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004756 {
4757 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004758 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004759
Eli Friedman264c1f82009-11-19 03:14:00 +00004760 // Transform the left-hand case value.
4761 LHS = getDerived().TransformExpr(S->getLHS());
4762 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004763 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004764
Eli Friedman264c1f82009-11-19 03:14:00 +00004765 // Transform the right-hand case value (for the GNU case-range extension).
4766 RHS = getDerived().TransformExpr(S->getRHS());
4767 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004768 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004769 }
Mike Stump1eb44332009-09-09 15:08:12 +00004770
Douglas Gregor43959a92009-08-20 07:17:43 +00004771 // Build the case statement.
4772 // Case statements are always rebuilt so that they will attached to their
4773 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004774 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004775 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004776 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004777 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004778 S->getColonLoc());
4779 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004780 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004781
Douglas Gregor43959a92009-08-20 07:17:43 +00004782 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004783 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004784 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004785 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004786
Douglas Gregor43959a92009-08-20 07:17:43 +00004787 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004788 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004789}
4790
4791template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004792StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004793TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004794 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004795 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004796 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004797 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregor43959a92009-08-20 07:17:43 +00004799 // Default statements are always rebuilt
4800 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004801 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004802}
Mike Stump1eb44332009-09-09 15:08:12 +00004803
Douglas Gregor43959a92009-08-20 07:17:43 +00004804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004805StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004806TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004807 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004808 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004809 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004810
Chris Lattner57ad3782011-02-17 20:34:02 +00004811 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4812 S->getDecl());
4813 if (!LD)
4814 return StmtError();
4815
4816
Douglas Gregor43959a92009-08-20 07:17:43 +00004817 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004818 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004819 cast<LabelDecl>(LD), SourceLocation(),
4820 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004821}
Mike Stump1eb44332009-09-09 15:08:12 +00004822
Douglas Gregor43959a92009-08-20 07:17:43 +00004823template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004824StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004825TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004826 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004827 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004828 VarDecl *ConditionVar = 0;
4829 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004830 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004831 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004832 getDerived().TransformDefinition(
4833 S->getConditionVariable()->getLocation(),
4834 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004835 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004836 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004837 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004838 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004839
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004840 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004841 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004842
4843 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004844 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004845 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4846 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004847 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004848 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004849
John McCall9ae2f072010-08-23 23:25:46 +00004850 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004851 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004852 }
Sean Huntc3021132010-05-05 15:23:54 +00004853
John McCall9ae2f072010-08-23 23:25:46 +00004854 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4855 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004856 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004857
Douglas Gregor43959a92009-08-20 07:17:43 +00004858 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004859 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004860 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004861 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004862
Douglas Gregor43959a92009-08-20 07:17:43 +00004863 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004864 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004865 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004866 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004867
Douglas Gregor43959a92009-08-20 07:17:43 +00004868 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004869 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004870 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004871 Then.get() == S->getThen() &&
4872 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004873 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004874
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004875 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004876 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004877 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004878}
4879
4880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004881StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004882TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004883 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004884 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004885 VarDecl *ConditionVar = 0;
4886 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004887 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004888 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004889 getDerived().TransformDefinition(
4890 S->getConditionVariable()->getLocation(),
4891 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004892 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004893 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004894 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004895 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004896
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004897 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004898 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004899 }
Mike Stump1eb44332009-09-09 15:08:12 +00004900
Douglas Gregor43959a92009-08-20 07:17:43 +00004901 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004902 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004903 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004904 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004905 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004906 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004907
Douglas Gregor43959a92009-08-20 07:17:43 +00004908 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004909 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004910 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004911 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004912
Douglas Gregor43959a92009-08-20 07:17:43 +00004913 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004914 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4915 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004916}
Mike Stump1eb44332009-09-09 15:08:12 +00004917
Douglas Gregor43959a92009-08-20 07:17:43 +00004918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004919StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004920TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004921 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004922 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004923 VarDecl *ConditionVar = 0;
4924 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004925 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004926 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004927 getDerived().TransformDefinition(
4928 S->getConditionVariable()->getLocation(),
4929 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004930 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004931 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004932 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004933 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004934
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004935 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004936 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004937
4938 if (S->getCond()) {
4939 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004940 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4941 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004942 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004943 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004944 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004945 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004946 }
Mike Stump1eb44332009-09-09 15:08:12 +00004947
John McCall9ae2f072010-08-23 23:25:46 +00004948 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4949 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004950 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004951
Douglas Gregor43959a92009-08-20 07:17:43 +00004952 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004953 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004954 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004955 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004956
Douglas Gregor43959a92009-08-20 07:17:43 +00004957 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004958 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004959 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004960 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004961 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004962
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004963 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004964 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004965}
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregor43959a92009-08-20 07:17:43 +00004967template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004968StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004969TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004970 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004971 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004972 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004973 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004974
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004975 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004976 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004977 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004978 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004979
Douglas Gregor43959a92009-08-20 07:17:43 +00004980 if (!getDerived().AlwaysRebuild() &&
4981 Cond.get() == S->getCond() &&
4982 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004983 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004984
John McCall9ae2f072010-08-23 23:25:46 +00004985 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4986 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004987 S->getRParenLoc());
4988}
Mike Stump1eb44332009-09-09 15:08:12 +00004989
Douglas Gregor43959a92009-08-20 07:17:43 +00004990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004991StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004992TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004993 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004994 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004995 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004996 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004997
Douglas Gregor43959a92009-08-20 07:17:43 +00004998 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004999 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005000 VarDecl *ConditionVar = 0;
5001 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005002 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005003 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005004 getDerived().TransformDefinition(
5005 S->getConditionVariable()->getLocation(),
5006 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005007 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005008 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005009 } else {
5010 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005011
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005012 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005013 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005014
5015 if (S->getCond()) {
5016 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005017 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5018 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005019 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005020 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005021
John McCall9ae2f072010-08-23 23:25:46 +00005022 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005023 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005024 }
Mike Stump1eb44332009-09-09 15:08:12 +00005025
John McCall9ae2f072010-08-23 23:25:46 +00005026 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5027 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005028 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005029
Douglas Gregor43959a92009-08-20 07:17:43 +00005030 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005031 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005032 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005033 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005034
John McCall9ae2f072010-08-23 23:25:46 +00005035 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5036 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005037 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005038
Douglas Gregor43959a92009-08-20 07:17:43 +00005039 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005040 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005041 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005042 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005043
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 if (!getDerived().AlwaysRebuild() &&
5045 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005046 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005047 Inc.get() == S->getInc() &&
5048 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005049 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005050
Douglas Gregor43959a92009-08-20 07:17:43 +00005051 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005052 Init.get(), FullCond, ConditionVar,
5053 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005054}
5055
5056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005057StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005058TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005059 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5060 S->getLabel());
5061 if (!LD)
5062 return StmtError();
5063
Douglas Gregor43959a92009-08-20 07:17:43 +00005064 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005065 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005066 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005067}
5068
5069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005070StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005071TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005072 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005073 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005074 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregor43959a92009-08-20 07:17:43 +00005076 if (!getDerived().AlwaysRebuild() &&
5077 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005078 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005079
5080 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005081 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005082}
5083
5084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005085StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005086TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005087 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005088}
Mike Stump1eb44332009-09-09 15:08:12 +00005089
Douglas Gregor43959a92009-08-20 07:17:43 +00005090template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005091StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005092TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005093 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005094}
Mike Stump1eb44332009-09-09 15:08:12 +00005095
Douglas Gregor43959a92009-08-20 07:17:43 +00005096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005097StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005098TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005099 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005101 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005102
Mike Stump1eb44332009-09-09 15:08:12 +00005103 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005105 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005106}
Mike Stump1eb44332009-09-09 15:08:12 +00005107
Douglas Gregor43959a92009-08-20 07:17:43 +00005108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005109StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005110TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005111 bool DeclChanged = false;
5112 llvm::SmallVector<Decl *, 4> Decls;
5113 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5114 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005115 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5116 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005118 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 if (Transformed != *D)
5121 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 Decls.push_back(Transformed);
5124 }
Mike Stump1eb44332009-09-09 15:08:12 +00005125
Douglas Gregor43959a92009-08-20 07:17:43 +00005126 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005127 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005128
5129 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 S->getStartLoc(), S->getEndLoc());
5131}
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005134StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005135TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005136
John McCallca0408f2010-08-23 06:44:23 +00005137 ASTOwningVector<Expr*> Constraints(getSema());
5138 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005139 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005140
John McCall60d7b3a2010-08-24 06:29:42 +00005141 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005142 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005143
5144 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005145
Anders Carlsson703e3942010-01-24 05:50:09 +00005146 // Go through the outputs.
5147 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005148 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005149
Anders Carlsson703e3942010-01-24 05:50:09 +00005150 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005151 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005152
Anders Carlsson703e3942010-01-24 05:50:09 +00005153 // Transform the output expr.
5154 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005155 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005156 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005157 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005158
Anders Carlsson703e3942010-01-24 05:50:09 +00005159 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005160
John McCall9ae2f072010-08-23 23:25:46 +00005161 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005162 }
Sean Huntc3021132010-05-05 15:23:54 +00005163
Anders Carlsson703e3942010-01-24 05:50:09 +00005164 // Go through the inputs.
5165 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005166 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005167
Anders Carlsson703e3942010-01-24 05:50:09 +00005168 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005169 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005170
Anders Carlsson703e3942010-01-24 05:50:09 +00005171 // Transform the input expr.
5172 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005173 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005174 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005175 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005176
Anders Carlsson703e3942010-01-24 05:50:09 +00005177 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005178
John McCall9ae2f072010-08-23 23:25:46 +00005179 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005180 }
Sean Huntc3021132010-05-05 15:23:54 +00005181
Anders Carlsson703e3942010-01-24 05:50:09 +00005182 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005183 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005184
5185 // Go through the clobbers.
5186 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005187 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005188
5189 // No need to transform the asm string literal.
5190 AsmString = SemaRef.Owned(S->getAsmString());
5191
5192 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5193 S->isSimple(),
5194 S->isVolatile(),
5195 S->getNumOutputs(),
5196 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005197 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005198 move_arg(Constraints),
5199 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005200 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005201 move_arg(Clobbers),
5202 S->getRParenLoc(),
5203 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005204}
5205
5206
5207template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005208StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005209TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005210 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005211 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005212 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005213 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005214
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005215 // Transform the @catch statements (if present).
5216 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005217 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005218 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005219 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005220 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005221 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005222 if (Catch.get() != S->getCatchStmt(I))
5223 AnyCatchChanged = true;
5224 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005225 }
Sean Huntc3021132010-05-05 15:23:54 +00005226
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005227 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005228 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005229 if (S->getFinallyStmt()) {
5230 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5231 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005232 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005233 }
5234
5235 // If nothing changed, just retain this statement.
5236 if (!getDerived().AlwaysRebuild() &&
5237 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005238 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005239 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005240 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005241
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005242 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005243 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5244 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005245}
Mike Stump1eb44332009-09-09 15:08:12 +00005246
Douglas Gregor43959a92009-08-20 07:17:43 +00005247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005248StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005249TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005250 // Transform the @catch parameter, if there is one.
5251 VarDecl *Var = 0;
5252 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5253 TypeSourceInfo *TSInfo = 0;
5254 if (FromVar->getTypeSourceInfo()) {
5255 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5256 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005258 }
Sean Huntc3021132010-05-05 15:23:54 +00005259
Douglas Gregorbe270a02010-04-26 17:57:08 +00005260 QualType T;
5261 if (TSInfo)
5262 T = TSInfo->getType();
5263 else {
5264 T = getDerived().TransformType(FromVar->getType());
5265 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005266 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005267 }
Sean Huntc3021132010-05-05 15:23:54 +00005268
Douglas Gregorbe270a02010-04-26 17:57:08 +00005269 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5270 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005271 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005272 }
Sean Huntc3021132010-05-05 15:23:54 +00005273
John McCall60d7b3a2010-08-24 06:29:42 +00005274 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005275 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005276 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005277
5278 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005279 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005280 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005281}
Mike Stump1eb44332009-09-09 15:08:12 +00005282
Douglas Gregor43959a92009-08-20 07:17:43 +00005283template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005284StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005285TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005286 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005287 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005288 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005290
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005291 // If nothing changed, just retain this statement.
5292 if (!getDerived().AlwaysRebuild() &&
5293 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005294 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005295
5296 // Build a new statement.
5297 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005298 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005299}
Mike Stump1eb44332009-09-09 15:08:12 +00005300
Douglas Gregor43959a92009-08-20 07:17:43 +00005301template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005302StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005303TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005304 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005305 if (S->getThrowExpr()) {
5306 Operand = getDerived().TransformExpr(S->getThrowExpr());
5307 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005308 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005309 }
Sean Huntc3021132010-05-05 15:23:54 +00005310
Douglas Gregord1377b22010-04-22 21:44:01 +00005311 if (!getDerived().AlwaysRebuild() &&
5312 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005313 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005314
John McCall9ae2f072010-08-23 23:25:46 +00005315 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005316}
Mike Stump1eb44332009-09-09 15:08:12 +00005317
Douglas Gregor43959a92009-08-20 07:17:43 +00005318template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005319StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005320TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005321 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005322 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005323 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005324 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005325 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005326
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005327 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005328 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005329 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005331
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005332 // If nothing change, just retain the current statement.
5333 if (!getDerived().AlwaysRebuild() &&
5334 Object.get() == S->getSynchExpr() &&
5335 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005336 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005337
5338 // Build a new statement.
5339 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005340 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005341}
5342
5343template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005344StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005345TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005346 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005347 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005348 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005349 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005350 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005351
Douglas Gregorc3203e72010-04-22 23:10:45 +00005352 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005353 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005354 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005355 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005356
Douglas Gregorc3203e72010-04-22 23:10:45 +00005357 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005358 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005359 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005361
Douglas Gregorc3203e72010-04-22 23:10:45 +00005362 // If nothing changed, just retain this statement.
5363 if (!getDerived().AlwaysRebuild() &&
5364 Element.get() == S->getElement() &&
5365 Collection.get() == S->getCollection() &&
5366 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005367 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005368
Douglas Gregorc3203e72010-04-22 23:10:45 +00005369 // Build a new statement.
5370 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5371 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005372 Element.get(),
5373 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005374 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005375 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005376}
5377
5378
5379template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005380StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005381TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5382 // Transform the exception declaration, if any.
5383 VarDecl *Var = 0;
5384 if (S->getExceptionDecl()) {
5385 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005386 TypeSourceInfo *T = getDerived().TransformType(
5387 ExceptionDecl->getTypeSourceInfo());
5388 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005389 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Douglas Gregor83cb9422010-09-09 17:09:21 +00005391 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00005393 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00005394 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005396 }
Mike Stump1eb44332009-09-09 15:08:12 +00005397
Douglas Gregor43959a92009-08-20 07:17:43 +00005398 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005399 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005400 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005401 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005402
Douglas Gregor43959a92009-08-20 07:17:43 +00005403 if (!getDerived().AlwaysRebuild() &&
5404 !Var &&
5405 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005406 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005407
5408 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5409 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005410 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005411}
Mike Stump1eb44332009-09-09 15:08:12 +00005412
Douglas Gregor43959a92009-08-20 07:17:43 +00005413template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005414StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005415TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5416 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005417 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 = getDerived().TransformCompoundStmt(S->getTryBlock());
5419 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregor43959a92009-08-20 07:17:43 +00005422 // Transform the handlers.
5423 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005424 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005425 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005426 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5428 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005429 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005430
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5432 Handlers.push_back(Handler.takeAs<Stmt>());
5433 }
Mike Stump1eb44332009-09-09 15:08:12 +00005434
Douglas Gregor43959a92009-08-20 07:17:43 +00005435 if (!getDerived().AlwaysRebuild() &&
5436 TryBlock.get() == S->getTryBlock() &&
5437 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005438 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005439
John McCall9ae2f072010-08-23 23:25:46 +00005440 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005441 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005442}
Mike Stump1eb44332009-09-09 15:08:12 +00005443
Douglas Gregor43959a92009-08-20 07:17:43 +00005444//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005445// Expression transformation
5446//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005447template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005448ExprResult
John McCall454feb92009-12-08 09:21:05 +00005449TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005450 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451}
Mike Stump1eb44332009-09-09 15:08:12 +00005452
5453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005454ExprResult
John McCall454feb92009-12-08 09:21:05 +00005455TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005456 NestedNameSpecifier *Qualifier = 0;
5457 if (E->getQualifier()) {
5458 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005459 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005460 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005461 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005462 }
John McCalldbd872f2009-12-08 09:08:17 +00005463
5464 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005465 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5466 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005467 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005468 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005469
John McCallec8045d2010-08-17 21:27:17 +00005470 DeclarationNameInfo NameInfo = E->getNameInfo();
5471 if (NameInfo.getName()) {
5472 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5473 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005474 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005475 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005476
5477 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005478 Qualifier == E->getQualifier() &&
5479 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005480 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005481 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005482
5483 // Mark it referenced in the new context regardless.
5484 // FIXME: this is a bit instantiation-specific.
5485 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5486
John McCall3fa5cae2010-10-26 07:05:15 +00005487 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005488 }
John McCalldbd872f2009-12-08 09:08:17 +00005489
5490 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005491 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005492 TemplateArgs = &TransArgs;
5493 TransArgs.setLAngleLoc(E->getLAngleLoc());
5494 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005495 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5496 E->getNumTemplateArgs(),
5497 TransArgs))
5498 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005499 }
5500
Douglas Gregora2813ce2009-10-23 18:54:35 +00005501 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005502 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005503}
Mike Stump1eb44332009-09-09 15:08:12 +00005504
Douglas Gregorb98b1992009-08-11 05:31:07 +00005505template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005506ExprResult
John McCall454feb92009-12-08 09:21:05 +00005507TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005508 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005509}
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregorb98b1992009-08-11 05:31:07 +00005511template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005512ExprResult
John McCall454feb92009-12-08 09:21:05 +00005513TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005514 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515}
Mike Stump1eb44332009-09-09 15:08:12 +00005516
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005518ExprResult
John McCall454feb92009-12-08 09:21:05 +00005519TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005520 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005521}
Mike Stump1eb44332009-09-09 15:08:12 +00005522
Douglas Gregorb98b1992009-08-11 05:31:07 +00005523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005524ExprResult
John McCall454feb92009-12-08 09:21:05 +00005525TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005526 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005527}
Mike Stump1eb44332009-09-09 15:08:12 +00005528
Douglas Gregorb98b1992009-08-11 05:31:07 +00005529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005530ExprResult
John McCall454feb92009-12-08 09:21:05 +00005531TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005532 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005533}
5534
5535template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005536ExprResult
John McCall454feb92009-12-08 09:21:05 +00005537TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005538 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005539 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005540 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005541
Douglas Gregorb98b1992009-08-11 05:31:07 +00005542 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005543 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005544
John McCall9ae2f072010-08-23 23:25:46 +00005545 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005546 E->getRParen());
5547}
5548
Mike Stump1eb44332009-09-09 15:08:12 +00005549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005550ExprResult
John McCall454feb92009-12-08 09:21:05 +00005551TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005552 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005555
Douglas Gregorb98b1992009-08-11 05:31:07 +00005556 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005557 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005558
Douglas Gregorb98b1992009-08-11 05:31:07 +00005559 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5560 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005561 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562}
Mike Stump1eb44332009-09-09 15:08:12 +00005563
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005565ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005566TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5567 // Transform the type.
5568 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5569 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005570 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005571
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005572 // Transform all of the components into components similar to what the
5573 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005574 // FIXME: It would be slightly more efficient in the non-dependent case to
5575 // just map FieldDecls, rather than requiring the rebuilder to look for
5576 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005577 // template code that we don't care.
5578 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005579 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005580 typedef OffsetOfExpr::OffsetOfNode Node;
5581 llvm::SmallVector<Component, 4> Components;
5582 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5583 const Node &ON = E->getComponent(I);
5584 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005585 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005586 Comp.LocStart = ON.getRange().getBegin();
5587 Comp.LocEnd = ON.getRange().getEnd();
5588 switch (ON.getKind()) {
5589 case Node::Array: {
5590 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005591 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005592 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005594
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005595 ExprChanged = ExprChanged || Index.get() != FromIndex;
5596 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005597 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005598 break;
5599 }
Sean Huntc3021132010-05-05 15:23:54 +00005600
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005601 case Node::Field:
5602 case Node::Identifier:
5603 Comp.isBrackets = false;
5604 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005605 if (!Comp.U.IdentInfo)
5606 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005607
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005608 break;
Sean Huntc3021132010-05-05 15:23:54 +00005609
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005610 case Node::Base:
5611 // Will be recomputed during the rebuild.
5612 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005613 }
Sean Huntc3021132010-05-05 15:23:54 +00005614
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005615 Components.push_back(Comp);
5616 }
Sean Huntc3021132010-05-05 15:23:54 +00005617
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005618 // If nothing changed, retain the existing expression.
5619 if (!getDerived().AlwaysRebuild() &&
5620 Type == E->getTypeSourceInfo() &&
5621 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005622 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005623
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005624 // Build a new offsetof expression.
5625 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5626 Components.data(), Components.size(),
5627 E->getRParenLoc());
5628}
5629
5630template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005631ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005632TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5633 assert(getDerived().AlreadyTransformed(E->getType()) &&
5634 "opaque value expression requires transformation");
5635 return SemaRef.Owned(E);
5636}
5637
5638template<typename Derived>
5639ExprResult
John McCall454feb92009-12-08 09:21:05 +00005640TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005641 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005642 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005643
John McCalla93c9342009-12-07 02:54:59 +00005644 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005645 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005646 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005647
John McCall5ab75172009-11-04 07:28:41 +00005648 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005649 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005650
John McCall5ab75172009-11-04 07:28:41 +00005651 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005652 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653 E->getSourceRange());
5654 }
Mike Stump1eb44332009-09-09 15:08:12 +00005655
John McCall60d7b3a2010-08-24 06:29:42 +00005656 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005657 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005658 // C++0x [expr.sizeof]p1:
5659 // The operand is either an expression, which is an unevaluated operand
5660 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005661 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005662
Douglas Gregorb98b1992009-08-11 05:31:07 +00005663 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5664 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005666
Douglas Gregorb98b1992009-08-11 05:31:07 +00005667 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005668 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 }
Mike Stump1eb44332009-09-09 15:08:12 +00005670
John McCall9ae2f072010-08-23 23:25:46 +00005671 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005672 E->isSizeOf(),
5673 E->getSourceRange());
5674}
Mike Stump1eb44332009-09-09 15:08:12 +00005675
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005677ExprResult
John McCall454feb92009-12-08 09:21:05 +00005678TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005679 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005681 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005682
John McCall60d7b3a2010-08-24 06:29:42 +00005683 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005686
5687
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 if (!getDerived().AlwaysRebuild() &&
5689 LHS.get() == E->getLHS() &&
5690 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005691 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005692
John McCall9ae2f072010-08-23 23:25:46 +00005693 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005695 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005696 E->getRBracketLoc());
5697}
Mike Stump1eb44332009-09-09 15:08:12 +00005698
5699template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005700ExprResult
John McCall454feb92009-12-08 09:21:05 +00005701TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005703 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005704 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005705 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005706
5707 // Transform arguments.
5708 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005709 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005710 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5711 &ArgChanged))
5712 return ExprError();
5713
Douglas Gregorb98b1992009-08-11 05:31:07 +00005714 if (!getDerived().AlwaysRebuild() &&
5715 Callee.get() == E->getCallee() &&
5716 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005717 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005718
Douglas Gregorb98b1992009-08-11 05:31:07 +00005719 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005720 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005722 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005723 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005724 E->getRParenLoc());
5725}
Mike Stump1eb44332009-09-09 15:08:12 +00005726
5727template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005728ExprResult
John McCall454feb92009-12-08 09:21:05 +00005729TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005730 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005731 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005732 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005734 NestedNameSpecifier *Qualifier = 0;
5735 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005736 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005737 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005738 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005739 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005740 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005741 }
Mike Stump1eb44332009-09-09 15:08:12 +00005742
Eli Friedmanf595cc42009-12-04 06:40:45 +00005743 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005744 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5745 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005747 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005748
John McCall6bb80172010-03-30 21:47:33 +00005749 NamedDecl *FoundDecl = E->getFoundDecl();
5750 if (FoundDecl == E->getMemberDecl()) {
5751 FoundDecl = Member;
5752 } else {
5753 FoundDecl = cast_or_null<NamedDecl>(
5754 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5755 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005756 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005757 }
5758
Douglas Gregorb98b1992009-08-11 05:31:07 +00005759 if (!getDerived().AlwaysRebuild() &&
5760 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005761 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005762 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005763 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005764 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005765
Anders Carlsson1f240322009-12-22 05:24:09 +00005766 // Mark it referenced in the new context regardless.
5767 // FIXME: this is a bit instantiation-specific.
5768 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005769 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005770 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005771
John McCalld5532b62009-11-23 01:53:49 +00005772 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005773 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005774 TransArgs.setLAngleLoc(E->getLAngleLoc());
5775 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005776 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5777 E->getNumTemplateArgs(),
5778 TransArgs))
5779 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005780 }
Sean Huntc3021132010-05-05 15:23:54 +00005781
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782 // FIXME: Bogus source location for the operator
5783 SourceLocation FakeOperatorLoc
5784 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5785
John McCallc2233c52010-01-15 08:34:02 +00005786 // FIXME: to do this check properly, we will need to preserve the
5787 // first-qualifier-in-scope here, just in case we had a dependent
5788 // base (and therefore couldn't do the check) and a
5789 // nested-name-qualifier (and therefore could do the lookup).
5790 NamedDecl *FirstQualifierInScope = 0;
5791
John McCall9ae2f072010-08-23 23:25:46 +00005792 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005794 Qualifier,
5795 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005796 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005797 Member,
John McCall6bb80172010-03-30 21:47:33 +00005798 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005799 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005800 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005801 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802}
Mike Stump1eb44332009-09-09 15:08:12 +00005803
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005805ExprResult
John McCall454feb92009-12-08 09:21:05 +00005806TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005807 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005808 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005809 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005810
John McCall60d7b3a2010-08-24 06:29:42 +00005811 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005812 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005813 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005814
Douglas Gregorb98b1992009-08-11 05:31:07 +00005815 if (!getDerived().AlwaysRebuild() &&
5816 LHS.get() == E->getLHS() &&
5817 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005819
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005821 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822}
5823
Mike Stump1eb44332009-09-09 15:08:12 +00005824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005825ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005826TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005827 CompoundAssignOperator *E) {
5828 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005829}
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00005832ExprResult TreeTransform<Derived>::
5833TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5834 // Just rebuild the common and RHS expressions and see whether we
5835 // get any changes.
5836
5837 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5838 if (commonExpr.isInvalid())
5839 return ExprError();
5840
5841 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5842 if (rhs.isInvalid())
5843 return ExprError();
5844
5845 if (!getDerived().AlwaysRebuild() &&
5846 commonExpr.get() == e->getCommon() &&
5847 rhs.get() == e->getFalseExpr())
5848 return SemaRef.Owned(e);
5849
5850 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5851 e->getQuestionLoc(),
5852 0,
5853 e->getColonLoc(),
5854 rhs.get());
5855}
5856
5857template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005858ExprResult
John McCall454feb92009-12-08 09:21:05 +00005859TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005860 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005862 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005863
John McCall60d7b3a2010-08-24 06:29:42 +00005864 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005866 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005867
John McCall60d7b3a2010-08-24 06:29:42 +00005868 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005869 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005870 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregorb98b1992009-08-11 05:31:07 +00005872 if (!getDerived().AlwaysRebuild() &&
5873 Cond.get() == E->getCond() &&
5874 LHS.get() == E->getLHS() &&
5875 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005876 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005877
John McCall9ae2f072010-08-23 23:25:46 +00005878 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005879 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005880 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005881 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005882 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005883}
Mike Stump1eb44332009-09-09 15:08:12 +00005884
5885template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005886ExprResult
John McCall454feb92009-12-08 09:21:05 +00005887TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005888 // Implicit casts are eliminated during transformation, since they
5889 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005890 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005891}
Mike Stump1eb44332009-09-09 15:08:12 +00005892
Douglas Gregorb98b1992009-08-11 05:31:07 +00005893template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005894ExprResult
John McCall454feb92009-12-08 09:21:05 +00005895TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005896 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5897 if (!Type)
5898 return ExprError();
5899
John McCall60d7b3a2010-08-24 06:29:42 +00005900 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005901 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005902 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005903 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005904
Douglas Gregorb98b1992009-08-11 05:31:07 +00005905 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005906 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005907 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005908 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005909
John McCall9d125032010-01-15 18:39:57 +00005910 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005911 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005912 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005913 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005914}
Mike Stump1eb44332009-09-09 15:08:12 +00005915
Douglas Gregorb98b1992009-08-11 05:31:07 +00005916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005917ExprResult
John McCall454feb92009-12-08 09:21:05 +00005918TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005919 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5920 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5921 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005922 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005923
John McCall60d7b3a2010-08-24 06:29:42 +00005924 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005925 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005926 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005927
Douglas Gregorb98b1992009-08-11 05:31:07 +00005928 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005929 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005930 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005931 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005932
John McCall1d7d8d62010-01-19 22:33:45 +00005933 // Note: the expression type doesn't necessarily match the
5934 // type-as-written, but that's okay, because it should always be
5935 // derivable from the initializer.
5936
John McCall42f56b52010-01-18 19:35:47 +00005937 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005938 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005939 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005940}
Mike Stump1eb44332009-09-09 15:08:12 +00005941
Douglas Gregorb98b1992009-08-11 05:31:07 +00005942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005943ExprResult
John McCall454feb92009-12-08 09:21:05 +00005944TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005945 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005946 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005947 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005948
Douglas Gregorb98b1992009-08-11 05:31:07 +00005949 if (!getDerived().AlwaysRebuild() &&
5950 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005951 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005952
Douglas Gregorb98b1992009-08-11 05:31:07 +00005953 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005954 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005955 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005956 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957 E->getAccessorLoc(),
5958 E->getAccessor());
5959}
Mike Stump1eb44332009-09-09 15:08:12 +00005960
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005962ExprResult
John McCall454feb92009-12-08 09:21:05 +00005963TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005964 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005965
John McCallca0408f2010-08-23 06:44:23 +00005966 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005967 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5968 Inits, &InitChanged))
5969 return ExprError();
5970
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005972 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005973
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005975 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976}
Mike Stump1eb44332009-09-09 15:08:12 +00005977
Douglas Gregorb98b1992009-08-11 05:31:07 +00005978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005979ExprResult
John McCall454feb92009-12-08 09:21:05 +00005980TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005981 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005982
Douglas Gregor43959a92009-08-20 07:17:43 +00005983 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005984 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005985 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005986 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005987
Douglas Gregor43959a92009-08-20 07:17:43 +00005988 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005989 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005990 bool ExprChanged = false;
5991 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5992 DEnd = E->designators_end();
5993 D != DEnd; ++D) {
5994 if (D->isFieldDesignator()) {
5995 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5996 D->getDotLoc(),
5997 D->getFieldLoc()));
5998 continue;
5999 }
Mike Stump1eb44332009-09-09 15:08:12 +00006000
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006002 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006003 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006004 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006005
6006 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006007 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006008
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6010 ArrayExprs.push_back(Index.release());
6011 continue;
6012 }
Mike Stump1eb44332009-09-09 15:08:12 +00006013
Douglas Gregorb98b1992009-08-11 05:31:07 +00006014 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006015 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6017 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006019
John McCall60d7b3a2010-08-24 06:29:42 +00006020 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006021 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006022 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006023
6024 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025 End.get(),
6026 D->getLBracketLoc(),
6027 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006028
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6030 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006031
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032 ArrayExprs.push_back(Start.release());
6033 ArrayExprs.push_back(End.release());
6034 }
Mike Stump1eb44332009-09-09 15:08:12 +00006035
Douglas Gregorb98b1992009-08-11 05:31:07 +00006036 if (!getDerived().AlwaysRebuild() &&
6037 Init.get() == E->getInit() &&
6038 !ExprChanged)
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().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6042 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006043 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006044}
Mike Stump1eb44332009-09-09 15:08:12 +00006045
Douglas Gregorb98b1992009-08-11 05:31:07 +00006046template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006047ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006048TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006049 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006050 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006051
Douglas Gregor5557b252009-10-28 00:29:27 +00006052 // FIXME: Will we ever have proper type location here? Will we actually
6053 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006054 QualType T = getDerived().TransformType(E->getType());
6055 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006056 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006057
Douglas Gregorb98b1992009-08-11 05:31:07 +00006058 if (!getDerived().AlwaysRebuild() &&
6059 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006060 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006061
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062 return getDerived().RebuildImplicitValueInitExpr(T);
6063}
Mike Stump1eb44332009-09-09 15:08:12 +00006064
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006066ExprResult
John McCall454feb92009-12-08 09:21:05 +00006067TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006068 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6069 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006070 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006071
John McCall60d7b3a2010-08-24 06:29:42 +00006072 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006074 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006075
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006077 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006078 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006079 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006080
John McCall9ae2f072010-08-23 23:25:46 +00006081 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006082 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006083}
6084
6085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006086ExprResult
John McCall454feb92009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006088 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006089 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006090 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6091 &ArgumentChanged))
6092 return ExprError();
6093
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6095 move_arg(Inits),
6096 E->getRParenLoc());
6097}
Mike Stump1eb44332009-09-09 15:08:12 +00006098
Douglas Gregorb98b1992009-08-11 05:31:07 +00006099/// \brief Transform an address-of-label expression.
6100///
6101/// By default, the transformation of an address-of-label expression always
6102/// rebuilds the expression, so that the label identifier can be resolved to
6103/// the corresponding label statement by semantic analysis.
6104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006105ExprResult
John McCall454feb92009-12-08 09:21:05 +00006106TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006107 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6108 E->getLabel());
6109 if (!LD)
6110 return ExprError();
6111
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006113 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114}
Mike Stump1eb44332009-09-09 15:08:12 +00006115
6116template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006117ExprResult
John McCall454feb92009-12-08 09:21:05 +00006118TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006119 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6121 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006122 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006123
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124 if (!getDerived().AlwaysRebuild() &&
6125 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006126 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006127
6128 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006129 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006130 E->getRParenLoc());
6131}
Mike Stump1eb44332009-09-09 15:08:12 +00006132
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006136 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006138 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006139
John McCall60d7b3a2010-08-24 06:29:42 +00006140 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006142 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006143
John McCall60d7b3a2010-08-24 06:29:42 +00006144 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006145 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006147
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148 if (!getDerived().AlwaysRebuild() &&
6149 Cond.get() == E->getCond() &&
6150 LHS.get() == E->getLHS() &&
6151 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006152 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006153
Douglas Gregorb98b1992009-08-11 05:31:07 +00006154 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006155 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156 E->getRParenLoc());
6157}
Mike Stump1eb44332009-09-09 15:08:12 +00006158
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006160ExprResult
John McCall454feb92009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006162 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163}
6164
6165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006166ExprResult
John McCall454feb92009-12-08 09:21:05 +00006167TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006168 switch (E->getOperator()) {
6169 case OO_New:
6170 case OO_Delete:
6171 case OO_Array_New:
6172 case OO_Array_Delete:
6173 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006174 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006175
Douglas Gregor668d6d92009-12-13 20:44:55 +00006176 case OO_Call: {
6177 // This is a call to an object's operator().
6178 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6179
6180 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006181 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006182 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006183 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006184
6185 // FIXME: Poor location information
6186 SourceLocation FakeLParenLoc
6187 = SemaRef.PP.getLocForEndOfToken(
6188 static_cast<Expr *>(Object.get())->getLocEnd());
6189
6190 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006191 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006192 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6193 Args))
6194 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006195
John McCall9ae2f072010-08-23 23:25:46 +00006196 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006197 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006198 E->getLocEnd());
6199 }
6200
6201#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6202 case OO_##Name:
6203#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6204#include "clang/Basic/OperatorKinds.def"
6205 case OO_Subscript:
6206 // Handled below.
6207 break;
6208
6209 case OO_Conditional:
6210 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006211 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006212
6213 case OO_None:
6214 case NUM_OVERLOADED_OPERATORS:
6215 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006216 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006217 }
6218
John McCall60d7b3a2010-08-24 06:29:42 +00006219 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006220 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006221 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006222
John McCall60d7b3a2010-08-24 06:29:42 +00006223 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006225 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006226
John McCall60d7b3a2010-08-24 06:29:42 +00006227 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 if (E->getNumArgs() == 2) {
6229 Second = getDerived().TransformExpr(E->getArg(1));
6230 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006231 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 }
Mike Stump1eb44332009-09-09 15:08:12 +00006233
Douglas Gregorb98b1992009-08-11 05:31:07 +00006234 if (!getDerived().AlwaysRebuild() &&
6235 Callee.get() == E->getCallee() &&
6236 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006237 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006238 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006239
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6241 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006242 Callee.get(),
6243 First.get(),
6244 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245}
Mike Stump1eb44332009-09-09 15:08:12 +00006246
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006248ExprResult
John McCall454feb92009-12-08 09:21:05 +00006249TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6250 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251}
Mike Stump1eb44332009-09-09 15:08:12 +00006252
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006254ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006255TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6256 // Transform the callee.
6257 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6258 if (Callee.isInvalid())
6259 return ExprError();
6260
6261 // Transform exec config.
6262 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6263 if (EC.isInvalid())
6264 return ExprError();
6265
6266 // Transform arguments.
6267 bool ArgChanged = false;
6268 ASTOwningVector<Expr*> Args(SemaRef);
6269 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6270 &ArgChanged))
6271 return ExprError();
6272
6273 if (!getDerived().AlwaysRebuild() &&
6274 Callee.get() == E->getCallee() &&
6275 !ArgChanged)
6276 return SemaRef.Owned(E);
6277
6278 // FIXME: Wrong source location information for the '('.
6279 SourceLocation FakeLParenLoc
6280 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6281 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6282 move_arg(Args),
6283 E->getRParenLoc(), EC.get());
6284}
6285
6286template<typename Derived>
6287ExprResult
John McCall454feb92009-12-08 09:21:05 +00006288TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006289 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6290 if (!Type)
6291 return ExprError();
6292
John McCall60d7b3a2010-08-24 06:29:42 +00006293 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006294 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006296 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006297
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006299 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006300 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006302
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006304 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6306 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6307 SourceLocation FakeRParenLoc
6308 = SemaRef.PP.getLocForEndOfToken(
6309 E->getSubExpr()->getSourceRange().getEnd());
6310 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006311 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006313 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 FakeRAngleLoc,
6315 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006316 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317 FakeRParenLoc);
6318}
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
John McCall454feb92009-12-08 09:21:05 +00006322TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6323 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324}
Mike Stump1eb44332009-09-09 15:08:12 +00006325
6326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006327ExprResult
John McCall454feb92009-12-08 09:21:05 +00006328TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6329 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006330}
6331
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006333ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006335 CXXReinterpretCastExpr *E) {
6336 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337}
Mike Stump1eb44332009-09-09 15:08:12 +00006338
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006340ExprResult
John McCall454feb92009-12-08 09:21:05 +00006341TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6342 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343}
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Douglas Gregorb98b1992009-08-11 05:31:07 +00006345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006346ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006348 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006349 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6350 if (!Type)
6351 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006352
John McCall60d7b3a2010-08-24 06:29:42 +00006353 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006354 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006356 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006359 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006361 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006362
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006363 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006365 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 E->getRParenLoc());
6367}
Mike Stump1eb44332009-09-09 15:08:12 +00006368
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006370ExprResult
John McCall454feb92009-12-08 09:21:05 +00006371TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006373 TypeSourceInfo *TInfo
6374 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6375 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006376 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006377
Douglas Gregorb98b1992009-08-11 05:31:07 +00006378 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006379 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006380 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006381
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006382 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6383 E->getLocStart(),
6384 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 E->getLocEnd());
6386 }
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 // We don't know whether the expression is potentially evaluated until
6389 // after we perform semantic analysis, so the expression is potentially
6390 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006391 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006392 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006393
John McCall60d7b3a2010-08-24 06:29:42 +00006394 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006396 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006397
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 if (!getDerived().AlwaysRebuild() &&
6399 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006400 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006401
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006402 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6403 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006404 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 E->getLocEnd());
6406}
6407
6408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006409ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006410TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6411 if (E->isTypeOperand()) {
6412 TypeSourceInfo *TInfo
6413 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6414 if (!TInfo)
6415 return ExprError();
6416
6417 if (!getDerived().AlwaysRebuild() &&
6418 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006419 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006420
6421 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6422 E->getLocStart(),
6423 TInfo,
6424 E->getLocEnd());
6425 }
6426
6427 // We don't know whether the expression is potentially evaluated until
6428 // after we perform semantic analysis, so the expression is potentially
6429 // potentially evaluated.
6430 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6431
6432 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6433 if (SubExpr.isInvalid())
6434 return ExprError();
6435
6436 if (!getDerived().AlwaysRebuild() &&
6437 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006438 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006439
6440 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6441 E->getLocStart(),
6442 SubExpr.get(),
6443 E->getLocEnd());
6444}
6445
6446template<typename Derived>
6447ExprResult
John McCall454feb92009-12-08 09:21:05 +00006448TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006449 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450}
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006453ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006455 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006456 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457}
Mike Stump1eb44332009-09-09 15:08:12 +00006458
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006460ExprResult
John McCall454feb92009-12-08 09:21:05 +00006461TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006462 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6463 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6464 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006465
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006466 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006467 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006468
Douglas Gregor828a1972010-01-07 23:12:05 +00006469 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470}
Mike Stump1eb44332009-09-09 15:08:12 +00006471
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006473ExprResult
John McCall454feb92009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006475 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006477 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006478
Douglas Gregorb98b1992009-08-11 05:31:07 +00006479 if (!getDerived().AlwaysRebuild() &&
6480 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006481 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482
John McCall9ae2f072010-08-23 23:25:46 +00006483 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484}
Mike Stump1eb44332009-09-09 15:08:12 +00006485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006487ExprResult
John McCall454feb92009-12-08 09:21:05 +00006488TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006489 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006490 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6491 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006493 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006494
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006495 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006497 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregor036aed12009-12-23 23:03:06 +00006499 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500}
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregorb98b1992009-08-11 05:31:07 +00006502template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006503ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006504TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6505 CXXScalarValueInitExpr *E) {
6506 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6507 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006508 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006511 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregorab6677e2010-09-08 00:15:04 +00006514 return getDerived().RebuildCXXScalarValueInitExpr(T,
6515 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006516 E->getRParenLoc());
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
John McCall454feb92009-12-08 09:21:05 +00006521TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006523 TypeSourceInfo *AllocTypeInfo
6524 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6525 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006527
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006529 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006530 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006531 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 // Transform the placement arguments (if any).
6534 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006535 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006536 if (getDerived().TransformExprs(E->getPlacementArgs(),
6537 E->getNumPlacementArgs(), true,
6538 PlacementArgs, &ArgumentChanged))
6539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregor43959a92009-08-20 07:17:43 +00006541 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006542 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006543 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6544 ConstructorArgs, &ArgumentChanged))
6545 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006546
Douglas Gregor1af74512010-02-26 00:38:10 +00006547 // Transform constructor, new operator, and delete operator.
6548 CXXConstructorDecl *Constructor = 0;
6549 if (E->getConstructor()) {
6550 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006551 getDerived().TransformDecl(E->getLocStart(),
6552 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006553 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006554 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006555 }
6556
6557 FunctionDecl *OperatorNew = 0;
6558 if (E->getOperatorNew()) {
6559 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006560 getDerived().TransformDecl(E->getLocStart(),
6561 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006562 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006563 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006564 }
6565
6566 FunctionDecl *OperatorDelete = 0;
6567 if (E->getOperatorDelete()) {
6568 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006569 getDerived().TransformDecl(E->getLocStart(),
6570 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006571 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006572 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006573 }
Sean Huntc3021132010-05-05 15:23:54 +00006574
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006576 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006578 Constructor == E->getConstructor() &&
6579 OperatorNew == E->getOperatorNew() &&
6580 OperatorDelete == E->getOperatorDelete() &&
6581 !ArgumentChanged) {
6582 // Mark any declarations we need as referenced.
6583 // FIXME: instantiation-specific.
6584 if (Constructor)
6585 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6586 if (OperatorNew)
6587 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6588 if (OperatorDelete)
6589 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006590 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006591 }
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006593 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006594 if (!ArraySize.get()) {
6595 // If no array size was specified, but the new expression was
6596 // instantiated with an array type (e.g., "new T" where T is
6597 // instantiated with "int[4]"), extract the outer bound from the
6598 // array type as our array size. We do this with constant and
6599 // dependently-sized array types.
6600 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6601 if (!ArrayT) {
6602 // Do nothing
6603 } else if (const ConstantArrayType *ConsArrayT
6604 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006605 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006606 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6607 ConsArrayT->getSize(),
6608 SemaRef.Context.getSizeType(),
6609 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006610 AllocType = ConsArrayT->getElementType();
6611 } else if (const DependentSizedArrayType *DepArrayT
6612 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6613 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006614 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006615 AllocType = DepArrayT->getElementType();
6616 }
6617 }
6618 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006619
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6621 E->isGlobalNew(),
6622 /*FIXME:*/E->getLocStart(),
6623 move_arg(PlacementArgs),
6624 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006625 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006627 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006628 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 /*FIXME:*/E->getLocStart(),
6630 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006631 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632}
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006635ExprResult
John McCall454feb92009-12-08 09:21:05 +00006636TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006637 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006638 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006639 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregor1af74512010-02-26 00:38:10 +00006641 // Transform the delete operator, if known.
6642 FunctionDecl *OperatorDelete = 0;
6643 if (E->getOperatorDelete()) {
6644 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006645 getDerived().TransformDecl(E->getLocStart(),
6646 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006647 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006648 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006649 }
Sean Huntc3021132010-05-05 15:23:54 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006652 Operand.get() == E->getArgument() &&
6653 OperatorDelete == E->getOperatorDelete()) {
6654 // Mark any declarations we need as referenced.
6655 // FIXME: instantiation-specific.
6656 if (OperatorDelete)
6657 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006658
6659 if (!E->getArgument()->isTypeDependent()) {
6660 QualType Destroyed = SemaRef.Context.getBaseElementType(
6661 E->getDestroyedType());
6662 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6663 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6664 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6665 SemaRef.LookupDestructor(Record));
6666 }
6667 }
6668
John McCall3fa5cae2010-10-26 07:05:15 +00006669 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006670 }
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6673 E->isGlobalDelete(),
6674 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006675 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676}
Mike Stump1eb44332009-09-09 15:08:12 +00006677
Douglas Gregorb98b1992009-08-11 05:31:07 +00006678template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006679ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006680TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006681 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006682 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006683 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
John McCallb3d87482010-08-24 05:47:05 +00006686 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006687 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006688 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006689 E->getOperatorLoc(),
6690 E->isArrow()? tok::arrow : tok::period,
6691 ObjectTypePtr,
6692 MayBePseudoDestructor);
6693 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006694 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006695
John McCallb3d87482010-08-24 05:47:05 +00006696 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006697 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6698 if (QualifierLoc) {
6699 QualifierLoc
6700 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6701 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006702 return ExprError();
6703 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006704 CXXScopeSpec SS;
6705 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006706
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006707 PseudoDestructorTypeStorage Destroyed;
6708 if (E->getDestroyedTypeInfo()) {
6709 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006710 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006711 ObjectType, 0,
6712 QualifierLoc.getNestedNameSpecifier());
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006713 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006714 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006715 Destroyed = DestroyedTypeInfo;
6716 } else if (ObjectType->isDependentType()) {
6717 // We aren't likely to be able to resolve the identifier down to a type
6718 // now anyway, so just retain the identifier.
6719 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6720 E->getDestroyedTypeLoc());
6721 } else {
6722 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006723 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006724 *E->getDestroyedTypeIdentifier(),
6725 E->getDestroyedTypeLoc(),
6726 /*Scope=*/0,
6727 SS, ObjectTypePtr,
6728 false);
6729 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006730 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006731
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006732 Destroyed
6733 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6734 E->getDestroyedTypeLoc());
6735 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006736
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006737 TypeSourceInfo *ScopeTypeInfo = 0;
6738 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006739 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006740 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006741 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006742 }
Sean Huntc3021132010-05-05 15:23:54 +00006743
John McCall9ae2f072010-08-23 23:25:46 +00006744 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006745 E->getOperatorLoc(),
6746 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006747 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006748 ScopeTypeInfo,
6749 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006750 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006751 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006752}
Mike Stump1eb44332009-09-09 15:08:12 +00006753
Douglas Gregora71d8192009-09-04 17:36:40 +00006754template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006755ExprResult
John McCallba135432009-11-21 08:51:07 +00006756TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006757 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006758 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6759
6760 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6761 Sema::LookupOrdinaryName);
6762
6763 // Transform all the decls.
6764 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6765 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006766 NamedDecl *InstD = static_cast<NamedDecl*>(
6767 getDerived().TransformDecl(Old->getNameLoc(),
6768 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006769 if (!InstD) {
6770 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6771 // This can happen because of dependent hiding.
6772 if (isa<UsingShadowDecl>(*I))
6773 continue;
6774 else
John McCallf312b1e2010-08-26 23:41:50 +00006775 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006776 }
John McCallf7a1a742009-11-24 19:00:30 +00006777
6778 // Expand using declarations.
6779 if (isa<UsingDecl>(InstD)) {
6780 UsingDecl *UD = cast<UsingDecl>(InstD);
6781 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6782 E = UD->shadow_end(); I != E; ++I)
6783 R.addDecl(*I);
6784 continue;
6785 }
6786
6787 R.addDecl(InstD);
6788 }
6789
6790 // Resolve a kind, but don't do any further analysis. If it's
6791 // ambiguous, the callee needs to deal with it.
6792 R.resolveKind();
6793
6794 // Rebuild the nested-name qualifier, if present.
6795 CXXScopeSpec SS;
6796 NestedNameSpecifier *Qualifier = 0;
6797 if (Old->getQualifier()) {
6798 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006799 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006800 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006801 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006802
Douglas Gregorc34348a2011-02-24 17:54:50 +00006803 SS.MakeTrivial(SemaRef.Context, Qualifier, Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006804 }
6805
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006806 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006807 CXXRecordDecl *NamingClass
6808 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6809 Old->getNameLoc(),
6810 Old->getNamingClass()));
6811 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006812 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006813
Douglas Gregor66c45152010-04-27 16:10:10 +00006814 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006815 }
6816
6817 // If we have no template arguments, it's a normal declaration name.
6818 if (!Old->hasExplicitTemplateArgs())
6819 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6820
6821 // If we have template arguments, rebuild them, then rebuild the
6822 // templateid expression.
6823 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006824 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6825 Old->getNumTemplateArgs(),
6826 TransArgs))
6827 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006828
6829 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6830 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831}
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006834ExprResult
John McCall454feb92009-12-08 09:21:05 +00006835TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006836 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6837 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006838 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006839
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006841 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006842 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Mike Stump1eb44332009-09-09 15:08:12 +00006844 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006845 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846 T,
6847 E->getLocEnd());
6848}
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006851ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006852TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6853 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6854 if (!LhsT)
6855 return ExprError();
6856
6857 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6858 if (!RhsT)
6859 return ExprError();
6860
6861 if (!getDerived().AlwaysRebuild() &&
6862 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6863 return SemaRef.Owned(E);
6864
6865 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6866 E->getLocStart(),
6867 LhsT, RhsT,
6868 E->getLocEnd());
6869}
6870
6871template<typename Derived>
6872ExprResult
John McCall865d4472009-11-19 22:55:06 +00006873TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006874 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006875 NestedNameSpecifierLoc QualifierLoc
6876 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6877 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006878 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006879
John McCall43fed0d2010-11-12 08:19:04 +00006880 // TODO: If this is a conversion-function-id, verify that the
6881 // destination type name (if present) resolves the same way after
6882 // instantiation as it did in the local scope.
6883
Abramo Bagnara25777432010-08-11 22:01:17 +00006884 DeclarationNameInfo NameInfo
6885 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6886 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006887 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006888
John McCallf7a1a742009-11-24 19:00:30 +00006889 if (!E->hasExplicitTemplateArgs()) {
6890 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006891 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006892 // Note: it is sufficient to compare the Name component of NameInfo:
6893 // if name has not changed, DNLoc has not changed either.
6894 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006895 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006896
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006897 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006898 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006899 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006900 }
John McCalld5532b62009-11-23 01:53:49 +00006901
6902 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006903 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6904 E->getNumTemplateArgs(),
6905 TransArgs))
6906 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00006908 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006909 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006910 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911}
6912
6913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006914ExprResult
John McCall454feb92009-12-08 09:21:05 +00006915TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006916 // CXXConstructExprs are always implicit, so when we have a
6917 // 1-argument construction we just transform that argument.
6918 if (E->getNumArgs() == 1 ||
6919 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6920 return getDerived().TransformExpr(E->getArg(0));
6921
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6923
6924 QualType T = getDerived().TransformType(E->getType());
6925 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006926 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927
6928 CXXConstructorDecl *Constructor
6929 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006930 getDerived().TransformDecl(E->getLocStart(),
6931 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006932 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006933 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006936 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006937 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6938 &ArgumentChanged))
6939 return ExprError();
6940
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 if (!getDerived().AlwaysRebuild() &&
6942 T == E->getType() &&
6943 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006944 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006945 // Mark the constructor as referenced.
6946 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006947 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006948 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006949 }
Mike Stump1eb44332009-09-09 15:08:12 +00006950
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006951 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6952 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006953 move_arg(Args),
6954 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006955 E->getConstructionKind(),
6956 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957}
Mike Stump1eb44332009-09-09 15:08:12 +00006958
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959/// \brief Transform a C++ temporary-binding expression.
6960///
Douglas Gregor51326552009-12-24 18:51:59 +00006961/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6962/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006964ExprResult
John McCall454feb92009-12-08 09:21:05 +00006965TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006966 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006967}
Mike Stump1eb44332009-09-09 15:08:12 +00006968
John McCall4765fa02010-12-06 08:20:24 +00006969/// \brief Transform a C++ expression that contains cleanups that should
6970/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971///
John McCall4765fa02010-12-06 08:20:24 +00006972/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006973/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006975ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006976TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006977 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978}
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006983 CXXTemporaryObjectExpr *E) {
6984 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6985 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006986 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006987
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988 CXXConstructorDecl *Constructor
6989 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006990 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006991 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006994
Douglas Gregorb98b1992009-08-11 05:31:07 +00006995 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006996 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006997 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006998 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6999 &ArgumentChanged))
7000 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorb98b1992009-08-11 05:31:07 +00007002 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007003 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007005 !ArgumentChanged) {
7006 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007007 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007008 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007009 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007010
7011 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7012 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007014 E->getLocEnd());
7015}
Mike Stump1eb44332009-09-09 15:08:12 +00007016
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007018ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007020 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007021 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7022 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007024
Douglas Gregorb98b1992009-08-11 05:31:07 +00007025 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007026 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007027 Args.reserve(E->arg_size());
7028 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7029 &ArgumentChanged))
7030 return ExprError();
7031
Douglas Gregorb98b1992009-08-11 05:31:07 +00007032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007033 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007038 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039 E->getLParenLoc(),
7040 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 E->getRParenLoc());
7042}
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007045ExprResult
John McCall865d4472009-11-19 22:55:06 +00007046TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007047 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007049 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007050 Expr *OldBase;
7051 QualType BaseType;
7052 QualType ObjectType;
7053 if (!E->isImplicitAccess()) {
7054 OldBase = E->getBase();
7055 Base = getDerived().TransformExpr(OldBase);
7056 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007058
John McCallaa81e162009-12-01 22:10:20 +00007059 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007060 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007061 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007062 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007063 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007064 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007065 ObjectTy,
7066 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007067 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007068 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007069
John McCallb3d87482010-08-24 05:47:05 +00007070 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007071 BaseType = ((Expr*) Base.get())->getType();
7072 } else {
7073 OldBase = 0;
7074 BaseType = getDerived().TransformType(E->getBaseType());
7075 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7076 }
Mike Stump1eb44332009-09-09 15:08:12 +00007077
Douglas Gregor6cd21982009-10-20 05:58:46 +00007078 // Transform the first part of the nested-name-specifier that qualifies
7079 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007080 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007081 = getDerived().TransformFirstQualifierInScope(
7082 E->getFirstQualifierFoundInScope(),
7083 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregora38c6872009-09-03 16:14:30 +00007085 NestedNameSpecifier *Qualifier = 0;
7086 if (E->getQualifier()) {
7087 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
7088 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00007089 ObjectType,
7090 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00007091 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00007092 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007093 }
Mike Stump1eb44332009-09-09 15:08:12 +00007094
John McCall43fed0d2010-11-12 08:19:04 +00007095 // TODO: If this is a conversion-function-id, verify that the
7096 // destination type name (if present) resolves the same way after
7097 // instantiation as it did in the local scope.
7098
Abramo Bagnara25777432010-08-11 22:01:17 +00007099 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007100 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007101 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007102 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007103
John McCallaa81e162009-12-01 22:10:20 +00007104 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007105 // This is a reference to a member without an explicitly-specified
7106 // template argument list. Optimize for this common case.
7107 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007108 Base.get() == OldBase &&
7109 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007110 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007111 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007112 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007113 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007114
John McCall9ae2f072010-08-23 23:25:46 +00007115 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007116 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007117 E->isArrow(),
7118 E->getOperatorLoc(),
7119 Qualifier,
7120 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00007121 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007122 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007123 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007124 }
7125
John McCalld5532b62009-11-23 01:53:49 +00007126 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007127 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7128 E->getNumTemplateArgs(),
7129 TransArgs))
7130 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007131
John McCall9ae2f072010-08-23 23:25:46 +00007132 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007133 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007134 E->isArrow(),
7135 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007136 Qualifier,
7137 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007138 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007139 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007140 &TransArgs);
7141}
7142
7143template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007144ExprResult
John McCall454feb92009-12-08 09:21:05 +00007145TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007146 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007147 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007148 QualType BaseType;
7149 if (!Old->isImplicitAccess()) {
7150 Base = getDerived().TransformExpr(Old->getBase());
7151 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007152 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007153 BaseType = ((Expr*) Base.get())->getType();
7154 } else {
7155 BaseType = getDerived().TransformType(Old->getBaseType());
7156 }
John McCall129e2df2009-11-30 22:42:35 +00007157
7158 NestedNameSpecifier *Qualifier = 0;
7159 if (Old->getQualifier()) {
7160 Qualifier
7161 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00007162 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00007163 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00007164 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007165 }
7166
Abramo Bagnara25777432010-08-11 22:01:17 +00007167 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007168 Sema::LookupOrdinaryName);
7169
7170 // Transform all the decls.
7171 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7172 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007173 NamedDecl *InstD = static_cast<NamedDecl*>(
7174 getDerived().TransformDecl(Old->getMemberLoc(),
7175 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007176 if (!InstD) {
7177 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7178 // This can happen because of dependent hiding.
7179 if (isa<UsingShadowDecl>(*I))
7180 continue;
7181 else
John McCallf312b1e2010-08-26 23:41:50 +00007182 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007183 }
John McCall129e2df2009-11-30 22:42:35 +00007184
7185 // Expand using declarations.
7186 if (isa<UsingDecl>(InstD)) {
7187 UsingDecl *UD = cast<UsingDecl>(InstD);
7188 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7189 E = UD->shadow_end(); I != E; ++I)
7190 R.addDecl(*I);
7191 continue;
7192 }
7193
7194 R.addDecl(InstD);
7195 }
7196
7197 R.resolveKind();
7198
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007199 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007200 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007201 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007202 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007203 Old->getMemberLoc(),
7204 Old->getNamingClass()));
7205 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007206 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007207
Douglas Gregor66c45152010-04-27 16:10:10 +00007208 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007209 }
Sean Huntc3021132010-05-05 15:23:54 +00007210
John McCall129e2df2009-11-30 22:42:35 +00007211 TemplateArgumentListInfo TransArgs;
7212 if (Old->hasExplicitTemplateArgs()) {
7213 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7214 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007215 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7216 Old->getNumTemplateArgs(),
7217 TransArgs))
7218 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007219 }
John McCallc2233c52010-01-15 08:34:02 +00007220
7221 // FIXME: to do this check properly, we will need to preserve the
7222 // first-qualifier-in-scope here, just in case we had a dependent
7223 // base (and therefore couldn't do the check) and a
7224 // nested-name-qualifier (and therefore could do the lookup).
7225 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007226
John McCall9ae2f072010-08-23 23:25:46 +00007227 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007228 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007229 Old->getOperatorLoc(),
7230 Old->isArrow(),
7231 Qualifier,
7232 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00007233 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007234 R,
7235 (Old->hasExplicitTemplateArgs()
7236 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007237}
7238
7239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007240ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007241TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7242 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7243 if (SubExpr.isInvalid())
7244 return ExprError();
7245
7246 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007247 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007248
7249 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7250}
7251
7252template<typename Derived>
7253ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007254TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007255 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7256 if (Pattern.isInvalid())
7257 return ExprError();
7258
7259 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7260 return SemaRef.Owned(E);
7261
Douglas Gregor67fd1252011-01-14 21:20:45 +00007262 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7263 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007264}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007265
7266template<typename Derived>
7267ExprResult
7268TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7269 // If E is not value-dependent, then nothing will change when we transform it.
7270 // Note: This is an instantiation-centric view.
7271 if (!E->isValueDependent())
7272 return SemaRef.Owned(E);
7273
7274 // Note: None of the implementations of TryExpandParameterPacks can ever
7275 // produce a diagnostic when given only a single unexpanded parameter pack,
7276 // so
7277 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7278 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007279 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007280 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007281 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7282 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007283 ShouldExpand, RetainExpansion,
7284 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007285 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007286
Douglas Gregord3731192011-01-10 07:32:04 +00007287 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007288 return SemaRef.Owned(E);
7289
7290 // We now know the length of the parameter pack, so build a new expression
7291 // that stores that length.
7292 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7293 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007294 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007295}
7296
Douglas Gregorbe230c32011-01-03 17:17:50 +00007297template<typename Derived>
7298ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007299TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7300 SubstNonTypeTemplateParmPackExpr *E) {
7301 // Default behavior is to do nothing with this transformation.
7302 return SemaRef.Owned(E);
7303}
7304
7305template<typename Derived>
7306ExprResult
John McCall454feb92009-12-08 09:21:05 +00007307TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007308 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007309}
7310
Mike Stump1eb44332009-09-09 15:08:12 +00007311template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007312ExprResult
John McCall454feb92009-12-08 09:21:05 +00007313TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007314 TypeSourceInfo *EncodedTypeInfo
7315 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7316 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007317 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007318
Douglas Gregorb98b1992009-08-11 05:31:07 +00007319 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007320 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007321 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007322
7323 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007324 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007325 E->getRParenLoc());
7326}
Mike Stump1eb44332009-09-09 15:08:12 +00007327
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007329ExprResult
John McCall454feb92009-12-08 09:21:05 +00007330TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007331 // Transform arguments.
7332 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007333 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007334 Args.reserve(E->getNumArgs());
7335 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7336 &ArgChanged))
7337 return ExprError();
7338
Douglas Gregor92e986e2010-04-22 16:44:27 +00007339 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7340 // Class message: transform the receiver type.
7341 TypeSourceInfo *ReceiverTypeInfo
7342 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7343 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007344 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007345
Douglas Gregor92e986e2010-04-22 16:44:27 +00007346 // If nothing changed, just retain the existing message send.
7347 if (!getDerived().AlwaysRebuild() &&
7348 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007349 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007350
7351 // Build a new class message send.
7352 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7353 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007354 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007355 E->getMethodDecl(),
7356 E->getLeftLoc(),
7357 move_arg(Args),
7358 E->getRightLoc());
7359 }
7360
7361 // Instance message: transform the receiver
7362 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7363 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007364 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007365 = getDerived().TransformExpr(E->getInstanceReceiver());
7366 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007367 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007368
7369 // If nothing changed, just retain the existing message send.
7370 if (!getDerived().AlwaysRebuild() &&
7371 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007372 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007373
Douglas Gregor92e986e2010-04-22 16:44:27 +00007374 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007375 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007376 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007377 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007378 E->getMethodDecl(),
7379 E->getLeftLoc(),
7380 move_arg(Args),
7381 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382}
7383
Mike Stump1eb44332009-09-09 15:08:12 +00007384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007385ExprResult
John McCall454feb92009-12-08 09:21:05 +00007386TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007387 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388}
7389
Mike Stump1eb44332009-09-09 15:08:12 +00007390template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007391ExprResult
John McCall454feb92009-12-08 09:21:05 +00007392TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007393 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394}
7395
Mike Stump1eb44332009-09-09 15:08:12 +00007396template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007397ExprResult
John McCall454feb92009-12-08 09:21:05 +00007398TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007399 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007400 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007401 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007402 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007403
7404 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007405
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007406 // If nothing changed, just retain the existing expression.
7407 if (!getDerived().AlwaysRebuild() &&
7408 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007409 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007410
John McCall9ae2f072010-08-23 23:25:46 +00007411 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007412 E->getLocation(),
7413 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414}
7415
Mike Stump1eb44332009-09-09 15:08:12 +00007416template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007417ExprResult
John McCall454feb92009-12-08 09:21:05 +00007418TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007419 // 'super' and types never change. Property never changes. Just
7420 // retain the existing expression.
7421 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007422 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007423
Douglas Gregore3303542010-04-26 20:47:02 +00007424 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007425 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007426 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007427 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007428
Douglas Gregore3303542010-04-26 20:47:02 +00007429 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007430
Douglas Gregore3303542010-04-26 20:47:02 +00007431 // If nothing changed, just retain the existing expression.
7432 if (!getDerived().AlwaysRebuild() &&
7433 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007434 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007435
John McCall12f78a62010-12-02 01:19:52 +00007436 if (E->isExplicitProperty())
7437 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7438 E->getExplicitProperty(),
7439 E->getLocation());
7440
7441 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7442 E->getType(),
7443 E->getImplicitPropertyGetter(),
7444 E->getImplicitPropertySetter(),
7445 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446}
7447
Mike Stump1eb44332009-09-09 15:08:12 +00007448template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007449ExprResult
John McCall454feb92009-12-08 09:21:05 +00007450TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007451 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007452 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007453 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007454 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007455
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007456 // If nothing changed, just retain the existing expression.
7457 if (!getDerived().AlwaysRebuild() &&
7458 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007459 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007460
John McCall9ae2f072010-08-23 23:25:46 +00007461 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007462 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463}
7464
Mike Stump1eb44332009-09-09 15:08:12 +00007465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007466ExprResult
John McCall454feb92009-12-08 09:21:05 +00007467TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007468 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007469 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007470 SubExprs.reserve(E->getNumSubExprs());
7471 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7472 SubExprs, &ArgumentChanged))
7473 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007474
Douglas Gregorb98b1992009-08-11 05:31:07 +00007475 if (!getDerived().AlwaysRebuild() &&
7476 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007477 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007478
Douglas Gregorb98b1992009-08-11 05:31:07 +00007479 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7480 move_arg(SubExprs),
7481 E->getRParenLoc());
7482}
7483
Mike Stump1eb44332009-09-09 15:08:12 +00007484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007485ExprResult
John McCall454feb92009-12-08 09:21:05 +00007486TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007487 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007488
John McCallc6ac9c32011-02-04 18:33:18 +00007489 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7490 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7491
7492 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7493 llvm::SmallVector<ParmVarDecl*, 4> params;
7494 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007495
7496 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007497 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7498 oldBlock->param_begin(),
7499 oldBlock->param_size(),
7500 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007501 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007502
7503 const FunctionType *exprFunctionType = E->getFunctionType();
7504 QualType exprResultType = exprFunctionType->getResultType();
7505 if (!exprResultType.isNull()) {
7506 if (!exprResultType->isDependentType())
7507 blockScope->ReturnType = exprResultType;
7508 else if (exprResultType != getSema().Context.DependentTy)
7509 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007510 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007511
7512 // If the return type has not been determined yet, leave it as a dependent
7513 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007514 if (blockScope->ReturnType.isNull())
7515 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007516
7517 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007518 if (blockScope->ReturnType->isObjCObjectType()) {
7519 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007520 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007521 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007522 return ExprError();
7523 }
John McCall711c52b2011-01-05 12:14:39 +00007524
John McCallc6ac9c32011-02-04 18:33:18 +00007525 QualType functionType = getDerived().RebuildFunctionProtoType(
7526 blockScope->ReturnType,
7527 paramTypes.data(),
7528 paramTypes.size(),
7529 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007530 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007531 exprFunctionType->getExtInfo());
7532 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007533
7534 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007535 if (!params.empty())
7536 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007537
7538 // If the return type wasn't explicitly set, it will have been marked as a
7539 // dependent type (DependentTy); clear out the return type setting so
7540 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007541 if (blockScope->ReturnType == getSema().Context.DependentTy)
7542 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007543
John McCall711c52b2011-01-05 12:14:39 +00007544 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007545 StmtResult body = getDerived().TransformStmt(E->getBody());
7546 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007547 return ExprError();
7548
John McCallc6ac9c32011-02-04 18:33:18 +00007549#ifndef NDEBUG
7550 // In builds with assertions, make sure that we captured everything we
7551 // captured before.
7552
7553 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7554
7555 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7556 e = oldBlock->capture_end(); i != e; ++i) {
John McCall6b5a61b2011-02-07 10:33:21 +00007557 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007558
7559 // Ignore parameter packs.
7560 if (isa<ParmVarDecl>(oldCapture) &&
7561 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7562 continue;
7563
7564 VarDecl *newCapture =
7565 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7566 oldCapture));
John McCall6b5a61b2011-02-07 10:33:21 +00007567 assert(blockScope->CaptureMap.count(newCapture));
John McCallc6ac9c32011-02-04 18:33:18 +00007568 }
7569#endif
7570
7571 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7572 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007573}
7574
Mike Stump1eb44332009-09-09 15:08:12 +00007575template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007576ExprResult
John McCall454feb92009-12-08 09:21:05 +00007577TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007578 NestedNameSpecifier *Qualifier = 0;
7579
7580 ValueDecl *ND
7581 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7582 E->getDecl()));
7583 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007584 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007585
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007586 if (!getDerived().AlwaysRebuild() &&
7587 ND == E->getDecl()) {
7588 // Mark it referenced in the new context regardless.
7589 // FIXME: this is a bit instantiation-specific.
7590 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7591
John McCall3fa5cae2010-10-26 07:05:15 +00007592 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007593 }
7594
Abramo Bagnara25777432010-08-11 22:01:17 +00007595 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007596 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007597 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598}
Mike Stump1eb44332009-09-09 15:08:12 +00007599
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007601// Type reconstruction
7602//===----------------------------------------------------------------------===//
7603
Mike Stump1eb44332009-09-09 15:08:12 +00007604template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007605QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7606 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007607 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007608 getDerived().getBaseEntity());
7609}
7610
Mike Stump1eb44332009-09-09 15:08:12 +00007611template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007612QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7613 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007614 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007615 getDerived().getBaseEntity());
7616}
7617
Mike Stump1eb44332009-09-09 15:08:12 +00007618template<typename Derived>
7619QualType
John McCall85737a72009-10-30 00:06:24 +00007620TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7621 bool WrittenAsLValue,
7622 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007623 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007624 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007625}
7626
7627template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007628QualType
John McCall85737a72009-10-30 00:06:24 +00007629TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7630 QualType ClassType,
7631 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007632 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007633 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007634}
7635
7636template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007637QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007638TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7639 ArrayType::ArraySizeModifier SizeMod,
7640 const llvm::APInt *Size,
7641 Expr *SizeExpr,
7642 unsigned IndexTypeQuals,
7643 SourceRange BracketsRange) {
7644 if (SizeExpr || !Size)
7645 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7646 IndexTypeQuals, BracketsRange,
7647 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007648
7649 QualType Types[] = {
7650 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7651 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7652 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007653 };
7654 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7655 QualType SizeType;
7656 for (unsigned I = 0; I != NumTypes; ++I)
7657 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7658 SizeType = Types[I];
7659 break;
7660 }
Mike Stump1eb44332009-09-09 15:08:12 +00007661
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007662 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7663 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007664 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007665 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007666 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007667}
Mike Stump1eb44332009-09-09 15:08:12 +00007668
Douglas Gregor577f75a2009-08-04 16:50:30 +00007669template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007670QualType
7671TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007672 ArrayType::ArraySizeModifier SizeMod,
7673 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007674 unsigned IndexTypeQuals,
7675 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007676 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007677 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007678}
7679
7680template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007681QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007682TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007683 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007684 unsigned IndexTypeQuals,
7685 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007686 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007687 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007688}
Mike Stump1eb44332009-09-09 15:08:12 +00007689
Douglas Gregor577f75a2009-08-04 16:50:30 +00007690template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007691QualType
7692TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007693 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007694 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007695 unsigned IndexTypeQuals,
7696 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007697 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007698 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007699 IndexTypeQuals, BracketsRange);
7700}
7701
7702template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007703QualType
7704TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007705 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007706 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007707 unsigned IndexTypeQuals,
7708 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007709 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007710 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007711 IndexTypeQuals, BracketsRange);
7712}
7713
7714template<typename Derived>
7715QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007716 unsigned NumElements,
7717 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007718 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007719 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007720}
Mike Stump1eb44332009-09-09 15:08:12 +00007721
Douglas Gregor577f75a2009-08-04 16:50:30 +00007722template<typename Derived>
7723QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7724 unsigned NumElements,
7725 SourceLocation AttributeLoc) {
7726 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7727 NumElements, true);
7728 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007729 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7730 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007731 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007732}
Mike Stump1eb44332009-09-09 15:08:12 +00007733
Douglas Gregor577f75a2009-08-04 16:50:30 +00007734template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007735QualType
7736TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007737 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007738 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007739 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007740}
Mike Stump1eb44332009-09-09 15:08:12 +00007741
Douglas Gregor577f75a2009-08-04 16:50:30 +00007742template<typename Derived>
7743QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007744 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007745 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007746 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007747 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007748 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007749 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007750 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007751 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007752 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007753 getDerived().getBaseEntity(),
7754 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007755}
Mike Stump1eb44332009-09-09 15:08:12 +00007756
Douglas Gregor577f75a2009-08-04 16:50:30 +00007757template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007758QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7759 return SemaRef.Context.getFunctionNoProtoType(T);
7760}
7761
7762template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007763QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7764 assert(D && "no decl found");
7765 if (D->isInvalidDecl()) return QualType();
7766
Douglas Gregor92e986e2010-04-22 16:44:27 +00007767 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007768 TypeDecl *Ty;
7769 if (isa<UsingDecl>(D)) {
7770 UsingDecl *Using = cast<UsingDecl>(D);
7771 assert(Using->isTypeName() &&
7772 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7773
7774 // A valid resolved using typename decl points to exactly one type decl.
7775 assert(++Using->shadow_begin() == Using->shadow_end());
7776 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007777
John McCalled976492009-12-04 22:46:56 +00007778 } else {
7779 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7780 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7781 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7782 }
7783
7784 return SemaRef.Context.getTypeDeclType(Ty);
7785}
7786
7787template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007788QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7789 SourceLocation Loc) {
7790 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007791}
7792
7793template<typename Derived>
7794QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7795 return SemaRef.Context.getTypeOfType(Underlying);
7796}
7797
7798template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007799QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7800 SourceLocation Loc) {
7801 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007802}
7803
7804template<typename Derived>
7805QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007806 TemplateName Template,
7807 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007808 const TemplateArgumentListInfo &TemplateArgs) {
7809 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007810}
Mike Stump1eb44332009-09-09 15:08:12 +00007811
Douglas Gregordcee1a12009-08-06 05:28:30 +00007812template<typename Derived>
7813NestedNameSpecifier *
7814TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7815 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007816 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007817 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007818 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007819 CXXScopeSpec SS;
7820 // FIXME: The source location information is all wrong.
Douglas Gregorc34348a2011-02-24 17:54:50 +00007821 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor2e4c34a2011-02-24 00:17:56 +00007822 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7823 /*FIXME:*/Range.getEnd(),
7824 ObjectType, false,
7825 SS, FirstQualifierInScope,
7826 false))
7827 return 0;
7828
7829 return SS.getScopeRep();
Douglas Gregordcee1a12009-08-06 05:28:30 +00007830}
7831
7832template<typename Derived>
7833NestedNameSpecifier *
7834TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7835 SourceRange Range,
7836 NamespaceDecl *NS) {
7837 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7838}
7839
7840template<typename Derived>
7841NestedNameSpecifier *
7842TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7843 SourceRange Range,
Douglas Gregor14aba762011-02-24 02:36:08 +00007844 NamespaceAliasDecl *Alias) {
7845 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7846}
7847
7848template<typename Derived>
7849NestedNameSpecifier *
7850TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7851 SourceRange Range,
Douglas Gregordcee1a12009-08-06 05:28:30 +00007852 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007853 QualType T) {
7854 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007855 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007856 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007857 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7858 T.getTypePtr());
7859 }
Mike Stump1eb44332009-09-09 15:08:12 +00007860
Douglas Gregordcee1a12009-08-06 05:28:30 +00007861 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7862 return 0;
7863}
Mike Stump1eb44332009-09-09 15:08:12 +00007864
Douglas Gregord1067e52009-08-06 06:41:21 +00007865template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007866TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007867TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7868 bool TemplateKW,
7869 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007870 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007871 Template);
7872}
7873
7874template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007875TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007876TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007877 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007878 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007879 QualType ObjectType,
7880 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007881 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00007882 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007883 UnqualifiedId Name;
7884 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007885 Sema::TemplateTy Template;
7886 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7887 /*FIXME:*/getDerived().getBaseLocation(),
7888 SS,
7889 Name,
John McCallb3d87482010-08-24 05:47:05 +00007890 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007891 /*EnteringContext=*/false,
7892 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007893 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007894}
Mike Stump1eb44332009-09-09 15:08:12 +00007895
Douglas Gregorb98b1992009-08-11 05:31:07 +00007896template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007897TemplateName
7898TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7899 OverloadedOperatorKind Operator,
7900 QualType ObjectType) {
7901 CXXScopeSpec SS;
Douglas Gregorc34348a2011-02-24 17:54:50 +00007902 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007903 UnqualifiedId Name;
7904 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7905 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7906 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007907 Sema::TemplateTy Template;
7908 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007909 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007910 SS,
7911 Name,
John McCallb3d87482010-08-24 05:47:05 +00007912 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007913 /*EnteringContext=*/false,
7914 Template);
7915 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007916}
Sean Huntc3021132010-05-05 15:23:54 +00007917
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007918template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007919ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007920TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7921 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007922 Expr *OrigCallee,
7923 Expr *First,
7924 Expr *Second) {
7925 Expr *Callee = OrigCallee->IgnoreParenCasts();
7926 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007927
Douglas Gregorb98b1992009-08-11 05:31:07 +00007928 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007929 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007930 if (!First->getType()->isOverloadableType() &&
7931 !Second->getType()->isOverloadableType())
7932 return getSema().CreateBuiltinArraySubscriptExpr(First,
7933 Callee->getLocStart(),
7934 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007935 } else if (Op == OO_Arrow) {
7936 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007937 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7938 } else if (Second == 0 || isPostIncDec) {
7939 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007940 // The argument is not of overloadable type, so try to create a
7941 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007942 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007943 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007944
John McCall9ae2f072010-08-23 23:25:46 +00007945 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007946 }
7947 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007948 if (!First->getType()->isOverloadableType() &&
7949 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007950 // Neither of the arguments is an overloadable type, so try to
7951 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007952 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007953 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007954 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007955 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007956 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007957
Douglas Gregorb98b1992009-08-11 05:31:07 +00007958 return move(Result);
7959 }
7960 }
Mike Stump1eb44332009-09-09 15:08:12 +00007961
7962 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007963 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007964 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007965
John McCall9ae2f072010-08-23 23:25:46 +00007966 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007967 assert(ULE->requiresADL());
7968
7969 // FIXME: Do we have to check
7970 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007971 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007972 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007973 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007974 }
Mike Stump1eb44332009-09-09 15:08:12 +00007975
Douglas Gregorb98b1992009-08-11 05:31:07 +00007976 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007977 Expr *Args[2] = { First, Second };
7978 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007979
Douglas Gregorb98b1992009-08-11 05:31:07 +00007980 // Create the overloaded operator invocation for unary operators.
7981 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007982 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007983 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007984 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007985 }
Mike Stump1eb44332009-09-09 15:08:12 +00007986
Sebastian Redlf322ed62009-10-29 20:17:01 +00007987 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007988 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007989 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007990 First,
7991 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007992
Douglas Gregorb98b1992009-08-11 05:31:07 +00007993 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007994 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007995 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007996 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7997 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007998 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007999
Mike Stump1eb44332009-09-09 15:08:12 +00008000 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008001}
Mike Stump1eb44332009-09-09 15:08:12 +00008002
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008004ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008005TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008006 SourceLocation OperatorLoc,
8007 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008008 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008009 TypeSourceInfo *ScopeType,
8010 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008011 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008012 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008013 QualType BaseType = Base->getType();
8014 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008015 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008016 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008017 !BaseType->getAs<PointerType>()->getPointeeType()
8018 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008019 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008020 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008021 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008022 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008023 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008024 /*FIXME?*/true);
8025 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008026
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008027 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008028 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8029 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8030 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8031 NameInfo.setNamedTypeInfo(DestroyedType);
8032
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008033 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008034
John McCall9ae2f072010-08-23 23:25:46 +00008035 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008036 OperatorLoc, isArrow,
8037 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008038 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008039 /*TemplateArgs*/ 0);
8040}
8041
Douglas Gregor577f75a2009-08-04 16:50:30 +00008042} // end namespace clang
8043
8044#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H